hikari.internal.time#

Utility methods used for parsing timestamps and datetimes from Discord.

Module Contents#

hikari.internal.time.datetime_to_discord_epoch(timestamp)[source]#

Parse a datetime.datetime object into an int DISCORD_EPOCH offset.

Parameters:
timestampdatetime.datetime

Number of seconds since 1/1/1970 00:00:00 UTC.

Returns:
int

Number of milliseconds since 1/1/2015 00:00:00 UTC.

hikari.internal.time.discord_epoch_to_datetime(epoch, /)[source]#

Parse a Discord epoch into a datetime.datetime object.

Parameters:
epochint

Number of milliseconds since 1/1/2015 00:00:00 UTC.

Returns:
datetime.datetime

Number of seconds since 1/1/1970 00:00:00 UTC.

hikari.internal.time.local_datetime()[source]#

Return the current date/time for the system’s time zone.

hikari.internal.time.monotonic()[source]#

Performance counter for benchmarking.

hikari.internal.time.timespan_to_int(value, /)[source]#

Cast the given timespan in seconds to an integer value.

Parameters:
valueIntervalish

The number of seconds.

Returns:
int

The integer number of seconds. Fractions are discarded. Negative values are removed.

hikari.internal.time.unix_epoch_to_datetime(epoch, /, *, is_millis=True)[source]#

Parse a UNIX epoch to a datetime.datetime object.

Note

If an epoch that’s outside the range of what this system can handle, this will return datetime.datetime.max if the timestamp is positive, or datetime.datetime.min otherwise.

Parameters:
epochtyping.Union[int, float]

Number of seconds/milliseconds since 1/1/1970 00:00:00 UTC.

is_millisbool

True by default, indicates the input timestamp is measured in milliseconds rather than seconds.

Returns:
datetime.datetime

Number of seconds since 1/1/1970 00:00:00 UTC.

hikari.internal.time.utc_datetime()[source]#

Return the current date/time for UTC (GMT+0).

hikari.internal.time.uuid()[source]#

Generate a unique UUID (1ns precision).

hikari.internal.time.DISCORD_EPOCH: Final[datetime.timedelta][source]#

Discord epoch used within snowflake identifiers.

This is defined as the timedelta of seconds between 1/1/1970 00:00:00 UTC and 1/1/2015 00:00:00 UTC.

References

hikari.internal.time.Intervalish[source]#

Type hint representing a naive time period or time span.

This is a type that is like an interval of some sort.

This is an alias for typing.Union[int, float, datetime.datetime], where int and float types are interpreted as a number of seconds.