From e0490aaec48ac68e74e4bbcda02e0ae136f361bd Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 15 Dec 2016 21:50:29 -0500 Subject: [PATCH] when timezone --- README.rst | 13 +++++++++---- maya.py | 5 ++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 5f982b6..5b44651 100644 --- a/README.rst +++ b/README.rst @@ -24,10 +24,15 @@ Just playing with an API here:: >>> tomorrow.datetime() datetime.datetime(2016, 12, 16, 15, 11, 30, 263350, tzinfo=) - >>> tomorrow.year - 2016 + >>> rand_day = maya.when('2011-02-07', timezone='US/Eastern') + - >>> tomorrow.microseconds - 263350 + # Note how this is the 6th, not the 7th. + >>> rand_day.day + 6 + + # Always. + >>> rand_day.timezone + Timezones fit in here somewhere... diff --git a/maya.py b/maya.py index c02c5f1..31d98fa 100644 --- a/maya.py +++ b/maya.py @@ -66,7 +66,6 @@ class MayaDT(object): def timezone(self): return pytz.timezone(self._timezone) - def iso8601(self): return '{}Z'.format(self.datetime().isoformat()) @@ -94,8 +93,8 @@ def now(): epoch = time.time() return MayaDT(epoch=epoch) -def when(string): - dt = dateparser.parse(string) +def when(string, timezone='UTC'): + dt = dateparser.parse(string, settings={'TIMEZONE': timezone}) if dt is None: raise ValueError('invalid datetime input specified.') epoch = (dt - Datetime(*__epoch_start)).total_seconds()