mirror of
https://github.com/kennethreitz/maya.git
synced 2026-06-05 23:00:18 +00:00
when timezone
This commit is contained in:
+9
-4
@@ -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...
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user