Beispiel #1
0
  def testProperties(self):
    """Tests the properties."""
    posix_time_object = posix_time.PosixTimeInMilliseconds(
        timestamp=1281643591546)
    self.assertEqual(posix_time_object.timestamp, 1281643591546)

    posix_time_object = posix_time.PosixTimeInMilliseconds()
    self.assertIsNone(posix_time_object.timestamp)
Beispiel #2
0
  def testGetTimeOfDay(self):
    """Tests the GetTimeOfDay function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds(
        timestamp=1281643591546)

    time_of_day_tuple = posix_time_object.GetTimeOfDay()
    self.assertEqual(time_of_day_tuple, (20, 6, 31))

    posix_time_object = posix_time.PosixTimeInMilliseconds()

    time_of_day_tuple = posix_time_object.GetTimeOfDay()
    self.assertEqual(time_of_day_tuple, (None, None, None))
Beispiel #3
0
  def testGetDate(self):
    """Tests the GetDate function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds(
        timestamp=1281643591546)

    date_tuple = posix_time_object.GetDate()
    self.assertEqual(date_tuple, (2010, 8, 12))

    posix_time_object = posix_time.PosixTimeInMilliseconds()

    date_tuple = posix_time_object.GetDate()
    self.assertEqual(date_tuple, (None, None, None))
Beispiel #4
0
  def testCopyToStatTimeTuple(self):
    """Tests the CopyToStatTimeTuple function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds(
        timestamp=1281643591546)

    stat_time_tuple = posix_time_object.CopyToStatTimeTuple()
    self.assertEqual(stat_time_tuple, (1281643591, 5460000))

    posix_time_object = posix_time.PosixTimeInMilliseconds()

    stat_time_tuple = posix_time_object.CopyToStatTimeTuple()
    self.assertEqual(stat_time_tuple, (None, None))
Beispiel #5
0
  def testCopyToDateTimeString(self):
    """Tests the CopyToDateTimeString function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds(
        timestamp=1281643591546)

    date_time_string = posix_time_object.CopyToDateTimeString()
    self.assertEqual(date_time_string, '2010-08-12 20:06:31.546')

    posix_time_object = posix_time.PosixTimeInMilliseconds()

    date_time_string = posix_time_object.CopyToDateTimeString()
    self.assertIsNone(date_time_string)
Beispiel #6
0
  def testGetNormalizedTimestamp(self):
    """Tests the _GetNormalizedTimestamp function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds(
        timestamp=1281643591546)

    normalized_timestamp = posix_time_object._GetNormalizedTimestamp()
    self.assertEqual(normalized_timestamp, decimal.Decimal('1281643591.546'))

    posix_time_object = posix_time.PosixTimeInMilliseconds()

    normalized_timestamp = posix_time_object._GetNormalizedTimestamp()
    self.assertIsNone(normalized_timestamp)
Beispiel #7
0
  def testCopyFromDateTimeString(self):
    """Tests the CopyFromDateTimeString function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds()

    expected_timestamp = 1281571200000
    posix_time_object.CopyFromDateTimeString('2010-08-12')
    self.assertEqual(posix_time_object.timestamp, expected_timestamp)

    expected_timestamp = 1281647191000
    posix_time_object.CopyFromDateTimeString('2010-08-12 21:06:31')
    self.assertEqual(posix_time_object.timestamp, expected_timestamp)

    expected_timestamp = 1281647191546
    posix_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546')
    self.assertEqual(posix_time_object.timestamp, expected_timestamp)

    expected_timestamp = 1281650791546
    posix_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546-01:00')
    self.assertEqual(posix_time_object.timestamp, expected_timestamp)

    expected_timestamp = 1281643591546
    posix_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546+01:00')
    self.assertEqual(posix_time_object.timestamp, expected_timestamp)

    expected_timestamp = -11644387200000
    posix_time_object.CopyFromDateTimeString('1601-01-02 00:00:00')
    self.assertEqual(posix_time_object.timestamp, expected_timestamp)
Beispiel #8
0
  def testCopyToDateTimeStringISO8601(self):
    """Tests the CopyToDateTimeStringISO8601 function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds(
        timestamp=1281643591546)

    date_time_string = posix_time_object.CopyToDateTimeStringISO8601()
    self.assertEqual(date_time_string, '2010-08-12T20:06:31.546+00:00')
Beispiel #9
0
  def testCopyFromDateTimeString(self):
    """Tests the CopyFromDateTimeString function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds()

    posix_time_object.CopyFromDateTimeString('2010-08-12')
    self.assertEqual(posix_time_object._timestamp, 1281571200000)
    self.assertEqual(posix_time_object._time_zone_offset, 0)

    posix_time_object.CopyFromDateTimeString('2010-08-12 21:06:31')
    self.assertEqual(posix_time_object._timestamp, 1281647191000)
    self.assertEqual(posix_time_object._time_zone_offset, 0)

    posix_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546')
    self.assertEqual(posix_time_object._timestamp, 1281647191546)
    self.assertEqual(posix_time_object._time_zone_offset, 0)

    posix_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546-01:00')
    self.assertEqual(posix_time_object._timestamp, 1281647191546)
    self.assertEqual(posix_time_object._time_zone_offset, -60)

    posix_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546+01:00')
    self.assertEqual(posix_time_object._timestamp, 1281647191546)
    self.assertEqual(posix_time_object._time_zone_offset, 60)

    posix_time_object.CopyFromDateTimeString('1601-01-02 00:00:00')
    self.assertEqual(posix_time_object._timestamp, -11644387200000)
    self.assertEqual(posix_time_object._time_zone_offset, 0)
Beispiel #10
0
  def testCopyToPosixTimestampWithFractionOfSecond(self):
    """Tests the CopyToPosixTimestampWithFractionOfSecond function."""
    posix_time_object = posix_time.PosixTimeInMilliseconds(
        timestamp=1281643591546)

    posix_timestamp, fraction_of_second = (
        posix_time_object.CopyToPosixTimestampWithFractionOfSecond())
    self.assertEqual(posix_timestamp, 1281643591)
    self.assertEqual(fraction_of_second, 546)

    posix_time_object = posix_time.PosixTime()

    posix_timestamp, fraction_of_second = (
        posix_time_object.CopyToPosixTimestampWithFractionOfSecond())
    self.assertIsNone(posix_timestamp)
    self.assertIsNone(fraction_of_second)