hikari.internal.time#
Utility methods used for parsing timestamps and datetimes from Discord.
Module Contents#
- 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]
, whereint
andfloat
types are interpreted as a number of seconds.
- 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
and1/1/2015 00:00:00 UTC
.References
[Discord API documentation - Snowflakes](https://discord.com/developers/docs/reference#snowflakes)
- hikari.internal.time.discord_epoch_to_datetime(epoch, /)[source]#
Parse a Discord epoch into a
datetime.datetime
object.- Parameters
- epoch
int
Number of milliseconds since
1/1/2015 00:00:00 UTC
.
- epoch
- Returns
datetime.datetime
Number of seconds since
1/1/1970 00:00:00 UTC
.
- hikari.internal.time.datetime_to_discord_epoch(timestamp)[source]#
Parse a
datetime.datetime
object into anint
DISCORD_EPOCH
offset.- Parameters
- timestamp
datetime.datetime
Number of seconds since
1/1/1970 00:00:00 UTC
.
- timestamp
- Returns
int
Number of milliseconds since
1/1/2015 00:00:00 UTC
.
- 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, ordatetime.datetime.min
otherwise.- Parameters
- epoch
typing.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.
- epoch
- Returns
datetime.datetime
Number of seconds since
1/1/1970 00:00:00 UTC
.
- hikari.internal.time.timespan_to_int(value, /)[source]#
Cast the given timespan in seconds to an integer value.
- Parameters
- value
Intervalish
The number of seconds.
- value
- Returns
int
The integer number of seconds. Fractions are discarded. Negative values are removed.