Skip to content

Commit

Permalink
Merge branch 'main' into experiment/coherent
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Aug 5, 2024
2 parents 17bfd32 + 27efe48 commit 5b97814
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
__requires__ = [
'pytz',
'jaraco.functools>=1.20',
'python-dateutil',
'pytest-freezer; extra=="test"',
'types-pytz; extra=="test"',
'types-python-dateutil; extra=="test"',
]

import datetime
Expand All @@ -17,6 +19,9 @@
from typing import Union, Tuple, Iterable
from typing import cast

import dateutil.parser
import dateutil.tz


# some useful constants
osc_per_year = 290_091_329_207_984_000
Expand Down Expand Up @@ -618,3 +623,40 @@ def date_range(start=None, stop=None, step=None):
while start < stop:
yield start
start += step


tzinfos = dict(
AEST=dateutil.tz.gettz("Australia/Sydney"),
AEDT=dateutil.tz.gettz("Australia/Sydney"),
ACST=dateutil.tz.gettz("Australia/Darwin"),
ACDT=dateutil.tz.gettz("Australia/Adelaide"),
AWST=dateutil.tz.gettz("Australia/Perth"),
EST=dateutil.tz.gettz("America/New_York"),
EDT=dateutil.tz.gettz("America/New_York"),
CST=dateutil.tz.gettz("America/Chicago"),
CDT=dateutil.tz.gettz("America/Chicago"),
MST=dateutil.tz.gettz("America/Denver"),
MDT=dateutil.tz.gettz("America/Denver"),
PST=dateutil.tz.gettz("America/Los_Angeles"),
PDT=dateutil.tz.gettz("America/Los_Angeles"),
GMT=dateutil.tz.gettz("Etc/GMT"),
UTC=dateutil.tz.gettz("UTC"),
CET=dateutil.tz.gettz("Europe/Berlin"),
CEST=dateutil.tz.gettz("Europe/Berlin"),
IST=dateutil.tz.gettz("Asia/Kolkata"),
BST=dateutil.tz.gettz("Europe/London"),
MSK=dateutil.tz.gettz("Europe/Moscow"),
EET=dateutil.tz.gettz("Europe/Helsinki"),
EEST=dateutil.tz.gettz("Europe/Helsinki"),
# Add more mappings as needed
)


def parse(*args, **kwargs):
"""
Parse the input using dateutil.parser.parse with friendly tz support.
>>> parse('2024-07-26 12:59:00 EDT')
datetime.datetime(...America/New_York...)
"""
return dateutil.parser.parse(*args, tzinfos=tzinfos, **kwargs)

0 comments on commit 5b97814

Please sign in to comment.