date tools: class methods to convert date[time] objects
This commit is contained in:
parent
3ffee483b0
commit
aa72812b36
1 changed files with 10 additions and 1 deletions
|
|
@ -47,6 +47,10 @@ class date(real_date):
|
|||
def strftime(self, fmt):
|
||||
return strftime(self, fmt)
|
||||
|
||||
@classmethod
|
||||
def from_date(cls, d):
|
||||
return cls(d.year, d.month, d.day)
|
||||
|
||||
|
||||
class datetime(real_datetime):
|
||||
def strftime(self, fmt):
|
||||
|
|
@ -58,6 +62,10 @@ class datetime(real_datetime):
|
|||
def date(self):
|
||||
return date(self.year, self.month, self.day)
|
||||
|
||||
@classmethod
|
||||
def from_datetime(cls, dt):
|
||||
return cls(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond, dt.tzinfo)
|
||||
|
||||
|
||||
def new_date(d):
|
||||
""" Generate a safe date from a datetime.date object """
|
||||
|
|
@ -201,6 +209,7 @@ class LinearDateGuesser(object):
|
|||
self.set_current_date(parsed_date)
|
||||
return parsed_date
|
||||
|
||||
|
||||
class ChaoticDateGuesser(LinearDateGuesser):
|
||||
"""
|
||||
This class aim to find the guess the date when you know the
|
||||
|
|
@ -221,7 +230,6 @@ class ChaoticDateGuesser(LinearDateGuesser):
|
|||
raise ValueError("%s is inferior to min_date %s" % (parsed_date, self.min_date))
|
||||
|
||||
|
||||
|
||||
DATE_TRANSLATE_FR = [(re.compile(u'janvier', re.I), u'january'),
|
||||
(re.compile(u'février', re.I), u'february'),
|
||||
(re.compile(u'mars', re.I), u'march'),
|
||||
|
|
@ -251,6 +259,7 @@ DATE_TRANSLATE_FR = [(re.compile(u'janvier', re.I), u'january'),
|
|||
(re.compile(u'samedi', re.I), u'saturday'),
|
||||
(re.compile(u'dimanche', re.I), u'sunday')]
|
||||
|
||||
|
||||
def parse_french_date(date):
|
||||
for fr, en in DATE_TRANSLATE_FR:
|
||||
date = fr.sub(en, date)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue