Utils Dates
inyoka.utils.dates
Various utilities for datetime handling.
- copyright:
2007-2025 by the Inyoka Team, see AUTHORS for more details.
- license:
BSD, see LICENSE for more details.
- inyoka.utils.dates._localtime(val)
- inyoka.utils.dates.datetime_to_timezone(dt)
Convert a datetime object to the user’s timezone or the instance default timezone.
If the object is None, it’s returned unchanged.
- inyoka.utils.dates.format_date(value, arg='DATE_FORMAT')
- inyoka.utils.dates.format_datetime(value, arg='DATETIME_FORMAT')
- inyoka.utils.dates.format_time(value, arg='TIME_FORMAT')
- inyoka.utils.dates.format_timetz(value, arg='TIME_FORMAT')
- inyoka.utils.dates.get_timezone_list()
- Returns a set of available timezones.
the set is only created once on the first call and cached afterwards
it excludes deprecated names (taken from the IANA’s Time Zone Database)
The used code is from Adam Johnson’s blog post https://adamj.eu/tech/2021/05/06/how-to-list-all-timezones-in-python/ © 2021 All rights reserved. Code samples are public domain unless otherwise noted.
- inyoka.utils.dates.group_by_day(entries, date_func=operator.attrgetter('pub_date'), enforce_utc=False)
Group a list of entries by the date but in the users’ timezone (or UTC if enforce_utc is set to True). Per default the pub_date Attribute is used. If this is not desired a different date_func can be provided. It’s important that the list is already sorted by date otherwise the behavior is undefined.
- inyoka.utils.dates.naturalday(value, arg='DATE_FORMAT')