A few conveniences to do with dates and times.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cs_dateutils-20250724.tar.gz.
File metadata
- Download URL: cs_dateutils-20250724.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b9ebdcdd03044aba4a55ec772c602447d8a7249a111d746f3b61e25b818a0a5
|
|
| MD5 |
564a245e2290b3fb8f70098d56f2b36a
|
|
| BLAKE2b-256 |
50091aeb4969c31c54452419e408d3607bc03e29df043449f30d8d099d649598
|
File details
Details for the file cs_dateutils-20250724-py2.py3-none-any.whl.
File metadata
- Download URL: cs_dateutils-20250724-py2.py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b35fe82c6ff04418730b4795679c254f9744c58051cfcd3e942d410882d8bbb6
|
|
| MD5 |
5fcca5ab353cfe42b2eaa5d47a1e83a3
|
|
| BLAKE2b-256 |
565e420e5a7d0667386082e84b53f570b57644d4083942207309bc5e1e65d724
|