Back to index

moin  1.9.0~rc2
Functions | Variables
MoinMoin.support.xappy.parsedate Namespace Reference

Functions

def date_from_string

Variables

string __docformat__ = "restructuredtext en"
tuple yyyymmdd_re = re.compile(r'(?P<year>[0-9]{4})(?P<month>[0-9]{2})(?P<day>[0-9]{2})$')
tuple yyyy_mm_dd_re = re.compile(r'(?P<year>[0-9]{4})([-/.])(?P<month>[0-9]{2})\2(?P<day>[0-9]{2})$')

Function Documentation

Parse a string into a date.

If the value supplied is already a date-like object (ie, has 'year',
'month' and 'day' attributes), it is returned without processing.

Supported date formats are:

 - YYYYMMDD
 - YYYY-MM-DD 
 - YYYY/MM/DD 
 - YYYY.MM.DD 

Definition at line 29 of file parsedate.py.

00029 
00030 def date_from_string(value):
00031     """Parse a string into a date.
00032 
00033     If the value supplied is already a date-like object (ie, has 'year',
00034     'month' and 'day' attributes), it is returned without processing.
00035 
00036     Supported date formats are:
00037 
00038      - YYYYMMDD
00039      - YYYY-MM-DD 
00040      - YYYY/MM/DD 
00041      - YYYY.MM.DD 
00042 
00043     """
00044     if (hasattr(value, 'year')
00045         and hasattr(value, 'month')
00046         and hasattr(value, 'day')):
00047         return value
00048 
00049     mg = yyyymmdd_re.match(value)
00050     if mg is None:
00051         mg = yyyy_mm_dd_re.match(value)
00052 
00053     if mg is not None:
00054         year, month, day = (int(i) for i in mg.group('year', 'month', 'day'))
00055         return datetime.date(year, month, day)
00056 
00057     raise ValueError('Unrecognised date format')

Variable Documentation

string MoinMoin.support.xappy.parsedate.__docformat__ = "restructuredtext en"

Definition at line 21 of file parsedate.py.

tuple MoinMoin.support.xappy.parsedate.yyyy_mm_dd_re = re.compile(r'(?P<year>[0-9]{4})([-/.])(?P<month>[0-9]{2})\2(?P<day>[0-9]{2})$')

Definition at line 27 of file parsedate.py.

tuple MoinMoin.support.xappy.parsedate.yyyymmdd_re = re.compile(r'(?P<year>[0-9]{4})(?P<month>[0-9]{2})(?P<day>[0-9]{2})$')

Definition at line 26 of file parsedate.py.