Skip to main content

Dates

Library for formatting date-strings.

Introduction​

This library was created to make handling and formatting of dates from incoming datafiles easier. Oftentimes systems send dates in a standardized format (like ISO-date), that might need to be displayed with a different format in the rendered document. For this purpose, this library offers functions to convert and localize date-formats.
The function to convert / format a date is format_date while the others are mostly for internal use by that function.

PATTERNS​

KeyPatternOrdinal-placeholders (list)Localization-placeholders (list)
ddmmyyyy_localized_ordinal%d %B %Y%d%B 
ddmmyyyy_localized_time%d %B %Y, %H:%M %B
ddmmyyyy_localized%d %B %Y%B
mmddyyyy_localized%B %d, %Y%B
ddmmyyyy%d.%m.%Y
ddmmyyyy_hhmm%d.%m.%Y %H:%M
ddmmyyyy_hhmmss%d.%m.%Y %H:%M:%S
dmyy%d.%m.%y
hhmm%H:%M
hhmmss%H:%M:%S
hmm%I:%M
hmmss%I:%M:%S
yyyymmddhhmmss%d%m%Y%H%M%S
xmldatetime%d-%m-%YT%H:%M:%S
iso_time_colon%H:%M:%S
iso_time_hyphen%H-%M-%S
iso_date%Y-%m-%d
iso_date_time_colon%Y-%m-%d %H:%M:%S
iso_date_time_hyphen%Y-%m-%d %H-%M-%S
python_str%Y-%m-%d %H:%M:%S.%f

format_date(...)​

( string, output_format = "", input_format = "", my_locale = "" )​

Change the formatting of a date-time-string by giving a key to one of the available patterns as input- as well as output-format. If the pattern includes ordinal- or localization-placeholders, a locale should be given as well.

Parameters:string (str)
The date-time-string to be formatted. For example retrieved from the datafile.
output_format (str)
One of the keys to a pattern. If no valid pattern is given, iso_dateis used as output-format.
input_format (str)
One of the keys to a pattern. If no valid pattern is given, XML-date-time is used as input-format (%Y-%m-%dT%H:%M:%S%z).
my_locale (str)
The locale in which ordinals and localizable parts should be localized in. If no locale is given, the function tries to use the systems locale. Check the localizer-library for the available locales.
Returns:A string with changed date-formatting based on the given parameters or the original string, if the formatting couldn't be applied.
Return Type:str