예제 #1
0
 def parse(cls, value, kwds):
     if not value:
         kwds['defects'].append(errors.HeaderMissingRequiredValue())
         kwds['datetime'] = None
         kwds['decoded'] = ''
         return
     if isinstance(value, str):
         *dtuple, tz = utils.parsedate_tz(value)
         value = datetime.datetime(*dtuple[:6],
             tzinfo=datetime.timezone(datetime.timedelta(seconds=tz)))
     kwds['datetime'] = value
     kwds['decoded'] = utils.format_datetime(kwds['datetime'])
예제 #2
0
 def test_usegmt_with_non_utc_datetime_raises(self):
     with self.assertRaises(ValueError):
         utils.format_datetime(self.aware_dt, usegmt=True)
예제 #3
0
 def test_usegmt(self):
     utc_dt = datetime.datetime(*self.dateargs,
                                tzinfo=datetime.timezone.utc)
     self.assertEqual(utils.format_datetime(utc_dt, usegmt=True),
                      self.datestring + ' GMT')
예제 #4
0
 def test_aware_datetime(self):
     self.assertEqual(utils.format_datetime(self.aware_dt),
                      self.datestring + self.offsetstring)
예제 #5
0
 def test_naive_datetime(self):
     self.assertEqual(utils.format_datetime(self.naive_dt),
                      self.datestring + ' -0000')
예제 #6
0
 def test_usegmt_with_non_utc_datetime_raises(self):
     with self.assertRaises(ValueError):
         utils.format_datetime(self.aware_dt, usegmt=True)
예제 #7
0
 def test_usegmt(self):
     utc_dt = datetime.datetime(*self.dateargs,
                                tzinfo=datetime.timezone.utc)
     self.assertEqual(utils.format_datetime(utc_dt, usegmt=True),
                      self.datestring + ' GMT')
예제 #8
0
 def test_aware_datetime(self):
     self.assertEqual(utils.format_datetime(self.aware_dt),
                      self.datestring + self.offsetstring)
예제 #9
0
 def test_naive_datetime(self):
     self.assertEqual(utils.format_datetime(self.naive_dt),
                      self.datestring + ' -0000')