def wintime_to_datetime(timestamp):
    """
    Given a funky Windows timestamp, convert it to a UTC datetime object.

    :param int timestamp: The timestamp, in win format.
    :rtype: datetime.datetime
    :returns: The correct UTC-aware timestamp.
    """

    return enlighten_dtime(datetime.datetime.utcfromtimestamp((timestamp-116444736000000000)/10000000))
def wintime_to_datetime(timestamp):
    """
    Given a funky Windows timestamp, convert it to a UTC datetime object.

    :param int timestamp: The timestamp, in win format.
    :rtype: datetime.datetime
    :returns: The correct UTC-aware timestamp.
    """

    return enlighten_dtime(
        datetime.datetime.utcfromtimestamp(
            (timestamp - 116444736000000000) / 10000000))
Пример #3
0
    def test_enlighten_dtime(self):
        """
        Makes sure our datetime 'enlightening' is behaving correctly.
        """

        est = pytz.timezone("EST")
        aware_dtime = datetime.datetime(
            year=1985, month=11, day=15,
            hour=6, minute=0,
            tzinfo=est)

        enlightened_dtime = enlighten_dtime(aware_dtime)
        # The tzinfo should be untouched.
        self.assertIs(aware_dtime.tzinfo, enlightened_dtime.tzinfo)

        # This is a naive object, but has UTC values for hour.
        utcnow = datetime.datetime.now()
        # No tzinfo was present, so that is replaced. hour should be the same.
        enlightened_utcnow = enlighten_dtime(utcnow)
        self.assertEqual(enlightened_utcnow.hour, utcnow.hour)
        self.assertIs(enlightened_utcnow.tzinfo, UTC_TZINFO)
Пример #4
0
    def test_enlighten_dtime(self):
        """
        Makes sure our datetime 'enlightening' is behaving correctly.
        """

        est = pytz.timezone("EST")
        aware_dtime = datetime.datetime(year=1985,
                                        month=11,
                                        day=15,
                                        hour=6,
                                        minute=0,
                                        tzinfo=est)

        enlightened_dtime = enlighten_dtime(aware_dtime)
        # The tzinfo should be untouched.
        self.assertIs(aware_dtime.tzinfo, enlightened_dtime.tzinfo)

        # This is a naive object, but has UTC values for hour.
        utcnow = datetime.datetime.now()
        # No tzinfo was present, so that is replaced. hour should be the same.
        enlightened_utcnow = enlighten_dtime(utcnow)
        self.assertEqual(enlightened_utcnow.hour, utcnow.hour)
        self.assertIs(enlightened_utcnow.tzinfo, UTC_TZINFO)