-í
wH<c       s›  d  Z  d k l Z d k Z d Z d Z d Z e d e d e d Z e d e d e d Z e d e d e d Z	 e i
 e e i ƒ Z e i
 e e i ƒ Z e i
 e	 e i ƒ Z h  e d	 <e d
 <e d <Z d Z d Z d Z e d e d e d Z e i
 e e i ƒ Z d e e i ƒ  i d ƒ d Z d „  Z d d „ Z d „  Z d d „ Z d d „ Z d d „ Z e d j o e ƒ  n d S(   sP  
The functions in this module are useful for data entry or bulk data
import, where dates are in an all-numeric format.  Because of the
possibility that the user might type the wrong thing in a numeric
field, or a data file might contain other data or garbage where a date
is expected, it is desirable to return None or raise an exception
when an invalid expression is encountered.

Dates can be in any of these formats: ymd, dmy, or mdy
with any single-character nondigit separator, two- or four-digit
year, and one- or two-digit month and day; or they can be in all-digits
ymd format with no separator, four-digit year, and two-digit
month and day (e.g. 20010803). 

In accordance with ISO 8601, two-digit years in all-numeric dates
are interpreted as referring to the current century.

Synopsis:
    DateTime = numericDateTime(datetimestring, formats='ymd mdy dmy'))
        Return value is based on date and (if any) time data in the string.
    DateTime = numericDate(datestring, formats='ymd mdy dmy'))
        Return value is based on date data in the string.
    DateTimeDelta = numericTime(timestring)
        Return value is based on time data in the string.

20010804 JJD Created, borrowing some regular expressions and
         ideas from mxDateTime's Parser module.

COPYRIGHT:
Placed into the Public Domain by J.J. Dukarm (jdukarm@hydracen.com).

