google.cloud.forseti.common.util.date_time module

Common utility functions regarding date and time.

exception DateTimeTypeConversionError[source]

Bases: google.cloud.forseti.common.util.date_time.Error

Type Error for a given Request.

exception DateTimeValueConversionError[source]

Bases: google.cloud.forseti.common.util.date_time.Error

Invalid Value Given for a Request.

exception Error[source]

Bases: Exception

A Base UtilDateTime Exception.

get_date_from_microtimestamp(microtimestamp)[source]

Get a datetime object from a 64bit timestamp.

Parameters:microtimestamp (int) – A timestamp to be converted.
Returns:The converted datetime object
Return type:datetime
get_datetime_from_string(string, string_format)[source]

Get a datetime object from a string in the requested string_format.

Parameters:
  • string (str) – The timestamp in the form of a string.
  • string_format (str) – A string used for formatting.
Raises:
Returns:

A datetime object as requested.

Return type:

datetime

get_unix_timestamp_from_string(string)[source]

Parse string to a unix timestamp, as seconds since epoch.

Parameters:string (str) – The time string to parse.
Returns:The timestamp in seconds.
Return type:int
Raises:ValueError – Raised for unknown string formats.
get_utc_now_datetime()[source]

Get a datetime object for utcnow()

Returns:A datetime object representing utcnow().
Return type:datetime
get_utc_now_microtimestamp(date=None)[source]

Get a 64bit int representing the current time to the millisecond.

Parameters:date (datetime) – A datetime object representing current time in UTC.
Returns:A epoch timestamp including microseconds.
Return type:int
get_utc_now_timestamp(date=None)[source]

Get a formatted str representing utcnow()

Parameters:date (datetime) – A datetime object representing current time in UTC.
Returns:A timestamp in the classes default timestamp format.
Return type:str
get_utc_now_timestamp_human(date=None)[source]

Get a human formatted str representing utcnow()

Parameters:date (datetime) – A datetime object representing current time in UTC.
Returns:A timestamp in the classes default timestamp format.
Return type:str
get_utc_now_unix_timestamp(date=None)[source]

Get a 64bit int representing the current time to the millisecond.

Parameters:date (datetime) – A datetime object representing current time in UTC.
Returns:A epoch timestamp including microseconds.
Return type:int