DateUtils
Utility class providing helper methods for converting between datetime objects and formatted timestamp strings.
Supports both custom formats and two built-in formats commonly used across the Norman platform:
utc_format —
"YYYY-MM-DD HH:MM:SS.ssssss"Example:1970-01-01 00:00:00.000000iso_8061_format —
"YYYY-MM-DDTHH:MM:SS.ssssss+ZZZZ"Example:1970-01-01T00:00:00.000000+0000
These utilities are typically used for serialization, logging, persistence, or API interchange where consistent timestamp formatting is required.
Attributes
utc_format (
str) Default UTC timestamp format used when no format is provided.iso_8061_format (
str) ISO-8601–compliant timestamp format including timezone offset.
Methods
datetime_to_string(date_time, date_format=None) staticmethod
Convert a datetime object into a formatted timestamp string.
Parameters
date_time (
datetime) The datetime instance to convert.date_format (
Optional[str]) String format to use withstrftime. If not provided, defaults toDateUtils.utc_format.
Returns
str — The formatted timestamp string.
string_to_datetime(date_string, date_format=None) staticmethod
Parse a formatted timestamp string and convert it into a datetime object.
Parameters
date_string (
str) Timestamp string to parse.date_format (
Optional[str]) Format string to interpret the timestamp. If not provided, defaults toDateUtils.utc_format.
Returns
datetime — Parsed datetime instance.