Ignore:
Timestamp:
08/16/06 14:22:38 (8 years ago)
Author:
xi
Message:

Fix timestamp constructing and representing (close #25).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/lib/yaml/representer.py

    r222 r225  
    66from nodes import * 
    77 
    8 try: 
    9     import datetime 
    10     datetime_available = True 
    11 except ImportError: 
    12     datetime_available = False 
     8import datetime 
    139 
    1410try: 
     
    242238 
    243239    def represent_date(self, data): 
    244         value = u'%04d-%02d-%02d' % (data.year, data.month, data.day) 
     240        value = unicode(data.isoformat()) 
    245241        return self.represent_scalar(u'tag:yaml.org,2002:timestamp', value) 
    246242 
    247243    def represent_datetime(self, data): 
    248         value = u'%04d-%02d-%02d %02d:%02d:%02d' \ 
    249                 % (data.year, data.month, data.day, 
    250                     data.hour, data.minute, data.second) 
    251         if data.microsecond: 
    252             value += u'.' + unicode(data.microsecond/1000000.0).split(u'.')[1] 
    253         if data.utcoffset(): 
    254             value += unicode(data.utcoffset()) 
     244        value = unicode(data.isoformat(' ')) 
    255245        return self.represent_scalar(u'tag:yaml.org,2002:timestamp', value) 
    256246 
     
    298288        SafeRepresenter.represent_set) 
    299289 
    300 if datetime_available: 
    301     SafeRepresenter.add_representer(datetime.date, 
    302             SafeRepresenter.represent_date) 
    303     SafeRepresenter.add_representer(datetime.datetime, 
    304             SafeRepresenter.represent_datetime) 
     290SafeRepresenter.add_representer(datetime.date, 
     291        SafeRepresenter.represent_date) 
     292SafeRepresenter.add_representer(datetime.datetime, 
     293        SafeRepresenter.represent_datetime) 
    305294 
    306295SafeRepresenter.add_representer(None, 
Note: See TracChangeset for help on using the changeset viewer.