(   s   DateTimeNs$   (?P<year>(?<![\d:])\d{2,4}(?![\d:]))s%   (?P<month>(?<![\d:])\d{1,2}(?![\d:]))s#   (?P<day>(?<![\d:])\d{1,2}(?![\d:]))s   (?P<sep>\D)s   (?P=sep)s   (?!\d)s   ymds   dmys   mdys   (?P<hour>[012]?\d)s   (?P<minute>[0-6]\d)s   (?P<second>[0-6]\d(?:\.\d+)?)s   :s   (?::s   )?iè  i    c    s:   d |  j o
 d j  n o |  t } n |  } | Sd S(   sÏ   
    According to ISO 8601, a two-digit year in an all-numeric date
    expression refers to the current century.
    If year has exactly two digits, add the century. Otherwise, return
    it unchanged.
    i    id   N(   s   years   _THIS_CENTURYs   result(   s   years   result(    (    sF   /mit/seven/lib/python2.2/site-packages/mx/DateTime/Examples/numdate.pys   _iso_add_century> s
     s   ymd mdy dmyc    sh  |  t j o t Sn t } | i ƒ  }
 t |
 ƒ d j } t |  ƒ i	 ƒ  } t | ƒ } | d d f j o
 |  i ƒ  o¼ | d } | d } | d } t t | d | !ƒ ƒ } t | | | !ƒ } t | | | !ƒ } y t i | | | ƒ } Wn? t i j
 o0 } t } | o t i d | | f ‚ n n Xn.x|
 D]ý } t | i ƒ  }	 |	 i | ƒ } | t j o q:n | i d ƒ } | i d	 ƒ } | i d
 ƒ } t t | ƒ ƒ } t | ƒ } t | ƒ } y t i | | | ƒ } Wn? t i j
 o0 } t } | o t i d | | f ‚ n n X| t j	 o Pn q:W| t j o | o t" d | ‚ n | Sd S(   sØ  
    If the input string s is a valid numeric date 
    expression according to one of the formats given, return
    a DateTime object with default time components.
    Date formats, separated by a single space character, are
    packed into a string.

    If only one date format is given, raise a ValueError if
    the string cannot be interpreted, and raise a DateTime
    RangeError if it can be interpreted but is not a valid date.

    If more than one date format is given, try each of them in order
    until a valid interpretation is found.  If the string does
    not represent a valid date, return None.  You can use one
    format twice (e.g. ['ymd', 'ymd']) to test only one format but
    suppress exceptions.
    i   i   i   i   i   i    s   '%s' invalid: %ss   years   months   days   unrecognized date format: '%s'N(#   s   ss   Nones   dts   formatss   splits
   formatlists   lens   exceptions_oks   strs   strips   _ss   len_ss   isdigits   k0s   k1s   k2s   _iso_add_centurys   ints   yys   mms   dds   DateTimes
   RangeErrors   whys   formats   _formatdicts   lowers	   format_res   searchs   matchs   groups   years   months   days
   ValueError(   s   ss   formatss   formats   months   dds   yys   years   dts   whys	   format_res
   formatlists   mms   _ss   days   k2s   k1s   k0s   len_ss   exceptions_oks   match(    (    sF   /mit/seven/lib/python2.2/site-packages/mx/DateTime/Examples/numdate.pys   numericDateK sT       # 	c 	   sà   |  t j o t Sn t } t i |  ƒ } | t j	 o¡ | i d ƒ } | i d ƒ } | i d ƒ } t
 | ƒ } t
 | ƒ } | o t | ƒ } n d } y t i d | | | ƒ } Wn t i j
 o t } n Xn | Sd S(   s¶   
    If the input string s is a valid time expression of the
    form hh:mm:ss.sss or hh:mm:ss or hh:mm, return
    a corresponding DateTimeDelta object. Otherwise, return None.
    s   hours   minutes   secondf0.0i    N(   s   ss   Nones   dts   _timeREs   searchs   matchs   groups   hours   minutes   seconds   ints   hhs   mms   floats   sss   DateTimes   DateTimeDeltas
   RangeError(	   s   ss   mms   sss   hours   hhs   matchs   dts   minutes   second(    (    sF   /mit/seven/lib/python2.2/site-packages/mx/DateTime/Examples/numdate.pys   numericTimeˆ s$      c    s©   |  t j o t Sn t |  ƒ i ƒ  i d d ƒ } | i ƒ  } t | d | ƒ } | t j	 o t | ƒ d j o/ t | d ƒ } | t j	 o | | } n n | Sd  S(   Ns   Ts    i    i   (   s   ss   Nones   strs   strips   replaces   _ss   splits	   date_times   numericDates   formatss   ds   lens   numericTimes   t(   s   ss   formatss	   date_times   ds   _ss   t(    (    sF   /mit/seven/lib/python2.2/site-packages/mx/DateTime/Examples/numdate.pys   numericDateTime  s      c    s  t  } | oy yC t |  d ƒ } | |  d j o d |  d t | ƒ f } n Wn/ t j
 o# } d |  d t	 | ƒ f } n Xny yF t
 |  d | ƒ } | |  d j o d |  d t | ƒ f } n Wn/ t j
 o# } d |  d t	 | ƒ f } n X| Sd  S(   Ni    i   s   >>> '%s' --> %ss   >>> '%s' -- %s(   s   Nones   results   timeonlys   numericTimes   testcases   dtd0s   reprs	   Exceptions   es   strs   numericDateTimes   formatss   dt0(   s   testcases   formatss   timeonlys   dtd0s   es   results   dt0(    (    sF   /mit/seven/lib/python2.2/site-packages/mx/DateTime/Examples/numdate.pys   _test_it² s    "#"c 	   s€  d k  l } d t i d d d d ƒ f d t i d d d d ƒ f d	 t i d d d d ƒ f d
 t f d t i d d d ƒ f d t i d d d ƒ f d t i d d d d d d ƒ f d t i d d d d d d ƒ f d t i d d d ƒ f d t i d d d ƒ f d t i d d d ƒ f d t i d d d d d d ƒ f d t i d d d d d d ƒ f d t i d d d ƒ f d t i d d d ƒ f d t i d d d d d d ƒ f d t i d d d d d d ƒ f d t i d d d ƒ f d t i d d d ƒ f d t i d d d d d d ƒ f d t i d d d ƒ f d  t i d d d ƒ f d! t i d d d d d d ƒ f g } d" d# i |  i ƒ  ƒ GH| ƒ  } d } x¹ t d$ ƒ D]« } xQ | d d !D]B } t | |  d% d& ƒ} | d& } | o
 | d j o	 | GHn qÅWxN | d D]B } t | |  d% d ƒ} | d& } | o
 | d j o	 | GHn qWq±W| ƒ  } d' | | | f GHd  S((   N(   s   clocks   12:13:14.56i    i   i   f14.56s   12:13:14i   s   12:13s   Ceci n'est pas une dates   010803iÑ  i   i   s   20010803s   20010803 12:13:14.56s   20010803T12:13:14.56s   01-08-03s
   2001-08-03s   2001-8-3s   2001-08-03 12:13:14.56s   2001-08-03T12:13:14.56s
   08/03/2001s   8/3/2001s   08/03/2001 12:13:14.56s   08/03/2001T12:13:14.56s
   08/23/2001i   s	   8/23/2001s   08/23/2001 12:13:14.56s
   23.08.2001s	   23.8.2001s   23.08.2001 12:13:14.56s%   
Testing numdate.py with format(s) %ss   , id   s   timeonlyi   s$   Done - %d cases tested in %1.5f sec.(   s   times   clocks   DateTimes   DateTimeDeltas   Nones	   testcasess   joins   formatss   splits   t0s   casess   ranges   is   testcases   _test_its   results   t1(	   s   formatss   clocks   is   t0s   testcases	   testcasess   results   casess   t1(    (    sF   /mit/seven/lib/python2.2/site-packages/mx/DateTime/Examples/numdate.pys   testÄ s.    ÿ ÿ r	  
 
	s   __main__(    s   __doc__s   mxs   DateTimes   res   _years   _months   _days   _ymds   _dmys   _mdys   compiles   Is   _ymdREs   _dmyREs   _mdyREs   _formatdicts   _hours   _minutes   _seconds   _times   _timeREs   divmods   nows   years   _THIS_CENTURYs   _iso_add_centurys   numericDates   numericTimes   numericDateTimes   _test_its   tests   __name__(   s   _test_its   numericDateTimes   _formatdicts   _months   numericTimes   _iso_add_centurys   _THIS_CENTURYs   _years   _hours   _ymds   DateTimes   _seconds   _mdys   _days   _times   _timeREs   _minutes   numericDates   _dmys   res   _mdyREs   _ymdREs   tests   _dmyRE(    (    sF   /mit/seven/lib/python2.2/site-packages/mx/DateTime/Examples/numdate.pys   ?! s4   	! 	=	2