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:

datetime.datetime

ezcord.times.convert_time(seconds, relative=True, *, use_locale=None)[source]

Convert seconds to a human-readable time.

Parameters:
  • seconds (int | float) – The amount of seconds to convert.

  • 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 to None. If not provided, the language will be set to the default language.

Returns:

A human-readable time.

Return type:

str

ezcord.times.convert_dt(dt, relative=True, *, use_locale=None)[source]

Convert datetime or timedelta to a human-readable time.

This function calls convert_time().

Parameters:
Returns:

A human-readable time.

Return type:

str

ezcord.times.dc_timestamp(seconds, style='R')[source]

Convert seconds to a Discord timestamp.

Parameters:
Returns:

A Discord timestamp.

Return type:

str

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 to False, the function will return 0 instead. Defaults to False.

  • default_unit (Optional[Literal['s', 'm', 'h', 'd']]) – The default unit to use if no valid unit is specified. Defaults to m. If at least one valid unit is found, all numbers without a valid unit are ignored.

Returns:

The amount of seconds.

Return type:

int

Raises:
  • ConvertTimeError – No valid number was found, or default_unit is None 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