task_script_utils.datetime_parser.datetime_info module#

class DateTimeInfo(date_time_raw: str, config: DatetimeConfig)[source]#

Bases: object

DatetimeInfo acts as base class for ShortDatetimeInfo and LongDatetimeInfo. This class definer the parsing logic. _parse takes a list of matcher functions. Child class should define these matcher function.

property offset#

Return UTC offset that was found during parsing

property datetime_stamp#

Created Datetime string from parsed raw input string. The format is YYYY-MM-DD hh:mm:ss and fractional seconds (upto 6 digit), AM/PM and utc offset are appended conditionally.

Returns:

A datetime string

Return type:

str/None

property datetime_format#

Build datetime format using pendulum tokens. This property along with datetime_stamp property can be used to parse date using pendulum.from_format.

Returns:

A datetime format build using pendulum formatting tokens. This string represent the datetime format for datetime_stamp

Return type:

str

property datetime: TSDatetime#

Use parsing result to build TSDatetime object

class LongDateTimeInfo(date_time_raw: str, config: DatetimeConfig)[source]#

Bases: DateTimeInfo

LongDatetimeInfo defines matchers: - _match_day_of_week_token - _match_month_token - _match_day_token - _match_fractional_seconds

The idea is to detect which pendulum token should be used for building date format. The matchers detect the required tokens and _build_long_date_format return the resulting pendulum format for matching date. We then take a cartesian product of the date format with an exhaustive list of time formats built using _build_time_formats. This cartesian product returns a list of long datetime formats, which can be used to parse date_time_raw string if it is a valid long datetime string. This cartesian product is performed by _build_long_datetime_formats_list

class ShortDateTimeInfo(date_time_raw: str, config: DatetimeConfig)[source]#

Bases: DateTimeInfo

ShortDateTime info defines matcher function for detecting date, time and timezone values