A few conveniences to do with dates and times.
Latest release 20250724:
- unixtime2datetime: default tz now UTC.
- Some doc updates.
There are some other PyPI modules providing richer date handling
than the stdlib datetime module.
This module mostly contains conveniences used in my other code;
you're welcome to it, but it does not pretend to be large or complete.
Short summary:
datetime2unixtime: Convert a timezone awaredatetimeto a UNIX timestamp. WARNING: a naive datetime is assumed to be in UTC.isodate: Return a date in ISO8601 YYYY-MM-DD format, or YYYYMMDD if notdashed.localdate2unixtime: Convert a localtimedateinto a UNIX timestamp.tzinfoHHMM: tzinfo class based on +HHMM / -HHMM strings.unixtime2datetime: Convert a a UNIX timestamp to adatetimein the timezonetz. Note: the default timezone is UTC, not the local timezone.UNIXTimeMixin: A mixin for classes with a.unixtimeattribute, afloatstoring a UNIX timestamp.
Module contents:
-
datetime2unixtime(dt): Convert a timezone awaredatetimeto a UNIX timestamp. WARNING: a naive datetime is assumed to be in UTC. -
isodate(when=None, dashed=True): Return a date in ISO8601 YYYY-MM-DD format, or YYYYMMDD if notdashed.Modern Pythons have a
datetime.isoformatmethod, you should use that. -
localdate2unixtime(d): Convert a localtimedateinto a UNIX timestamp. -
class tzinfoHHMM(datetime.tzinfo): tzinfo class based on +HHMM / -HHMM strings. -
unixtime2datetime(unixtime, *, tz: datetime.tzinfo = datetime.timezone.utc): Convert a a UNIX timestamp to adatetimein the timezonetz. Note: the default timezone is UTC, not the local timezone. -
class UNIXTimeMixin: A mixin for classes with a.unixtimeattribute, afloatstoring a UNIX timestamp.
UNIXTimeMixin.as_datetime(self, tz: datetime.tzinfo = datetime.timezone.utc):
Return self.unixtime as a datetime
with the timezone tz (default UTC).
UNIXTimeMixin.datetime:
The unixtime as a UTC datetime.
Release Log
Release 20250724:
- unixtime2datetime: default tz now UTC.
- Some doc updates.
Release 20230210:
- Drop Python 2 support.
- Make timezones mandatory where previously they were assumed.
Release 20210306: Initial release, used by cs.sqltags.
Metadata
Release files for cs-dateutils 20250724
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cs_dateutils-20250724.tar.gz | 2.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cs_dateutils-20250724-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 6.5 kB
Release files / cs_dateutils-20250724.tar.gz
| Download URL | cs_dateutils-20250724.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b9ebdcdd03044aba4a55ec772c602447d8a7249a111d746f3b61e25b818a0a5
|
|
BLAKE2b-256 checksum How to use checksums |
50091aeb4969c31c54452419e408d3607bc03e29df043449f30d8d099d649598
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / cs_dateutils-20250724-py2.py3-none-any.whl
| Download URL | cs_dateutils-20250724-py2.py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b35fe82c6ff04418730b4795679c254f9744c58051cfcd3e942d410882d8bbb6
|
|
BLAKE2b-256 checksum How to use checksums |
565e420e5a7d0667386082e84b53f570b57644d4083942207309bc5e1e65d724
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Security for cs-dateutils 20250724
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.