when timezone

This commit is contained in:
2016-12-15 21:50:29 -05:00
parent 8a8d97239d
commit e0490aaec4
2 changed files with 11 additions and 7 deletions
+9 -4
View File
@@ -24,10 +24,15 @@ Just playing with an API here::
>>> tomorrow.datetime()
datetime.datetime(2016, 12, 16, 15, 11, 30, 263350, tzinfo=<UTC>)
>>> tomorrow.year
2016
>>> rand_day = maya.when('2011-02-07', timezone='US/Eastern')
<MayaDT epoch=1297036800.0>
>>> tomorrow.microseconds
263350
# Note how this is the 6th, not the 7th.
>>> rand_day.day
6
# Always.
>>> rand_day.timezone
<UTC>
Timezones fit in here somewhere...
+2 -3
View File
@@ -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()