Merge pull request #20 from jerry2yu/master

Add datafirst parameter to parse method. Set datafirst true to parse …
This commit is contained in:
2016-12-19 10:01:31 -08:00
committed by GitHub
2 changed files with 9 additions and 2 deletions
+3 -2
View File
@@ -196,13 +196,14 @@ def when(string, timezone='UTC'):
return MayaDT.from_datetime(dt)
def parse(string):
def parse(string, dayfirst=False):
""""Returns a MayaDT instance for the machine-produced moment specified.
Powered by dateutil. Accepts most known formats. Useful for working with data.
Keyword Arguments:
string -- string to be parsed
dayfirst -- if true, the first value in date string (e.g. 01/05/2016) is parsed as day; otherwise it is parsed as month (default: False)
"""
dt = dateutil.parser.parse(string)
dt = dateutil.parser.parse(string, dayfirst=dayfirst)
return MayaDT.from_datetime(dt)
+6
View File
@@ -83,4 +83,10 @@ def test_format():
d = maya.parse('February 21, 1994')
assert format(d) == '1994-02-21 00:00:00+00:00'
d = maya.parse('01/05/2016')
assert format(d) == '2016-01-05 00:00:00+00:00'
d = maya.parse('01/05/2016', dayfirst=True)
assert format(d) == '2016-05-01 00:00:00+00:00'
# rand_day = maya.when('2011-02-07', timezone='US/Eastern')