Time¶
- ezcord.times.set_utc(dt)[source]¶
Set the timezone of a datetime object to UTC.
- Parameters:
dt (
datetime
) – The datetime object to set the timezone of.- Return type:
- ezcord.times.convert_time(seconds, relative=True, *, use_locale=None)[source]¶
Convert seconds to a human-readable time.
- Parameters:
relative (
bool
) –Whether to use relative time. Defaults to
True
.Hint
This is only needed for German translation and will not have any effect if the language is set to English.
>>> convert_time(450000, relative=True) # Relative: Seit 5 Tagen '5 Tagen' >>> convert_time(450000, relative=False) # Not relative: 5 Tage '5 Tage'
use_locale (
Union
[Interaction
,ApplicationContext
,InteractionResponse
,Webhook
,Guild
,Member
,None
]) – The object to get the language from. Defaults toNone
. If not provided, the language will be set to the default language.
- Returns:
A human-readable time.
- Return type:
- ezcord.times.convert_dt(dt, relative=True, *, use_locale=None)[source]¶
Convert
datetime
ortimedelta
to a human-readable time.This function calls
convert_time()
.- Parameters:
dt (
datetime
|timedelta
) – The datetime or timedelta object to convert.relative (
bool
) – Whether to use relative time. Defaults toTrue
.use_locale (
Union
[Interaction
,ApplicationContext
,InteractionResponse
,Webhook
,Guild
,Member
,None
]) – The interaction to get the language from. Defaults toNone
. If not provided, the language will be set to the default language.
- Returns:
A human-readable time.
- Return type:
- ezcord.times.dc_timestamp(seconds, style='R')[source]¶
Convert seconds to a Discord timestamp.
- Parameters:
style (
str
) – The style of the timestamp. Defaults toR
. For more information, seediscord.utils.format_dt()
.
- Returns:
A Discord timestamp.
- Return type:
- ezcord.times.convert_to_seconds(string, error=False, default_unit='m')[source]¶
Convert a string to seconds. Supports multiple units and decimal separators.
- Parameters:
string (
str
) – The string to convert.error (
bool
) – Whether to raise an error if the string could not be converted. If set toFalse
, the function will return0
instead. Defaults toFalse
.default_unit (
Optional
[Literal
['s'
,'m'
,'h'
,'d'
]]) – The default unit to use if no valid unit is specified. Defaults tom
. If at least one valid unit is found, all numbers without a valid unit are ignored.
- Returns:
The amount of seconds.
- Return type:
- Raises:
ConvertTimeError – No valid number was found, or
default_unit
isNone
while no valid unit was found.DurationError – The duration is too long.
Example
>>> convert_to_seconds("1m 9s") 69 >>> convert_to_seconds("1.5m") 90 >>> convert_to_seconds("1,5 min") 90 >>> convert_to_seconds("1h 5m 10s") 3910