def testGetNormalizedTimestamp(self): """Tests the _GetNormalizedTimestamp function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertEqual(normalized_timestamp, decimal.Decimal('1375370728.0')) hfs_time_object = hfs_time.HFSTime(time_zone_offset=60, timestamp=3458215528) normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertEqual(normalized_timestamp, decimal.Decimal('1375367128.0')) hfs_time_object = hfs_time.HFSTime(timestamp=0x1ffffffff) normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertIsNone(normalized_timestamp) hfs_time_object = hfs_time.HFSTime(timestamp=-0x1ffffffff) normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertIsNone(normalized_timestamp) hfs_time_object = hfs_time.HFSTime() normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertIsNone(normalized_timestamp)
def testCopyToStatTimeTuple(self): """Tests the CopyToStatTimeTuple function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) expected_stat_time_tuple = (1375370728, 0) stat_time_tuple = hfs_time_object.CopyToStatTimeTuple() self.assertEqual(stat_time_tuple, expected_stat_time_tuple) hfs_time_object = hfs_time.HFSTime(timestamp=0x1ffffffff) expected_stat_time_tuple = (None, None) stat_time_tuple = hfs_time_object.CopyToStatTimeTuple() self.assertEqual(stat_time_tuple, expected_stat_time_tuple) hfs_time_object = hfs_time.HFSTime(timestamp=-0x1ffffffff) expected_stat_time_tuple = (None, None) stat_time_tuple = hfs_time_object.CopyToStatTimeTuple() self.assertEqual(stat_time_tuple, expected_stat_time_tuple) hfs_time_object = hfs_time.HFSTime() expected_stat_time_tuple = (None, None) stat_time_tuple = hfs_time_object.CopyToStatTimeTuple() self.assertEqual(stat_time_tuple, expected_stat_time_tuple)
def testProperties(self): """Tests the properties.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) self.assertEqual(hfs_time_object.timestamp, 3458215528) hfs_time_object = hfs_time.HFSTime() self.assertIsNone(hfs_time_object.timestamp)
def testCopyToDateTimeString(self): """Tests the CopyToDateTimeString function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) date_time_string = hfs_time_object.CopyToDateTimeString() self.assertEqual(date_time_string, '2013-08-01 15:25:28') hfs_time_object = hfs_time.HFSTime() date_time_string = hfs_time_object.CopyToDateTimeString() self.assertIsNone(date_time_string)
def testGetTimeOfDay(self): """Tests the GetTimeOfDay function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) time_of_day_tuple = hfs_time_object.GetTimeOfDay() self.assertEqual(time_of_day_tuple, (15, 25, 28)) hfs_time_object = hfs_time.HFSTime() time_of_day_tuple = hfs_time_object.GetTimeOfDay() self.assertEqual(time_of_day_tuple, (None, None, None))
def testGetDate(self): """Tests the GetDate function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) date_tuple = hfs_time_object.GetDate() self.assertEqual(date_tuple, (2013, 8, 1)) hfs_time_object = hfs_time.HFSTime() date_tuple = hfs_time_object.GetDate() self.assertEqual(date_tuple, (None, None, None))
def testGetDateWithTimeOfDay(self): """Tests the GetDateWithTimeOfDay function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) date_with_time_of_day_tuple = hfs_time_object.GetDateWithTimeOfDay() self.assertEqual(date_with_time_of_day_tuple, (2013, 8, 1, 15, 25, 28)) hfs_time_object = hfs_time.HFSTime() date_with_time_of_day_tuple = hfs_time_object.GetDateWithTimeOfDay() self.assertEqual(date_with_time_of_day_tuple, (None, None, None, None, None, None))
def testCopyFromDateTimeString(self): """Tests the CopyFromDateTimeString function.""" hfs_time_object = hfs_time.HFSTime() hfs_time_object.CopyFromDateTimeString('2013-08-01') self.assertEqual(hfs_time_object._timestamp, 3458160000) self.assertEqual(hfs_time_object._time_zone_offset, 0) hfs_time_object.CopyFromDateTimeString('2013-08-01 15:25:28') self.assertEqual(hfs_time_object._timestamp, 3458215528) self.assertEqual(hfs_time_object._time_zone_offset, 0) hfs_time_object.CopyFromDateTimeString('2013-08-01 15:25:28.546875') self.assertEqual(hfs_time_object._timestamp, 3458215528) self.assertEqual(hfs_time_object._time_zone_offset, 0) hfs_time_object.CopyFromDateTimeString( '2013-08-01 15:25:28.546875-01:00') self.assertEqual(hfs_time_object._timestamp, 3458215528) self.assertEqual(hfs_time_object._time_zone_offset, -60) hfs_time_object.CopyFromDateTimeString( '2013-08-01 15:25:28.546875+01:00') self.assertEqual(hfs_time_object._timestamp, 3458215528) self.assertEqual(hfs_time_object._time_zone_offset, 60) hfs_time_object.CopyFromDateTimeString('1904-01-02 00:00:00') self.assertEqual(hfs_time_object._timestamp, 86400) self.assertEqual(hfs_time_object._time_zone_offset, 0) with self.assertRaises(ValueError): hfs_time_object.CopyFromDateTimeString('1600-01-02 00:00:00')
def testCopyFromDateTimeString(self): """Tests the CopyFromDateTimeString function.""" hfs_time_object = hfs_time.HFSTime() expected_timestamp = 3458160000 hfs_time_object.CopyFromDateTimeString('2013-08-01') self.assertEqual(hfs_time_object.timestamp, expected_timestamp) expected_timestamp = 3458215528 hfs_time_object.CopyFromDateTimeString('2013-08-01 15:25:28') self.assertEqual(hfs_time_object.timestamp, expected_timestamp) expected_timestamp = 3458215528 hfs_time_object.CopyFromDateTimeString('2013-08-01 15:25:28.546875') self.assertEqual(hfs_time_object.timestamp, expected_timestamp) expected_timestamp = 3458219128 hfs_time_object.CopyFromDateTimeString('2013-08-01 15:25:28.546875-01:00') self.assertEqual(hfs_time_object.timestamp, expected_timestamp) expected_timestamp = 3458211928 hfs_time_object.CopyFromDateTimeString('2013-08-01 15:25:28.546875+01:00') self.assertEqual(hfs_time_object.timestamp, expected_timestamp) expected_timestamp = 86400 hfs_time_object.CopyFromDateTimeString('1904-01-02 00:00:00') self.assertEqual(hfs_time_object.timestamp, expected_timestamp) with self.assertRaises(ValueError): hfs_time_object.CopyFromDateTimeString('1600-01-02 00:00:00')
def testGetNormalizedTimestamp(self): """Tests the _GetNormalizedTimestamp function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertEqual(normalized_timestamp, 1375370728.0) hfs_time_object = hfs_time.HFSTime(timestamp=0x1ffffffff) normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertIsNone(normalized_timestamp) hfs_time_object = hfs_time.HFSTime(timestamp=-0x1ffffffff) normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertIsNone(normalized_timestamp) hfs_time_object = hfs_time.HFSTime() normalized_timestamp = hfs_time_object._GetNormalizedTimestamp() self.assertIsNone(normalized_timestamp)
def testGetPlasoTimestamp(self): """Tests the GetPlasoTimestamp function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) expected_micro_posix_timestamp = 1375370728000000 micro_posix_timestamp = hfs_time_object.GetPlasoTimestamp() self.assertEqual(micro_posix_timestamp, expected_micro_posix_timestamp) hfs_time_object = hfs_time.HFSTime(timestamp=0x1ffffffff) micro_posix_timestamp = hfs_time_object.GetPlasoTimestamp() self.assertIsNone(micro_posix_timestamp) hfs_time_object = hfs_time.HFSTime(timestamp=-0x1ffffffff) micro_posix_timestamp = hfs_time_object.GetPlasoTimestamp() self.assertIsNone(micro_posix_timestamp) hfs_time_object = hfs_time.HFSTime() micro_posix_timestamp = hfs_time_object.GetPlasoTimestamp() self.assertIsNone(micro_posix_timestamp)
def testCopyToDateTimeStringISO8601(self): """Tests the CopyToDateTimeStringISO8601 function.""" hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) date_time_string = hfs_time_object.CopyToDateTimeStringISO8601() self.assertEqual(date_time_string, '2013-08-01T15:25:28+00:00')