bh_utils.date_funcs module

Some date routines.

On ISO 8601 date time see:

Functions in this module handle, or rather assume, local time only. They haven’t yet taken UTC into account. That is, date time output is in the format YYYY-MM-DD["T"HH:MM:SS] only.

For usage examples, see ./tests/test_date_funcs.py.

bh_utils.date_funcs.australian_date_to_iso_datetime(date_time_data, time=True)
bh_utils.date_funcs.australian_date_to_iso_datetime(params: dict, time=True) tuple
bh_utils.date_funcs.australian_date_to_iso_datetime(date_str: str, time=True) str

Convert Australian date to ISO 8601 date and time format.

This is an overloaded function.

Australian date is in string format: D/M/YYYY HH:MM:SS [AM|PM], DD/MM/YYYY, etc. I.e., date and month can be either a single character without a leading 0, or a two characters consist of a leading 0 and a non-0 digit.

If the input string has the time component, it must be a 12-hour time, and must be in the format: HH:MM:SS [AM|PM]. E.g., 01:23:34 PM.

  1. Overload version 1:

Parameters:

params (dict) – a dictionary contains two (2) input Australian date strings. The dictionary keys are startDate and endDate.

Returns:

a tuple of two (2) strings in the format YYYY-MM-DD["T"HH:MM:SS], which is the ISO version of startDate and endDate.

Return type:

tuple.

  1. Overload version 2:

Parameters:

date_str (str) – the input Australian date string.

Returns:

a string in the format YYYY-MM-DD["T"HH:MM:SS], which is the ISO version of date_str.

Return type:

str.

Finally, the common parameter:

Parameters:

time (bool) – whether to include the time component in the output value.

  1. Overload version 1, usage example:

    d1, d2 = australian_date_to_iso_datetime({'startDate': '29/1/2022',
        'endDate': '1/12/2022'}, False)
    
    assert d1 == '2022-01-29'
    assert d2 == '2022-12-01'
    
  2. Overload version 2, usage example:

    date_str = australian_date_to_iso_datetime('29/1/2022', False)
    
    assert date_str == '2022-01-29'