Datetime Parser Implementations¶
Parser implementations for types provided in the datetime package.
Enumerations¶
- enum disnake_compass.impl.parser.datetime.Resolution(value)[source]¶
-
The resolution with which
datetime.datetimes etc. are stored.Member type:
float- MICROS = 1e-06¶
Microsecond resolution.
This is the default for the datetime module, but often more than required.
- MILLIS = 0.001¶
Millisecond resolution.
Rounds the datetime down to the nearest microsecond.
- SECONDS = 1.0¶
Second resolution.
Rounds the datetime down to the nearest second.
- MINUTES = 60.0¶
Minute resolution.
Rounds the datetime down to the nearest minute.
- HOURS = 3600.0¶
Hour resolution.
Rounds the datetime down to the nearest hour.
- DAYS = 86400.0¶
Day resolution.
Rounds the datetime down to the nearest day.
Classes¶
- class disnake_compass.impl.parser.datetime.DatetimeParser(int_parser=NOTHING, *, resolution=Resolution.SECONDS, timezone=datetime.timezone.utc, strict=True)[source]¶
-
Parser type with support for datetimes.
- Parameters:
int_parser (
IntParser) – TheIntParserto use internally for this parser.resolution (
int|float) – The resolution with which to storedatetimes in custom ids. Defaults toResolution.SECONDS.timezone (
timezone) – The timezone to use for parsing. Defaults todatetime.timezone.utc.strict (
bool) – Whether this parser is in strict mode. Defaults toTrue.
Attributes¶
-
int_parser:
IntParser¶ The
IntParserto use internally for this parser.Since the default integer parser uses base-36 to “compress” numbers, the default datetime parser will also return compressed results.
-
resolution:
int|float¶ The resolution with which to store
datetimes in seconds.Warning
The resolution must be greater than
1e-6, and if the resolution is smaller than 1, it must be a power of 10. If the resolution is greater than 1, it is coerced into an integer.Note
Python datetime objects have microsecond accuracy. For most applications, this is much more precise than necessary. Since custom id space is limited, seconds was chosen as the default.
Methods¶
- await dumps(argument, /)[source]¶
Dump a datetime into a string.
This uses the underlying
int_parser.If
strictis set toTrue, this will fail if the providedargumentdoes not have a timezone set. Otherwise, a timezone-naive datetime will automatically get its timezone set totimezone.- Parameters:
argument (
datetime) – The value that is to be dumped.- Raises:
ValueError – Either the parser is set to strict and the provided datetime was timezone-naive, or the provided datetime’s timezone does not match that of the parser.
- await loads(argument, /)[source]¶
Load a datetime from a string.
This uses the underlying
int_parser.The returned datetime is always of the specified
timezone.- Parameters:
argument (
str) – The string that is to be converted into a datetime.
- class disnake_compass.impl.parser.datetime.TimedeltaParser(int_parser=NOTHING, *, resolution=Resolution.SECONDS)[source]¶
-
Parser type with support for
datetime.timedeltas.- Parameters:
int_parser (
IntParser) – TheIntParserto use internally for this parser.resolution (
int|float) – The resolution with which to storetimedeltas in custom ids. Defaults toResolution.SECONDS.
Attributes¶
-
int_parser:
IntParser¶ The
IntParserto use internally for this parser.Since the default integer parser uses base-36 to “compress” numbers, the default datetime parser will also return compressed results.
-
resolution:
int|float¶ The resolution with which to store
timedeltas in seconds.Warning
The resolution must be greater than
1e-6, and if the resolution is smaller than 1, it must be a power of 10. If the resolution is greater than 1, it is coerced into an integer.Note
Python datetime objects have microsecond accuracy. For most applications, this is much more precise than necessary. Since custom id space is limited, seconds was chosen as the default.
Methods¶
- await dumps(argument, /)[source]¶
Dump a timedelta into a string.
This uses the underlying
int_parser.- Parameters:
argument (
timedelta) – The value that is to be dumped.
- await loads(argument, /)[source]¶
Load a timedelta from a string.
This uses the underlying
int_parser.- Parameters:
argument (
str) – The string that is to be converted into a timedelta.
- class disnake_compass.impl.parser.datetime.DateParser(int_parser=NOTHING)[source]¶
-
Parser type with support for dates.
- Parameters:
int_parser (
IntParser) – TheIntParserto use internally for this parser.
Attributes¶
Methods¶
- await dumps(argument, /)[source]¶
Dump a datetime into a string.
This uses the underlying
int_parser.- Parameters:
argument (
date) – The value that is to be dumped.
- await loads(argument, /)[source]¶
Load a date from a string.
This uses the underlying
int_parser.- Parameters:
argument (
str) – The string that is to be converted into a date.
- class disnake_compass.impl.parser.datetime.TimeParser(timedelta_parser=NOTHING, *, strict=True, timezone=datetime.timezone.utc)[source]¶
-
Parser type with support for times.
Important
Unlike
DatetimeParseretc., resolution for this class is set via the underlyingtimedelta_parser. Note that this class does proxy it through theprecisionproperty, which supports both getting and setting.- Parameters:
timedelta_parser (
TimedeltaParser) – TheTimedeltaParserto use internally for this parser.strict (
bool) – Whether this parser is in strict mode. Defaults toTrue.timezone (
timezone) – The timezone to use for parsing. Defaults todatetime.timezone.utc.
Attributes¶
- property resolution: int | float[source]¶
The resolution with which to store
times in seconds.Warning
The resolution must be greater than
1e-6, and if the resolution is smaller than 1, it must be a power of 10. If the resolution is greater than 1, it is coerced into an integer.Note
Python time objects have microsecond accuracy. For most applications, this is much more precise than necessary. Since custom id space is limited, seconds was chosen as the default.
-
strict:
bool¶ Whether the parser is in strict mode.
If the parser is in strict mode,
loads()requires the provided datetime object to be of the correcttimezone.
-
timedelta_parser:
TimedeltaParser¶ The
TimedeltaParserto use internally for this parser.Since the default timedelta parser uses base-36 to “compress” numbers, the default datetime parser will also return compressed results.
Methods¶
- await dumps(argument, /)[source]¶
Dump a time into a string.
This uses the underlying
timedelta_parser.If
strictis set toTrue, this will fail if the providedargumentdoes not have a timezone set. Otherwise, a timezone-naive time will automatically get its timezone set totimezone.- Parameters:
argument (
time) – The value that is to be dumped.- Raises:
ValueError – Either the parser is set to strict and the provided time was timezone-naive, or the provided time’s timezone does not match that of the parser.
- await loads(argument, /)[source]¶
Load a time from a string.
This uses the underlying
timedelta_parser.The returned time is always of the specified
timezone.- Parameters:
argument (
str) – The string that is to be converted into a time.
- class disnake_compass.impl.parser.datetime.TimezoneParser(timedelta_parser=NOTHING)[source]¶
-
Parser type with support for
timezones.Important
Unlike
DatetimeParseretc., resolution for this class is set via the underlyingtimedelta_parser. Note that this class does proxy it through theprecisionproperty, which supports both getting and setting.- Parameters:
timedelta_parser (
TimedeltaParser) – TheTimedeltaParserto use internally for this parser.
Attributes¶
- property resolution: int | float[source]¶
The resolution with which to store
times in seconds.Warning
The resolution must be greater than
1e-6, and if the resolution is smaller than 1, it must be a power of 10. If the resolution is greater than 1, it is coerced into an integer.Note
Python time objects have microsecond accuracy. For most applications, this is much more precise than necessary. Since custom id space is limited, seconds was chosen as the default.
-
timedelta_parser:
TimedeltaParser¶ The
TimedeltaParserto use internally for this parser.Since the default timedelta parser uses base-36 to “compress” numbers, the default datetime parser will also return compressed results.
Methods¶
- await dumps(argument, /)[source]¶
Dump a timezone into a string.
This uses the underlying
timedelta_parser.- Parameters:
argument (
timezone) – The value that is to be dumped.
- await loads(argument, /)[source]¶
Load a timezone from a string.
This uses the underlying
timedelta_parser.- Parameters:
argument (
str) – The string that is to be converted into a timezone.