datetime_interface#

tools.datetime_interface.compare_crontab(datestr, cronstr, frmttyp)[source]#

DESCRIPTION:

This function compares the user-specified date to the a crontab formatted value and returns a boolean value specifying whether the crontab string (specifying when to execute an action) and user-specified date match.

Parameters:
datestr: str

A Python string containing a date string.

cronstr: str

A Python string specifying a crontab formatted date string for which to perform an action.

frmttyp: str

A Python string specifying the format of the timestamps string; this assumes POSIX convention date attribute characters.

Returns:
crontab_match: bool

A Python boolean valued variable specifying whether the crontab string (specifying when to execute an action) and a date match.

Return type:

bool

tools.datetime_interface.current_date(frmttyp, is_utc=True)[source]#

DESCRIPTION:

This function returns the current time (at invocation of this function) formatted according to the parameter values specified upon entry.

Parameters:
frmttyp: str

A Python string specifying the format of the output timestamp string; this assumes POSIX convention date attribute characters.

Returns:
timestamp: str

A Python string containing the current time (at invocation of this function) formatted according to the user specifications.

Return type:

str

tools.datetime_interface.datestrcomps(datestr, frmttyp)[source]#

DESCRIPTION:

This function returns a Python object containing the specified date string component values; the following attributes are returned: :rtype: SimpleNamespace

  • year (year)

  • month of year (month)

  • day of month (day)

  • hour of day (hour)

  • minute of hour (minute)

  • second of minute (second)

  • full month name (month_name_long)

  • abbreviated month name (month_name_short)

  • full day name (weekday_long)

  • abbreviated day name (weekday_short)

  • 2-digit century (e.g., 2015 is 20; century_short)

  • 2-digit year (e.g., year without the century value; year_short)

  • date string (date_string; formatted as %Y-%m-%d_%H:%M:%S, assuming the POSIX convention)

  • cycle string (cycle_string; formatted as %Y%m%d%H, assuming the POSIX convention)

  • Julian date (julian_day)

  • The HH:MM:SS as the total elapsed seconds, formatted as 5-digit integer (total_seconds_of_day)

  • The day of the year (day_of_year); begins from day 1 of respective year.

  • epoch (seconds since 0000 UTC 01 January 1970).

Parameters:
datestr: str

A Python string containing a date string.

frmttyp: str

A Python string specifying the format for the input date string (datestr).

Returns:
date_comps_obj: SimpleNamespace

A Python SimpleNamespace object containing the date string component values for the user specfied date string.

tools.datetime_interface.datestrfrmt(datestr, frmttyp, offset_seconds=None)[source]#

DESCRIPTION:

This function ingests a date string and computes and returns a (newly/different) formatted date string; the format of the respective date string is defined by the frmttyp parameter specified upon entry; an optional keyword offset_seconds defines a datestr relative to the value for parameter datestr and the the specified number of seconds; both positive and negative values for offset_seconds is supported.

Parameters:
datestr: str

A Python string containing a date string; the input date string is assumed to have format %Y-%m-%d_%H:%M:%S assuming the POSIX convention.

frmttyp: str

A Python string specifying the format of the timestamps string; this assumes POSIX convention date attribute characters.

Returns:
outdatestr: str

A Python string containing the appropriately formatted time-stamp/date-string.

Return type:

str

tools.datetime_interface.datestrupdate(datestr, in_frmttyp, out_frmttyp, offset_seconds=None)[source]#

DESCRIPTION:

This function ingests a date string and an optional argument offset_seconds to define a new datestr relative to the user provided datestr and the number of seconds and the input and output date string formats; this function also permits non-POSIX standard time attributes, as determined by datestrcomps (above) and user specified template values (denoted between < > in the out_frmttyp parameter).

Parameters:
datestr: str

A Python string containing a date string of format in_frmttyp (see below).

in_frmttyp: str

A Python string specifying the POSIX convention for the datestr variable upon input.

out_frmttyp: str

A Python string specifying the POSIX convention for the datestr variable upon output.

Returns:
outdatestr: str

A Python string containing the appropriately formatted time-stamp/date-string.

Return type:

str

tools.datetime_interface.elapsed_seconds(start_datestr, start_frmttyp, stop_datestr, stop_frmttyp)[source]#

DESCRIPTION:

This function computes and returns the total number of seconds (e.g., the difference) between two input date strings.

Parameters:
start_datestr: str

A Python string containing a date string of format start_frmttyp (below).

start_frmttyp: str

A Python string specifying the POSIX convention for the start_datestr variable.

stop_datestr: str

A Python string containing a date string of format stop_frmttyp (below).

stop_frmttyp: str

A Python string specifying the POSIX convention for the stop_datestr variable.

Returns:
seconds: float

A Python float value specifying the total number of seconds between the two input date strings.

Return type:

float

tools.datetime_interface.epoch_to_datestr(epoch_seconds, out_frmttyp=None)[source]#

DESCRIPTION:

This function transforms the epoch time (e.g., the number of seconds relative to 0000 UTC 01 January 1970) to the (optional) date-string format (out_frmttyp).

Parameters:
epoch_seconds: int

A Python integer specifying the epoch seconds.

Returns:
epoch_datestr: str

A Python string defining the epoch time (seconds) represented as date-string characters.

Return type:

str