Beispiel #1
0
    def test_from_stream(self):
        ae = self.assertEqual
        datetime_3_25 = datetime(1900, 1, 2, 6, 0, 0)

        data_le = b"\x00\x00\x00\x00\x00\x00\x0A\x40"
        data_be = b"\x40\x0A\x00\x00\x00\x00\x00\x00"

        stream = ByteIStream(data_le)
        value = \
            VariantTimeTodatetime.from_stream(stream, byte_order=LITTLE_ENDIAN)
        ae(value, datetime_3_25)

        value = VariantTimeTodatetime.from_stream(stream, 0, LITTLE_ENDIAN)
        ae(value, datetime_3_25)

        stream = ByteIStream(data_be)
        value = \
            VariantTimeTodatetime.from_stream(stream, byte_order=BIG_ENDIAN)
        ae(value, datetime_3_25)

        value = VariantTimeTodatetime.from_stream(stream, 0, BIG_ENDIAN)
        ae(value, datetime_3_25)
Beispiel #2
0
    def test_from_stream(self):
        ae = self.assertEqual
        datetime_3_25 = datetime(1900, 1, 2, 6, 0, 0)

        data_le = b"\x00\x00\x00\x00\x00\x00\x0A\x40"
        data_be = b"\x40\x0A\x00\x00\x00\x00\x00\x00"

        stream = ByteIStream(data_le)
        value = \
            VariantTimeTodatetime.from_stream(stream, byte_order=LITTLE_ENDIAN)
        ae(value, datetime_3_25)

        value = VariantTimeTodatetime.from_stream(stream, 0, LITTLE_ENDIAN)
        ae(value, datetime_3_25)


        stream = ByteIStream(data_be)
        value = \
            VariantTimeTodatetime.from_stream(stream, byte_order=BIG_ENDIAN)
        ae(value, datetime_3_25)

        value = VariantTimeTodatetime.from_stream(stream, 0, BIG_ENDIAN)
        ae(value, datetime_3_25)
Beispiel #3
0
def variant_time_to_datetime(vtime):
    """
    Converts a variant time (OLE date/time) to a Python datetime object.

    :parameters:
        vtime
            The time in OLE date format.

    :raises:
        ValueError
            If vtime is an invalid value.

    :rtype: datetime
    :returns: The time as a Python datetime object.
    """
    return VariantTimeTodatetime.from_float(vtime)
Beispiel #4
0
def variant_time_to_datetime(vtime):
    """
    Converts a variant time (OLE date/time) to a Python datetime object.

    :parameters:
        vtime
            The time in OLE date format.

    :raises:
        ValueError
            If vtime is an invalid value.

    :rtype: datetime
    :returns: The time as a Python datetime object.
    """
    return VariantTimeTodatetime.from_float(vtime)
Beispiel #5
0
def convert_timestamp(timestamp, timestamp_type):
    """Converts a timestamp from an integer into a datetime object."""

    if timestamp_type == "posix":
        new_timestamp = POSIXTimeTodatetime.from_int(timestamp)

    elif timestamp_type == "dosdate":
        new_timestamp = DOSDateTimeTodatetime.from_ints(timestamp, None).date()

    elif timestamp_type == "dostime":
        new_timestamp = DOSDateTimeTodatetime.from_ints(None, timestamp).time()

    elif timestamp_type == "filetime":
        new_timestamp = FILETIMETodatetime.from_int(timestamp)

    elif timestamp_type == "variant":
        new_timestamp = VariantTimeTodatetime.from_float(timestamp)

    else:
        raise ValueError("Unknown timestamp type: {0}".format(timestamp_type))
    # end if

    return new_timestamp
Beispiel #6
0
    def test_from_float(self):
        ae = self.assertEqual

        value = VariantTimeTodatetime.from_float(3.25)
        ae(value, datetime(1900, 1, 2, 6, 0, 0))
Beispiel #7
0
    def test_from_float(self):
        ae = self.assertEqual

        value = VariantTimeTodatetime.from_float(3.25)
        ae(value, datetime(1900, 1, 2, 6, 0, 0))