This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients belopolsky, eric.snow, jackdied, jess.austin, mark.dickinson, ncoghlan, ysj.ray
Date 2013-08-12.23:06:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1376348765.29.0.519131041598.issue5516@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-08-12 23:06:05eric.snowsetrecipients: + eric.snow, mark.dickinson, ncoghlan, belopolsky, jackdied, jess.austin, ysj.ray
2013-08-12 23:06:05eric.snowsetmessageid: <1376348765.29.0.519131041598.issue5516@psf.upfronthosting.co.za>
2013-08-12 23:06:05eric.snowlinkissue5516 messages
2013-08-12 23:06:05eric.snowcreate