Message195035
I'm doing some string-based serialization of datetimes and need to be able to specify the type somewhat declaratively. So I'm using a datetime subclass. This is more or less the code I'm using:
class Timestamp(datetime.datetime):
def __new__(cls, raw_value, *args, **kwargs):
if not args and not kwargs:
return cls.fromtimestamp(int(raw_value))
else:
return super(Timestamp, cls).__new__(cls, raw_value,
*args, **kwargs)
def __str__(self):
return str(int(time.mktime(self.timetuple())))
Incidently, the whole equality testing thing didn't actually cause a problem. It was comparing against the result of `datetime.utcnow()` which has microseconds (and my Timestamp instance didn't). Clearing out the microseconds resolved the failure so I wasn't actually bitten by this issue after all. |
|
Date |
User |
Action |
Args |
2013-08-12 23:06:05 | eric.snow | set | recipients:
+ eric.snow, mark.dickinson, ncoghlan, belopolsky, jackdied, jess.austin, ysj.ray |
2013-08-12 23:06:05 | eric.snow | set | messageid: <1376348765.29.0.519131041598.issue5516@psf.upfronthosting.co.za> |
2013-08-12 23:06:05 | eric.snow | link | issue5516 messages |
2013-08-12 23:06:05 | eric.snow | create | |
|