def testProperties(self): """Tests the properties.""" fat_timestamp_object = fat_date_time.FATTimestamp( timestamp=131033589024) self.assertEqual(fat_timestamp_object.timestamp, 131033589024) fat_timestamp_object = fat_date_time.FATTimestamp() self.assertIsNone(fat_timestamp_object.timestamp)
def testGetTimeOfDay(self): """Tests the GetTimeOfDay function.""" fat_timestamp_object = fat_date_time.FATTimestamp( timestamp=131033589024) time_of_day_tuple = fat_timestamp_object.GetTimeOfDay() self.assertEqual(time_of_day_tuple, (22, 11, 30)) fat_timestamp_object = fat_date_time.FATTimestamp() time_of_day_tuple = fat_timestamp_object.GetTimeOfDay() self.assertEqual(time_of_day_tuple, (None, None, None))
def testGetDate(self): """Tests the GetDate function.""" fat_timestamp_object = fat_date_time.FATTimestamp( timestamp=131033589024) date_tuple = fat_timestamp_object.GetDate() self.assertEqual(date_tuple, (2021, 7, 9)) fat_timestamp_object = fat_date_time.FATTimestamp() date_tuple = fat_timestamp_object.GetDate() self.assertEqual(date_tuple, (None, None, None))
def testCopyToStatTimeTuple(self): """Tests the CopyToStatTimeTuple function.""" fat_timestamp_object = fat_date_time.FATTimestamp( timestamp=131033589024) stat_time_tuple = fat_timestamp_object.CopyToStatTimeTuple() self.assertEqual(stat_time_tuple, (1625868690, None)) fat_timestamp_object = fat_date_time.FATTimestamp() stat_time_tuple = fat_timestamp_object.CopyToStatTimeTuple() self.assertEqual(stat_time_tuple, (None, None))
def testCopyToDateTimeString(self): """Tests the CopyToDateTimeString function.""" fat_timestamp_object = fat_date_time.FATTimestamp( timestamp=131033589024) date_time_string = fat_timestamp_object.CopyToDateTimeString() self.assertEqual(date_time_string, '2021-07-09 22:11:30.24') fat_timestamp_object = fat_date_time.FATTimestamp() date_time_string = fat_timestamp_object.CopyToDateTimeString() self.assertIsNone(date_time_string)
def testCopyToFATTimestampstampWithFractionOfSecond(self): """Tests the CopyToPosixTimestampWithFractionOfSecond function.""" fat_timestamp_object = fat_date_time.FATTimestamp( timestamp=131033589024) fat_timestamp, fraction_of_second = ( fat_timestamp_object.CopyToPosixTimestampWithFractionOfSecond()) self.assertEqual(fat_timestamp, 1625868690) self.assertIsNone(fraction_of_second) fat_timestamp_object = fat_date_time.FATTimestamp() fat_timestamp, fraction_of_second = ( fat_timestamp_object.CopyToPosixTimestampWithFractionOfSecond()) self.assertIsNone(fat_timestamp) self.assertIsNone(fraction_of_second)
def testCopyToDateTimeStringISO8601(self): """Tests the CopyToDateTimeStringISO8601 function.""" fat_timestamp_object = fat_date_time.FATTimestamp( timestamp=131033589024) date_time_string = fat_timestamp_object.CopyToDateTimeStringISO8601() self.assertEqual(date_time_string, '2021-07-09T22:11:30.24+00:00')
def testCopyFromDateTimeString(self): """Tests the CopyFromDateTimeString function.""" fat_timestamp_object = fat_date_time.FATTimestamp() fat_timestamp_object.CopyFromDateTimeString('2021-07-09') self.assertEqual(fat_timestamp_object._timestamp, 131025600000) self.assertEqual(fat_timestamp_object._time_zone_offset, 0) fat_timestamp_object.CopyFromDateTimeString('2021-07-09 22:11:30') self.assertEqual(fat_timestamp_object._timestamp, 131033589000) self.assertEqual(fat_timestamp_object._time_zone_offset, 0) fat_timestamp_object.CopyFromDateTimeString( '2021-07-09 22:11:30.246875') self.assertEqual(fat_timestamp_object._timestamp, 131033589024) self.assertEqual(fat_timestamp_object._time_zone_offset, 0) fat_timestamp_object.CopyFromDateTimeString( '2021-07-09 22:11:30.246875-01:00') self.assertEqual(fat_timestamp_object._timestamp, 131033589024) self.assertEqual(fat_timestamp_object._time_zone_offset, -60) fat_timestamp_object.CopyFromDateTimeString( '2021-07-09 22:11:30.246875+01:00') self.assertEqual(fat_timestamp_object._timestamp, 131033589024) self.assertEqual(fat_timestamp_object._time_zone_offset, 60) fat_timestamp_object.CopyFromDateTimeString('1980-01-02 00:00:00') self.assertEqual(fat_timestamp_object._timestamp, 8640000) self.assertEqual(fat_timestamp_object._time_zone_offset, 0) with self.assertRaises(ValueError): fat_timestamp_object.CopyFromDateTimeString('2200-01-02 00:00:00')
def testGetNormalizedTimestamp(self): """Tests the _GetNormalizedTimestamp function.""" fat_timestamp_object = fat_date_time.FATTimestamp( timestamp=131033589024) normalized_timestamp = fat_timestamp_object._GetNormalizedTimestamp() self.assertEqual(normalized_timestamp, decimal.Decimal('1625868690.24')) fat_timestamp_object = fat_date_time.FATTimestamp( time_zone_offset=60, timestamp=131033589024) normalized_timestamp = fat_timestamp_object._GetNormalizedTimestamp() self.assertEqual(normalized_timestamp, decimal.Decimal('1625865090.24')) fat_timestamp_object = fat_date_time.FATTimestamp() normalized_timestamp = fat_timestamp_object._GetNormalizedTimestamp() self.assertIsNone(normalized_timestamp)