Add dayfirst option to Date and DateTime
This commit is contained in:
parent
ba2f66183c
commit
7dee2218ff
1 changed files with 8 additions and 1 deletions
|
|
@ -298,16 +298,23 @@ class Map(Filter):
|
||||||
|
|
||||||
|
|
||||||
class DateTime(Filter):
|
class DateTime(Filter):
|
||||||
|
def __init__(self, selector, default=_NO_DEFAULT, dayfirst=False):
|
||||||
|
super(DateTime, self).__init__(selector, default=default)
|
||||||
|
self.dayfirst = dayfirst
|
||||||
|
|
||||||
def filter(self, txt):
|
def filter(self, txt):
|
||||||
if empty(txt):
|
if empty(txt):
|
||||||
return txt
|
return txt
|
||||||
try:
|
try:
|
||||||
return parse_date(txt)
|
return parse_date(txt, dayfirst=self.dayfirst)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return self.default_or_raise(ParseError('Unable to parse %r: %s' % (txt, e)))
|
return self.default_or_raise(ParseError('Unable to parse %r: %s' % (txt, e)))
|
||||||
|
|
||||||
|
|
||||||
class Date(DateTime):
|
class Date(DateTime):
|
||||||
|
def __init__(self, selector, default=_NO_DEFAULT, dayfirst=False):
|
||||||
|
super(Date, self).__init__(selector, default=default, dayfirst=dayfirst)
|
||||||
|
|
||||||
def filter(self, txt):
|
def filter(self, txt):
|
||||||
datetime = super(Date, self).filter(txt)
|
datetime = super(Date, self).filter(txt)
|
||||||
if datetime is not None:
|
if datetime is not None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue