Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support macOS, where /usr/share/zoneinfo/posix doesn't exist #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ccaviness
Copy link

In this case, iterate through the files in /usr/share/zoneinfo, skipping
unreadable files.

This allows datetime_tz.datetime_tz.smartparse to work in most cases.

Currently:

❯ python3
Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime_tz
>>> datetime_tz.datetime_tz.smartparse('Feb 22 00:30:04')
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/datetime_tz/__init__.py:335: UserWarning: We detected no matches for your /etc/localtime.
  warnings.warn("We detected no matches for your /etc/localtime.")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/datetime_tz/__init__.py", line 606, in smartparse
    default = dt.replace(hour=0, minute=0, second=0, microsecond=0)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/datetime_tz/__init__.py", line 564, in replace
    replaced, tzinfo=tzinfo or self.tzinfo.zone, is_dst=is_dst)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/datetime_tz/__init__.py", line 425, in __new__
    tzinfo = _tzinfome(kw.pop("tzinfo"))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/datetime_tz/__init__.py", line 100, in _tzinfome
    assert tzinfo.zone in pytz.all_timezones
AssertionError

With this commit:

❯ python3
Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime_tz
>>> datetime_tz.datetime_tz.smartparse('Feb 22 00:30:04')
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/datetime_tz/__init__.py:326: UserWarning: Skipping posixrules because not in pytz database.
  warnings.warn("Skipping %s because not in pytz database." % tzname)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/datetime_tz/__init__.py:338: UserWarning: We detected multiple matches for your /etc/localtime. (Matches where [<DstTzInfo 'America/New_York' LMT-1 day, 19:04:00 STD>, <DstTzInfo 'US/Eastern' LMT-1 day, 19:04:00 STD>])
  "(Matches where %s)" % matches)
datetime_tz(2021, 2, 22, 0, 30, 4, tzinfo=<DstTzInfo 'America/New_York' EST-1 day, 19:00:00 STD>)
>>>

In this case, iterate through the files in `/usr/share/zoneinfo`, skipping
unreadable files.
@mithro mithro requested a review from micolous February 24, 2021 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant