Date parsers

This module contains the following parsers:

Date - command date

DateUTC - command date --utc

TimeDateCtlStatus - command timedatectl status

class, extra_bad_lines=None)[source]


Class to parse date command output.

Sample in:

Fri Jun 24 09:13:34 CST 2016


>>> from import Date
>>> from insights.tests import context_wrap
>>> date_content = "Mon May 30 10:49:14 CST 2016"
>>> shared = {Date: Date(context_wrap(date_content))}
>>> date_info = shared[Date]
'Mon May 30 10:49:14 CST 2016'
>>> date_info.datetime is not None
>>> date_info.timezone

Bases: Exception

class, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser

Base class implementing shared code.


Parses the output of the date and date --utc command.

Sample: Fri Jun 24 09:13:34 CST 2016 Sample: Fri Jun 24 09:13:34 UTC 2016


A native datetime.datetime of the parsed date string


The string portion of the date string containing the timezone


DateParseException: Raised if any exception occurs parsing the content.

class, extra_bad_lines=None)[source]


Class to parse date --utc command output.

Sample in:

Fri Jun 24 09:13:34 UTC 2016


>>> from import DateUTC
>>> from insights.tests import context_wrap
>>> date_content = "Mon May 30 10:49:14 UTC 2016"
>>> shared = {DateUTC: DateUTC(context_wrap(date_content))}
>>> date_info = shared[DateUTC]
'Mon May 30 10:49:14 UTC 2016'
>>> date_info.datetime
datetime.datetime(2016, 5, 30, 10, 49, 14)
>>> date_info.timezone
class, extra_bad_lines=None)[source]

Bases: insights.core.CommandParser, dict

Class to parse the timedatectl status command output. It saves the infomartion in each line into a dict. Since the colon in all the lines except warning is aligned, every line is splited by the same colon index. The key is the lowercase of the first part joined by underscore after splitting it by colon, and the value is the left part after the colon. If the next line is continue line, then append it to the previous key. And also it converts the value to datetime format for “Local time”, “Universal time” and “RTC time”.

Sample in:

               Local time: Mon 2022-11-14 23:04:06 PST
           Universal time: Tue 2022-11-15 07:04:06 UTC
                 RTC time: Tue 2022-11-15 07:04:05
                Time zone: US/Pacific (PST, -0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: yes
          Last DST change: DST ended at
                           Sun 2022-11-06 01:59:59 EDT
                           Sun 2022-11-06 01:00:00 EST
          Next DST change: DST begins (the clock jumps one hour forward) at
                           Sun 2023-03-12 01:59:59 EST
                           Sun 2023-03-12 03:00:00 EDT

Warning: The system is configured to read the RTC time in the local time zone.
        This mode cannot be fully supported. It will create various problems
        with time zone changes and daylight saving time adjustments. The RTC
        time is never updated, it relies on external facilities to maintain it.
        If at all possible, use RTC in UTC by calling
        'timedatectl set-local-rtc 0'.
  • DateParseException -- when the datetime in “Local time”, “Universal time”, “RTC time” are not in expected format.
  • ParseException -- when the colon in each line except warning is not aligned.


>>> ctl_info['ntp_service']
>>> ctl_info['system_clock_synchronized']
>>> ctl_info['local_time']
datetime.datetime(2022, 11, 14, 23, 4, 6)

This method must be implemented by classes based on this class.