Ticket #3513: log.diff

File log.diff, 3.1 KB (added by wangchun, 5 years ago)
  • twisted/python/log.py

     
    384384 
    385385        tzOffset = -self.getTimezoneOffset(when) 
    386386        when = datetime.utcfromtimestamp(when + tzOffset) 
    387         tzHour = int(tzOffset / 60 / 60) 
    388         tzMin = int(tzOffset / 60 % 60) 
    389         return '%d-%02d-%02d %02d:%02d:%02d%+03d%02d' % ( 
     387        tzSign = tzOffset >= 0 and '+' or '-' 
     388        tzHour, tzMinute = divmod(abs(tzOffset) // 60, 60) 
     389        return '%04d-%02d-%02dT%02d:%02d:%02d.%06d%s%02d%02d' % ( 
    390390            when.year, when.month, when.day, 
    391             when.hour, when.minute, when.second, 
    392             tzHour, tzMin) 
     391            when.hour, when.minute, when.second, when.microsecond, 
     392            tzSign, tzHour, tzMinute) 
    393393 
    394394    def emit(self, eventDict): 
    395395        text = textFromEventDict(eventDict) 
  • twisted/test/test_log.py

     
    319319        """ 
    320320        # There is no function in the time module which converts a UTC time 
    321321        # tuple to a timestamp. 
    322         when = time.mktime((2001, 2, 3, 4, 5, 6, 7, 8, 0)) - time.timezone 
     322        when = time.mktime((2001, 2, 3, 4, 5, 6, 7, 8, 0)) - time.timezone + 0.123 
    323323 
    324324        # Pretend to be in US/Eastern for a moment 
    325325        self.flo.getTimezoneOffset = lambda when: 18000 
    326         self.assertEquals(self.flo.formatTime(when), '2001-02-02 23:05:06-0500') 
     326        self.assertEquals(self.flo.formatTime(when), '2001-02-02T23:05:06.123000-0500') 
    327327 
    328328        # Okay now we're in Eastern Europe somewhere 
    329329        self.flo.getTimezoneOffset = lambda when: -3600 
    330         self.assertEquals(self.flo.formatTime(when), '2001-02-03 05:05:06+0100') 
     330        self.assertEquals(self.flo.formatTime(when), '2001-02-03T05:05:06.123000+0100') 
    331331 
    332332        # And off in the Pacific or someplace like that 
    333333        self.flo.getTimezoneOffset = lambda when: -39600 
    334         self.assertEquals(self.flo.formatTime(when), '2001-02-03 15:05:06+1100') 
     334        self.assertEquals(self.flo.formatTime(when), '2001-02-03T15:05:06.123000+1100') 
    335335 
    336336        # One of those weird places with a half-hour offset timezone 
    337         self.flo.getTimezoneOffset = lambda when: 5400 
    338         self.assertEquals(self.flo.formatTime(when), '2001-02-03 02:35:06-0130') 
     337        self.flo.getTimezoneOffset = lambda when: 1800 
     338        self.assertEquals(self.flo.formatTime(when), '2001-02-03T03:35:06.123000-0030') 
    339339 
    340340        # Half-hour offset in the other direction 
    341         self.flo.getTimezoneOffset = lambda when: -5400 
    342         self.assertEquals(self.flo.formatTime(when), '2001-02-03 05:35:06+0130') 
     341        self.flo.getTimezoneOffset = lambda when: -1800 
     342        self.assertEquals(self.flo.formatTime(when), '2001-02-03T04:35:06.123000+0030') 
    343343 
    344344        # If a strftime-format string is present on the logger, it should 
    345345        # use that instead.  Note we don't assert anything about day, hour