Changeset 1502

Show
Ignore:
Timestamp:
09/27/08 08:47:18 (2 months ago)
Author:
mattknox_ca
Message:

added support for parsing year information by itself

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/timeseries/scikits/timeseries/parser.py

    r767 r1502  
    104104_isotime = _hour + ':?' + _minute + ':?' + _second + '? *' + _zone + '?' 
    105105 
     106_yeardate = _year 
    106107_weekdate = _year + '-?(?:' + _week + '-?' + _day + '?)?' 
    107108_eurodate = _day + '\.' + _month + '\.' + _year_epoch + '?' 
     
    160161_altisodateRE = re.compile(_altisodate, re.I) 
    161162_usisodateRE = re.compile(_usisodate, re.I) 
     163_yeardateRE = re.compile(_yeardate, re.I) 
    162164_eurodateRE = re.compile(_eurodate, re.I) 
    163165_usdateRE = re.compile(_usdate, re.I) 
     
    180182                 'iso', 'altiso', 
    181183                 'lit', 'altlit', 'eurlit', 
    182                  'unknown') 
     184                 'year', 'unknown') 
    183185 
    184186# Available time parsers 
     
    389391                    match = None 
    390392                    continue 
     393                break 
     394 
     395        elif format == 'year': 
     396            # just a year specified 
     397            match = _yeardateRE.match(text) 
     398            if match is not None: 
     399                year = match.groups()[0] 
     400                if year: 
     401                    if len(year) == 2: 
     402                        # Y2K problem: 
     403                        year = add_century(int(year)) 
     404                    else: 
     405                        year = int(year) 
     406                else: 
     407                    defaultdate = now() 
     408                    year = defaultdate.year 
     409                day = 1 
     410                month = 1 
    391411                break 
    392412 
  • trunk/timeseries/scikits/timeseries/tests/test_dates.py

    r1457 r1502  
    5959        assert_equal(dates, 24073 + np.arange(12)) 
    6060        print "finished test_fromstrings" 
     61 
     62        # quarterly date 
     63        assert_equal( 
     64            Date(freq='Q', string='2007-01'), 
     65            Date(freq='Q', year=2007, quarter=1)) 
     66 
     67        # just a year 
     68        assert_equal(Date(freq='A', string='2007'), Date(freq='A', year=2007)) 
    6169 
    6270