New upstream version 20180510
Hilko Bengen
5 years ago
0 | dfdatetime (20180509-1) unstable; urgency=low | |
0 | dfdatetime (20180510-1) unstable; urgency=low | |
1 | 1 | |
2 | 2 | * Auto-generated |
3 | 3 | |
4 | -- Log2Timeline <log2timeline-dev@googlegroups.com> Wed, 09 May 2018 07:07:06 +0200⏎ | |
4 | -- Log2Timeline <log2timeline-dev@googlegroups.com> Thu, 10 May 2018 10:18:44 +0200⏎ |
4 | 4 | objects to preserve accuracy and precision. |
5 | 5 | """ |
6 | 6 | |
7 | __version__ = '20180509' | |
7 | __version__ = '20180510' |
122 | 122 | |
123 | 123 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:06d}'.format( |
124 | 124 | year, month, day_of_month, hours, minutes, seconds, microseconds) |
125 | ||
126 | def GetDate(self): | |
127 | """Retrieves the date represented by the date and time values. | |
128 | ||
129 | Returns: | |
130 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
131 | if the date and time values do not represent a date. | |
132 | """ | |
133 | if self.timestamp is None: | |
134 | return None, None, None | |
135 | ||
136 | try: | |
137 | number_of_days, _, _, _ = self._GetTimeValues(int(self.timestamp)) | |
138 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
139 | ||
140 | except ValueError: | |
141 | return None, None, None |
132 | 132 | |
133 | 133 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:06d}'.format( |
134 | 134 | year, month, day_of_month, hours, minutes, seconds, microseconds) |
135 | ||
136 | def GetDate(self): | |
137 | """Retrieves the date represented by the date and time values. | |
138 | ||
139 | Returns: | |
140 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
141 | if the date and time values do not represent a date. | |
142 | """ | |
143 | if self.timestamp is None: | |
144 | return None, None, None | |
145 | ||
146 | try: | |
147 | number_of_seconds = self.timestamp * definitions.SECONDS_PER_DAY | |
148 | number_of_days, _, _, _ = self._GetTimeValues(int(number_of_seconds)) | |
149 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
150 | ||
151 | except ValueError: | |
152 | return None, None, None |
103 | 103 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:06d}'.format( |
104 | 104 | year, month, day_of_month, hours, minutes, seconds, |
105 | 105 | self._microseconds) |
106 | ||
107 | def GetDate(self): | |
108 | """Retrieves the date represented by the date and time values. | |
109 | ||
110 | Returns: | |
111 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
112 | if the date and time values do not represent a date. | |
113 | """ | |
114 | if self._number_of_seconds is None: | |
115 | return None, None, None | |
116 | ||
117 | try: | |
118 | number_of_days, _, _, _ = self._GetTimeValues(self._number_of_seconds) | |
119 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
120 | ||
121 | except ValueError: | |
122 | return None, None, None |
171 | 171 | |
172 | 172 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'.format( |
173 | 173 | year, month, day_of_month, hours, minutes, seconds) |
174 | ||
175 | def GetDate(self): | |
176 | """Retrieves the date represented by the date and time values. | |
177 | ||
178 | Returns: | |
179 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
180 | if the date and time values do not represent a date. | |
181 | """ | |
182 | if self._number_of_seconds is None: | |
183 | return None, None, None | |
184 | ||
185 | try: | |
186 | number_of_days, _, _, _ = self._GetTimeValues(self._number_of_seconds) | |
187 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
188 | ||
189 | except ValueError: | |
190 | return None, None, None |
124 | 124 | |
125 | 125 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:07d}'.format( |
126 | 126 | year, month, day_of_month, hours, minutes, seconds, remainder) |
127 | ||
128 | def GetDate(self): | |
129 | """Retrieves the date represented by the date and time values. | |
130 | ||
131 | Returns: | |
132 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
133 | if the date and time values do not represent a date. | |
134 | """ | |
135 | if (self.timestamp is None or self.timestamp < 0 or | |
136 | self.timestamp > self._UINT64_MAX): | |
137 | return None, None, None | |
138 | ||
139 | try: | |
140 | timestamp, _ = divmod(self.timestamp, self._100NS_PER_SECOND) | |
141 | number_of_days, _, _, _ = self._GetTimeValues(timestamp) | |
142 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
143 | ||
144 | except ValueError: | |
145 | return None, None, None |
116 | 116 | |
117 | 117 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'.format( |
118 | 118 | year, month, day_of_month, hours, minutes, seconds) |
119 | ||
120 | def GetDate(self): | |
121 | """Retrieves the date represented by the date and time values. | |
122 | ||
123 | Returns: | |
124 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
125 | if the date and time values do not represent a date. | |
126 | """ | |
127 | if (self.timestamp is None or self.timestamp < 0 or | |
128 | self.timestamp > self._UINT32_MAX): | |
129 | return None, None, None | |
130 | ||
131 | try: | |
132 | number_of_days, _, _, _ = self._GetTimeValues(self.timestamp) | |
133 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
134 | ||
135 | except ValueError: | |
136 | return None, None, None |
31 | 31 | self.year = year |
32 | 32 | |
33 | 33 | |
34 | class NormalizedTimeEpoch(DateTimeEpoch): | |
35 | """dfDateTime normalized time epoch.""" | |
36 | ||
37 | def __init__(self): | |
38 | """Initializes a dfDateTime normalized time epoch.""" | |
39 | super(NormalizedTimeEpoch, self).__init__(1970, 1, 1) | |
40 | ||
41 | ||
34 | 42 | class DateTimeValues(object): |
35 | 43 | """Date and time values interface. |
36 | 44 | |
41 | 49 | """ |
42 | 50 | |
43 | 51 | _DAYS_PER_MONTH = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) |
52 | ||
53 | _EPOCH_NORMALIZED_TIME = NormalizedTimeEpoch() | |
44 | 54 | |
45 | 55 | _100NS_PER_SECOND = 10000000 |
46 | 56 | _100NS_PER_DECISECOND = 1000000 |
508 | 518 | of bounds. |
509 | 519 | """ |
510 | 520 | if epoch_year < 0: |
511 | raise ValueError('Epoch year value out of bounds.') | |
521 | raise ValueError('Epoch year value: {0:d} out of bounds.'.format( | |
522 | epoch_year)) | |
512 | 523 | |
513 | 524 | if epoch_month not in range(1, 13): |
514 | raise ValueError('Epoch month value out of bounds.') | |
525 | raise ValueError('Epoch month value: {0:d} out of bounds.'.format( | |
526 | epoch_month)) | |
515 | 527 | |
516 | 528 | epoch_days_per_month = self._GetDaysPerMonth(epoch_year, epoch_month) |
517 | 529 | if epoch_day_of_month < 1 or epoch_day_of_month > epoch_days_per_month: |
518 | raise ValueError('Epoch day of month value out of bounds.') | |
530 | raise ValueError('Epoch day of month value: {0:d} out of bounds.'.format( | |
531 | epoch_day_of_month)) | |
519 | 532 | |
520 | 533 | before_epoch = number_of_days < 0 |
521 | 534 | |
769 | 782 | """Determines time values. |
770 | 783 | |
771 | 784 | Args: |
772 | number_of_seconds (int): number of seconds. | |
785 | number_of_seconds (int|decimal.Decimal): number of seconds. | |
773 | 786 | |
774 | 787 | Returns: |
775 | 788 | tuple[int, int, int, int]: days, hours, minutes, seconds. |
776 | 789 | """ |
790 | number_of_seconds = int(number_of_seconds) | |
777 | 791 | number_of_minutes, seconds = divmod(number_of_seconds, 60) |
778 | 792 | number_of_hours, minutes = divmod(number_of_minutes, 60) |
779 | 793 | number_of_days, hours = divmod(number_of_hours, 24) |
870 | 884 | str: date and time value formatted as: "YYYY-MM-DD hh:mm:ss.######" |
871 | 885 | """ |
872 | 886 | |
873 | @abc.abstractmethod | |
874 | 887 | def GetDate(self): |
875 | 888 | """Retrieves the date represented by the date and time values. |
876 | 889 | |
878 | 891 | tuple[int, int, int]: year, month, day of month or (None, None, None) |
879 | 892 | if the date and time values do not represent a date. |
880 | 893 | """ |
894 | normalized_timestamp = self._GetNormalizedTimestamp() | |
895 | if normalized_timestamp is None: | |
896 | return None, None, None | |
897 | ||
898 | number_of_days, _, _, _ = self._GetTimeValues(normalized_timestamp) | |
899 | ||
900 | try: | |
901 | return self._GetDateValuesWithEpoch( | |
902 | number_of_days, self._EPOCH_NORMALIZED_TIME) | |
903 | ||
904 | except ValueError: | |
905 | return None, None, None | |
881 | 906 | |
882 | 907 | # TODO: remove this method when there is no more need for it in plaso. |
883 | 908 | def GetPlasoTimestamp(self): |
893 | 918 | |
894 | 919 | normalized_timestamp *= definitions.MICROSECONDS_PER_SECOND |
895 | 920 | return int(round(normalized_timestamp)) |
921 | ||
922 | def GetTimeOfDay(self): | |
923 | """Retrieves the time of day represented by the date and time values. | |
924 | ||
925 | Returns: | |
926 | tuple[int, int, int]: hours, minutes, seconds or (None, None, None) | |
927 | if the date and time values do not represent a time of day. | |
928 | """ | |
929 | normalized_timestamp = self._GetNormalizedTimestamp() | |
930 | if normalized_timestamp is None: | |
931 | return None, None, None | |
932 | ||
933 | _, hours, minutes, seconds = self._GetTimeValues(normalized_timestamp) | |
934 | return hours, minutes, seconds |
113 | 113 | |
114 | 114 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:03d}'.format( |
115 | 115 | year, month, day_of_month, hours, minutes, seconds, milliseconds) |
116 | ||
117 | def GetDate(self): | |
118 | """Retrieves the date represented by the date and time values. | |
119 | ||
120 | Returns: | |
121 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
122 | if the date and time values do not represent a date. | |
123 | """ | |
124 | if (self.timestamp is None or self.timestamp < self._INT64_MIN or | |
125 | self.timestamp > self._INT64_MAX): | |
126 | return None, None, None | |
127 | ||
128 | try: | |
129 | timestamp, _ = divmod(self.timestamp, definitions.MILLISECONDS_PER_SECOND) | |
130 | number_of_days, _, _, _ = self._GetTimeValues(timestamp) | |
131 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
132 | ||
133 | except ValueError: | |
134 | return None, None, None |
129 | 129 | |
130 | 130 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:06d}'.format( |
131 | 131 | year, month, day_of_month, hours, minutes, seconds, microseconds) |
132 | ||
133 | def GetDate(self): | |
134 | """Retrieves the date represented by the date and time values. | |
135 | ||
136 | Returns: | |
137 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
138 | if the date and time values do not represent a date. | |
139 | """ | |
140 | if self.timestamp is None: | |
141 | return None, None, None | |
142 | ||
143 | try: | |
144 | timestamp = self.timestamp * definitions.SECONDS_PER_DAY | |
145 | number_of_days, _, _, _ = self._GetTimeValues(int(timestamp)) | |
146 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
147 | ||
148 | except ValueError: | |
149 | return None, None, None |
106 | 106 | |
107 | 107 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'.format( |
108 | 108 | year, month, day_of_month, hours, minutes, seconds) |
109 | ||
110 | def GetDate(self): | |
111 | """Retrieves the date represented by the date and time values. | |
112 | ||
113 | Returns: | |
114 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
115 | if the date and time values do not represent a date. | |
116 | """ | |
117 | if self.timestamp is None: | |
118 | return None, None, None | |
119 | ||
120 | try: | |
121 | number_of_days, _, _, _ = self._GetTimeValues(self.timestamp) | |
122 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
123 | ||
124 | except ValueError: | |
125 | return None, None, None | |
126 | 109 | |
127 | 110 | |
128 | 111 | class PosixTimeInMicroseconds(interface.DateTimeValues): |
217 | 200 | |
218 | 201 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:06d}'.format( |
219 | 202 | year, month, day_of_month, hours, minutes, seconds, microseconds) |
220 | ||
221 | def GetDate(self): | |
222 | """Retrieves the date represented by the date and time values. | |
223 | ||
224 | Returns: | |
225 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
226 | if the date and time values do not represent a date. | |
227 | """ | |
228 | if self.timestamp is None: | |
229 | return None, None, None | |
230 | ||
231 | try: | |
232 | timestamp, _ = divmod(self.timestamp, definitions.MICROSECONDS_PER_SECOND) | |
233 | number_of_days, _, _, _ = self._GetTimeValues(timestamp) | |
234 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
235 | ||
236 | except ValueError: | |
237 | return None, None, None |
201 | 201 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:01d}'.format( |
202 | 202 | self.year, self.month, self.day_of_month, self.hours, self.minutes, |
203 | 203 | self.seconds, self.deciseconds) |
204 | ||
205 | def GetDate(self): | |
206 | """Retrieves the date represented by the date and time values. | |
207 | ||
208 | Returns: | |
209 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
210 | if the date and time values do not represent a date. | |
211 | """ | |
212 | if self._number_of_seconds is None: | |
213 | return None, None, None | |
214 | ||
215 | return self.year, self.month, self.day_of_month |
180 | 180 | """ |
181 | 181 | return None, None |
182 | 182 | |
183 | def GetDate(self): | |
184 | """Retrieves the date represented by the date and time values. | |
185 | ||
186 | Returns: | |
187 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
188 | if the date and time values do not represent a date. | |
189 | """ | |
190 | return None, None, None | |
191 | ||
192 | 183 | def GetPlasoTimestamp(self): |
193 | 184 | """Retrieves a timestamp that is compatible with plaso. |
194 | 185 |
183 | 183 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:03d}'.format( |
184 | 184 | self.year, self.month, self.day_of_month, self.hours, self.minutes, |
185 | 185 | self.seconds, self.milliseconds) |
186 | ||
187 | def GetDate(self): | |
188 | """Retrieves the date represented by the date and time values. | |
189 | ||
190 | Returns: | |
191 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
192 | if the date and time values do not represent a date. | |
193 | """ | |
194 | if self._number_of_seconds is None: | |
195 | return None, None, None | |
196 | ||
197 | return self.year, self.month, self.day_of_month |
409 | 409 | self._time_elements_tuple[2], self._time_elements_tuple[3], |
410 | 410 | self._time_elements_tuple[4], self._time_elements_tuple[5]) |
411 | 411 | |
412 | def GetDate(self): | |
413 | """Retrieves the date represented by the date and time values. | |
414 | ||
415 | Returns: | |
416 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
417 | if the date and time values do not represent a date. | |
418 | """ | |
419 | if self._number_of_seconds is None: | |
420 | return None, None, None | |
421 | ||
422 | return ( | |
423 | self._time_elements_tuple[0], self._time_elements_tuple[1], | |
424 | self._time_elements_tuple[2]) | |
425 | ||
426 | 412 | |
427 | 413 | class TimeElementsWithFractionOfSecond(TimeElements): |
428 | 414 | """Time elements with a fraction of second interface. |
129 | 129 | |
130 | 130 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:07d}'.format( |
131 | 131 | year, month, day_of_month, hours, minutes, seconds, remainder) |
132 | ||
133 | def GetDate(self): | |
134 | """Retrieves the date represented by the date and time values. | |
135 | ||
136 | Returns: | |
137 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
138 | if the date and time values do not represent a date. | |
139 | """ | |
140 | if (self.timestamp is None or self.timestamp < 0 or | |
141 | self.timestamp > self._UINT60_MAX): | |
142 | return None, None, None | |
143 | ||
144 | try: | |
145 | timestamp, _ = divmod(self.timestamp, self._100NS_PER_SECOND) | |
146 | number_of_days, _, _, _ = self._GetTimeValues(timestamp) | |
147 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
148 | ||
149 | except ValueError: | |
150 | return None, None, None |
118 | 118 | |
119 | 119 | return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}.{6:06d}'.format( |
120 | 120 | year, month, day_of_month, hours, minutes, seconds, microseconds) |
121 | ||
122 | def GetDate(self): | |
123 | """Retrieves the date represented by the date and time values. | |
124 | ||
125 | Returns: | |
126 | tuple[int, int, int]: year, month, day of month or (None, None, None) | |
127 | if the date and time values do not represent a date. | |
128 | """ | |
129 | if (self.timestamp is None or self.timestamp < self._INT64_MIN or | |
130 | self.timestamp > self._INT64_MAX): | |
131 | return None, None, None | |
132 | ||
133 | try: | |
134 | timestamp, _ = divmod(self.timestamp, definitions.MICROSECONDS_PER_SECOND) | |
135 | number_of_days, _, _, _ = self._GetTimeValues(timestamp) | |
136 | return self._GetDateValuesWithEpoch(number_of_days, self._EPOCH) | |
137 | ||
138 | except ValueError: | |
139 | return None, None, None |
49 | 49 | |
50 | 50 | expected_timestamp = 394934400.0 |
51 | 51 | cocoa_time_object.CopyFromDateTimeString('2013-07-08') |
52 | self.assertEqual(cocoa_time_object.timestamp, expected_timestamp) | |
52 | self.assertEqual(cocoa_time_object._timestamp, expected_timestamp) | |
53 | 53 | |
54 | 54 | expected_timestamp = 395011845.0 |
55 | 55 | cocoa_time_object.CopyFromDateTimeString('2013-07-08 21:30:45') |
56 | self.assertEqual(cocoa_time_object.timestamp, expected_timestamp) | |
56 | self.assertEqual(cocoa_time_object._timestamp, expected_timestamp) | |
57 | 57 | |
58 | 58 | expected_timestamp = 395011845.546875 |
59 | 59 | cocoa_time_object.CopyFromDateTimeString('2013-07-08 21:30:45.546875') |
60 | self.assertEqual(cocoa_time_object.timestamp, expected_timestamp) | |
60 | self.assertEqual(cocoa_time_object._timestamp, expected_timestamp) | |
61 | 61 | |
62 | 62 | expected_timestamp = 395015445.546875 |
63 | 63 | cocoa_time_object.CopyFromDateTimeString('2013-07-08 21:30:45.546875-01:00') |
64 | self.assertEqual(cocoa_time_object.timestamp, expected_timestamp) | |
64 | self.assertEqual(cocoa_time_object._timestamp, expected_timestamp) | |
65 | 65 | |
66 | 66 | expected_timestamp = 395008245.546875 |
67 | 67 | cocoa_time_object.CopyFromDateTimeString('2013-07-08 21:30:45.546875+01:00') |
68 | self.assertEqual(cocoa_time_object.timestamp, expected_timestamp) | |
68 | self.assertEqual(cocoa_time_object._timestamp, expected_timestamp) | |
69 | 69 | |
70 | 70 | expected_timestamp = 86400.0 |
71 | 71 | cocoa_time_object.CopyFromDateTimeString('2001-01-02 00:00:00') |
72 | self.assertEqual(cocoa_time_object.timestamp, expected_timestamp) | |
72 | self.assertEqual(cocoa_time_object._timestamp, expected_timestamp) | |
73 | 73 | |
74 | 74 | def testCopyToDateTimeString(self): |
75 | 75 | """Tests the CopyToDateTimeString function.""" |
77 | 77 | |
78 | 78 | date_time_string = cocoa_time_object.CopyToDateTimeString() |
79 | 79 | self.assertEqual(date_time_string, '2013-07-08 21:30:45.546875') |
80 | ||
81 | epoch_year = cocoa_time_object._EPOCH.year | |
82 | cocoa_time_object._EPOCH.year = -1 | |
83 | ||
84 | with self.assertRaises(ValueError): | |
85 | cocoa_time_object.CopyToDateTimeString() | |
86 | ||
87 | cocoa_time_object._EPOCH.year = epoch_year | |
80 | 88 | |
81 | 89 | cocoa_time_object = cocoa_time.CocoaTime() |
82 | 90 | |
89 | 97 | |
90 | 98 | date_tuple = cocoa_time_object.GetDate() |
91 | 99 | self.assertEqual(date_tuple, (2013, 7, 8)) |
92 | ||
93 | cocoa_time_object._EPOCH.year = -1 | |
94 | ||
95 | date_tuple = cocoa_time_object.GetDate() | |
96 | self.assertEqual(date_tuple, (None, None, None)) | |
97 | 100 | |
98 | 101 | cocoa_time_object = cocoa_time.CocoaTime() |
99 | 102 | |
113 | 116 | micro_posix_timestamp = cocoa_time_object.GetPlasoTimestamp() |
114 | 117 | self.assertIsNone(micro_posix_timestamp) |
115 | 118 | |
119 | def testGetTimeOfDay(self): | |
120 | """Tests the GetTimeOfDay function.""" | |
121 | cocoa_time_object = cocoa_time.CocoaTime(timestamp=395011845.546875) | |
122 | ||
123 | time_of_day_tuple = cocoa_time_object.GetTimeOfDay() | |
124 | self.assertEqual(time_of_day_tuple, (21, 30, 45)) | |
125 | ||
126 | cocoa_time_object = cocoa_time.CocoaTime() | |
127 | ||
128 | time_of_day_tuple = cocoa_time_object.GetTimeOfDay() | |
129 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
130 | ||
116 | 131 | |
117 | 132 | if __name__ == '__main__': |
118 | 133 | unittest.main() |
134 | 134 | date_tuple = delphi_date_time_object.GetDate() |
135 | 135 | self.assertEqual(date_tuple, (2013, 6, 18)) |
136 | 136 | |
137 | delphi_date_time_object._EPOCH.year = -1 | |
138 | ||
139 | date_tuple = delphi_date_time_object.GetDate() | |
140 | self.assertEqual(date_tuple, (None, None, None)) | |
141 | ||
142 | 137 | delphi_date_time_object = delphi_date_time.DelphiDateTime() |
143 | 138 | |
144 | 139 | date_tuple = delphi_date_time_object.GetDate() |
145 | 140 | self.assertEqual(date_tuple, (None, None, None)) |
146 | 141 | |
142 | def testGetTimeOfDay(self): | |
143 | """Tests the GetTimeOfDay function.""" | |
144 | delphi_date_time_object = delphi_date_time.DelphiDateTime( | |
145 | timestamp=41443.8263953) | |
146 | ||
147 | time_of_day_tuple = delphi_date_time_object.GetTimeOfDay() | |
148 | self.assertEqual(time_of_day_tuple, (19, 50, 0)) | |
149 | ||
150 | delphi_date_time_object = delphi_date_time.DelphiDateTime() | |
151 | ||
152 | time_of_day_tuple = delphi_date_time_object.GetTimeOfDay() | |
153 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
154 | ||
147 | 155 | |
148 | 156 | if __name__ == '__main__': |
149 | 157 | unittest.main() |
89 | 89 | date_tuple = fake_time_object.GetDate() |
90 | 90 | self.assertEqual(date_tuple, (2010, 8, 12)) |
91 | 91 | |
92 | fake_time_object._EPOCH.year = -1 | |
92 | fake_time_object = fake_time.FakeTime() | |
93 | fake_time_object._number_of_seconds = None | |
93 | 94 | |
94 | 95 | date_tuple = fake_time_object.GetDate() |
95 | 96 | self.assertEqual(date_tuple, (None, None, None)) |
96 | 97 | |
98 | def testGetTimeOfDay(self): | |
99 | """Tests the GetTimeOfDay function.""" | |
97 | 100 | fake_time_object = fake_time.FakeTime() |
101 | fake_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546875') | |
98 | 102 | |
99 | date_tuple = fake_time_object.GetDate() | |
100 | self.assertEqual(date_tuple, (None, None, None)) | |
103 | time_of_day_tuple = fake_time_object.GetTimeOfDay() | |
104 | self.assertEqual(time_of_day_tuple, (21, 6, 31)) | |
105 | ||
106 | fake_time_object = fake_time.FakeTime() | |
107 | fake_time_object._number_of_seconds = None | |
108 | ||
109 | time_of_day_tuple = fake_time_object.GetTimeOfDay() | |
110 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
101 | 111 | |
102 | 112 | |
103 | 113 | if __name__ == '__main__': |
123 | 123 | date_tuple = fat_date_time_object.GetDate() |
124 | 124 | self.assertEqual(date_tuple, (2010, 8, 12)) |
125 | 125 | |
126 | fat_date_time_object._EPOCH.year = -1 | |
127 | ||
128 | date_tuple = fat_date_time_object.GetDate() | |
129 | self.assertEqual(date_tuple, (None, None, None)) | |
130 | ||
131 | 126 | fat_date_time_object = fat_date_time.FATDateTime() |
132 | 127 | |
133 | 128 | date_tuple = fat_date_time_object.GetDate() |
134 | 129 | self.assertEqual(date_tuple, (None, None, None)) |
135 | 130 | |
131 | def testGetTimeOfDay(self): | |
132 | """Tests the GetTimeOfDay function.""" | |
133 | fat_date_time_object = fat_date_time.FATDateTime(fat_date_time=0xa8d03d0c) | |
134 | ||
135 | time_of_day_tuple = fat_date_time_object.GetTimeOfDay() | |
136 | self.assertEqual(time_of_day_tuple, (21, 6, 32)) | |
137 | ||
138 | fat_date_time_object = fat_date_time.FATDateTime() | |
139 | ||
140 | time_of_day_tuple = fat_date_time_object.GetTimeOfDay() | |
141 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
142 | ||
136 | 143 | |
137 | 144 | if __name__ == '__main__': |
138 | 145 | unittest.main() |
97 | 97 | date_tuple = filetime_object.GetDate() |
98 | 98 | self.assertEqual(date_tuple, (2010, 8, 12)) |
99 | 99 | |
100 | filetime_object._EPOCH.year = -1 | |
101 | ||
102 | date_tuple = filetime_object.GetDate() | |
103 | self.assertEqual(date_tuple, (None, None, None)) | |
104 | ||
105 | 100 | filetime_object = filetime.Filetime() |
106 | 101 | |
107 | 102 | date_tuple = filetime_object.GetDate() |
108 | 103 | self.assertEqual(date_tuple, (None, None, None)) |
109 | 104 | |
105 | def testGetTimeOfDay(self): | |
106 | """Tests the GetTimeOfDay function.""" | |
107 | filetime_object = filetime.Filetime(timestamp=0x01cb3a623d0a17ce) | |
108 | ||
109 | time_of_day_tuple = filetime_object.GetTimeOfDay() | |
110 | self.assertEqual(time_of_day_tuple, (21, 6, 31)) | |
111 | ||
112 | filetime_object = filetime.Filetime() | |
113 | ||
114 | time_of_day_tuple = filetime_object.GetTimeOfDay() | |
115 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
116 | ||
110 | 117 | |
111 | 118 | if __name__ == '__main__': |
112 | 119 | unittest.main() |
102 | 102 | date_tuple = hfs_time_object.GetDate() |
103 | 103 | self.assertEqual(date_tuple, (2013, 8, 1)) |
104 | 104 | |
105 | hfs_time_object._EPOCH.year = -1 | |
106 | ||
107 | date_tuple = hfs_time_object.GetDate() | |
108 | self.assertEqual(date_tuple, (None, None, None)) | |
109 | ||
110 | 105 | hfs_time_object = hfs_time.HFSTime() |
111 | 106 | |
112 | 107 | date_tuple = hfs_time_object.GetDate() |
113 | 108 | self.assertEqual(date_tuple, (None, None, None)) |
114 | 109 | |
110 | def testGetTimeOfDay(self): | |
111 | """Tests the GetTimeOfDay function.""" | |
112 | hfs_time_object = hfs_time.HFSTime(timestamp=3458215528) | |
113 | ||
114 | time_of_day_tuple = hfs_time_object.GetTimeOfDay() | |
115 | self.assertEqual(time_of_day_tuple, (15, 25, 28)) | |
116 | ||
117 | hfs_time_object = hfs_time.HFSTime() | |
118 | ||
119 | time_of_day_tuple = hfs_time_object.GetTimeOfDay() | |
120 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
121 | ||
115 | 122 | |
116 | 123 | if __name__ == '__main__': |
117 | 124 | unittest.main() |
81 | 81 | date_tuple = java_time_object.GetDate() |
82 | 82 | self.assertEqual(date_tuple, (2010, 8, 12)) |
83 | 83 | |
84 | java_time_object._EPOCH.year = -1 | |
85 | ||
86 | date_tuple = java_time_object.GetDate() | |
87 | self.assertEqual(date_tuple, (None, None, None)) | |
88 | ||
89 | 84 | java_time_object = java_time.JavaTime() |
90 | 85 | |
91 | 86 | date_tuple = java_time_object.GetDate() |
92 | 87 | self.assertEqual(date_tuple, (None, None, None)) |
93 | 88 | |
89 | def testGetTimeOfDay(self): | |
90 | """Tests the GetTimeOfDay function.""" | |
91 | java_time_object = java_time.JavaTime(timestamp=1281643591546) | |
92 | ||
93 | time_of_day_tuple = java_time_object.GetTimeOfDay() | |
94 | self.assertEqual(time_of_day_tuple, (20, 6, 31)) | |
95 | ||
96 | java_time_object = java_time.JavaTime() | |
97 | ||
98 | time_of_day_tuple = java_time_object.GetTimeOfDay() | |
99 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
100 | ||
94 | 101 | |
95 | 102 | if __name__ == '__main__': |
96 | 103 | unittest.main() |
99 | 99 | date_tuple = ole_automation_date_object.GetDate() |
100 | 100 | self.assertEqual(date_tuple, (2017, 11, 5)) |
101 | 101 | |
102 | ole_automation_date_object._EPOCH.year = -1 | |
103 | ||
104 | date_tuple = ole_automation_date_object.GetDate() | |
105 | self.assertEqual(date_tuple, (None, None, None)) | |
106 | ||
107 | 102 | ole_automation_date_object = ole_automation_date.OLEAutomationDate() |
108 | 103 | |
109 | 104 | date_tuple = ole_automation_date_object.GetDate() |
110 | 105 | self.assertEqual(date_tuple, (None, None, None)) |
111 | 106 | |
107 | def testGetTimeOfDay(self): | |
108 | """Tests the GetTimeOfDay function.""" | |
109 | ole_automation_date_object = ole_automation_date.OLEAutomationDate( | |
110 | timestamp=43044.480556) | |
111 | ||
112 | time_of_day_tuple = ole_automation_date_object.GetTimeOfDay() | |
113 | self.assertEqual(time_of_day_tuple, (11, 32, 0)) | |
114 | ||
115 | ole_automation_date_object = ole_automation_date.OLEAutomationDate() | |
116 | ||
117 | time_of_day_tuple = ole_automation_date_object.GetTimeOfDay() | |
118 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
119 | ||
112 | 120 | |
113 | 121 | if __name__ == '__main__': |
114 | 122 | unittest.main() |
102 | 102 | date_tuple = posix_time_object.GetDate() |
103 | 103 | self.assertEqual(date_tuple, (2010, 8, 12)) |
104 | 104 | |
105 | posix_time_object._EPOCH.year = -1 | |
105 | posix_time_object = posix_time.PosixTime() | |
106 | 106 | |
107 | 107 | date_tuple = posix_time_object.GetDate() |
108 | 108 | self.assertEqual(date_tuple, (None, None, None)) |
109 | 109 | |
110 | posix_time_object = posix_time.PosixTime() | |
111 | ||
112 | date_tuple = posix_time_object.GetDate() | |
113 | self.assertEqual(date_tuple, (None, None, None)) | |
110 | def testGetTimeOfDay(self): | |
111 | """Tests the GetTimeOfDay function.""" | |
112 | posix_time_object = posix_time.PosixTime(timestamp=1281643591) | |
113 | ||
114 | time_of_day_tuple = posix_time_object.GetTimeOfDay() | |
115 | self.assertEqual(time_of_day_tuple, (20, 6, 31)) | |
116 | ||
117 | posix_time_object = posix_time.PosixTime() | |
118 | ||
119 | time_of_day_tuple = posix_time_object.GetTimeOfDay() | |
120 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
114 | 121 | |
115 | 122 | |
116 | 123 | class PosixTimeInMicrosecondsTest(unittest.TestCase): |
205 | 212 | date_tuple = posix_time_object.GetDate() |
206 | 213 | self.assertEqual(date_tuple, (2010, 8, 12)) |
207 | 214 | |
208 | posix_time_object._EPOCH.year = -1 | |
215 | posix_time_object = posix_time.PosixTimeInMicroseconds() | |
209 | 216 | |
210 | 217 | date_tuple = posix_time_object.GetDate() |
211 | 218 | self.assertEqual(date_tuple, (None, None, None)) |
212 | 219 | |
213 | posix_time_object = posix_time.PosixTimeInMicroseconds() | |
214 | ||
215 | date_tuple = posix_time_object.GetDate() | |
216 | self.assertEqual(date_tuple, (None, None, None)) | |
220 | def testGetTimeOfDay(self): | |
221 | """Tests the GetTimeOfDay function.""" | |
222 | posix_time_object = posix_time.PosixTimeInMicroseconds( | |
223 | timestamp=1281643591546875) | |
224 | ||
225 | time_of_day_tuple = posix_time_object.GetTimeOfDay() | |
226 | self.assertEqual(time_of_day_tuple, (20, 6, 31)) | |
227 | ||
228 | posix_time_object = posix_time.PosixTimeInMicroseconds() | |
229 | ||
230 | time_of_day_tuple = posix_time_object.GetTimeOfDay() | |
231 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
217 | 232 | |
218 | 233 | |
219 | 234 | if __name__ == '__main__': |
228 | 228 | date_tuple = rfc2579_date_time_object.GetDate() |
229 | 229 | self.assertEqual(date_tuple, (None, None, None)) |
230 | 230 | |
231 | def testGetTimeOfDay(self): | |
232 | """Tests the GetTimeOfDay function.""" | |
233 | rfc2579_date_time_object = rfc2579_date_time.RFC2579DateTime( | |
234 | rfc2579_date_time_tuple=(2010, 8, 12, 20, 6, 31, 6, '+', 0, 0)) | |
235 | ||
236 | time_of_day_tuple = rfc2579_date_time_object.GetTimeOfDay() | |
237 | self.assertEqual(time_of_day_tuple, (20, 6, 31)) | |
238 | ||
239 | rfc2579_date_time_object = rfc2579_date_time.RFC2579DateTime() | |
240 | ||
241 | time_of_day_tuple = rfc2579_date_time_object.GetTimeOfDay() | |
242 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
243 | ||
231 | 244 | |
232 | 245 | if __name__ == '__main__': |
233 | 246 | unittest.main() |
93 | 93 | date_tuple = semantic_time_object.GetDate() |
94 | 94 | self.assertEqual(date_tuple, (None, None, None)) |
95 | 95 | |
96 | def testGetTimeOfDay(self): | |
97 | """Tests the GetTimeOfDay function.""" | |
98 | semantic_time_object = semantic_time.SemanticTime() | |
99 | ||
100 | time_of_day_tuple = semantic_time_object.GetTimeOfDay() | |
101 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
102 | ||
96 | 103 | def testGetPlasoTimestamp(self): |
97 | 104 | """Tests the GetPlasoTimestamp function.""" |
98 | 105 | semantic_time_object = semantic_time.SemanticTime() |
184 | 184 | date_tuple = systemtime_object.GetDate() |
185 | 185 | self.assertEqual(date_tuple, (None, None, None)) |
186 | 186 | |
187 | def testGetTimeOfDay(self): | |
188 | """Tests the GetTimeOfDay function.""" | |
189 | systemtime_object = systemtime.Systemtime( | |
190 | system_time_tuple=(2010, 8, 4, 12, 20, 6, 31, 142)) | |
191 | ||
192 | time_of_day_tuple = systemtime_object.GetTimeOfDay() | |
193 | self.assertEqual(time_of_day_tuple, (20, 6, 31)) | |
194 | ||
195 | systemtime_object = systemtime.Systemtime() | |
196 | ||
197 | time_of_day_tuple = systemtime_object.GetTimeOfDay() | |
198 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
199 | ||
187 | 200 | |
188 | 201 | if __name__ == '__main__': |
189 | 202 | unittest.main() |
484 | 484 | date_tuple = time_elements_object.GetDate() |
485 | 485 | self.assertEqual(date_tuple, (None, None, None)) |
486 | 486 | |
487 | def testGetTimeOfDay(self): | |
488 | """Tests the GetTimeOfDay function.""" | |
489 | time_elements_object = time_elements.TimeElements( | |
490 | time_elements_tuple=(2010, 8, 12, 20, 6, 31)) | |
491 | ||
492 | time_of_day_tuple = time_elements_object.GetTimeOfDay() | |
493 | self.assertEqual(time_of_day_tuple, (20, 6, 31)) | |
494 | ||
495 | time_elements_object = time_elements.TimeElements() | |
496 | ||
497 | time_of_day_tuple = time_elements_object.GetTimeOfDay() | |
498 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
499 | ||
487 | 500 | |
488 | 501 | class TimeElementsInMillisecondsTest(unittest.TestCase): |
489 | 502 | """Tests for the time elements in milliseconds.""" |
739 | 752 | date_tuple = time_elements_object.GetDate() |
740 | 753 | self.assertEqual(date_tuple, (None, None, None)) |
741 | 754 | |
755 | def testGetTimeOfDay(self): | |
756 | """Tests the GetTimeOfDay function.""" | |
757 | time_elements_object = time_elements.TimeElementsInMilliseconds( | |
758 | time_elements_tuple=(2010, 8, 12, 20, 6, 31, 429)) | |
759 | ||
760 | time_of_day_tuple = time_elements_object.GetTimeOfDay() | |
761 | self.assertEqual(time_of_day_tuple, (20, 6, 31)) | |
762 | ||
763 | time_elements_object = time_elements.TimeElementsInMilliseconds() | |
764 | ||
765 | time_of_day_tuple = time_elements_object.GetTimeOfDay() | |
766 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
767 | ||
742 | 768 | |
743 | 769 | class TimeElementsInMicrosecondsTest(unittest.TestCase): |
744 | 770 | """Tests for the time elements in microseconds.""" |
994 | 1020 | date_tuple = time_elements_object.GetDate() |
995 | 1021 | self.assertEqual(date_tuple, (None, None, None)) |
996 | 1022 | |
1023 | def testGetTimeOfDay(self): | |
1024 | """Tests the GetTimeOfDay function.""" | |
1025 | time_elements_object = time_elements.TimeElementsInMicroseconds( | |
1026 | time_elements_tuple=(2010, 8, 12, 20, 6, 31, 429876)) | |
1027 | ||
1028 | time_of_day_tuple = time_elements_object.GetTimeOfDay() | |
1029 | self.assertEqual(time_of_day_tuple, (20, 6, 31)) | |
1030 | ||
1031 | time_elements_object = time_elements.TimeElementsInMicroseconds() | |
1032 | ||
1033 | time_of_day_tuple = time_elements_object.GetTimeOfDay() | |
1034 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
1035 | ||
997 | 1036 | |
998 | 1037 | if __name__ == '__main__': |
999 | 1038 | unittest.main() |
128 | 128 | date_tuple = uuid_time_object.GetDate() |
129 | 129 | self.assertEqual(date_tuple, (2012, 5, 16)) |
130 | 130 | |
131 | uuid_time_object._EPOCH.year = -1 | |
132 | ||
133 | date_tuple = uuid_time_object.GetDate() | |
134 | self.assertEqual(date_tuple, (None, None, None)) | |
135 | ||
136 | 131 | uuid_time_object = uuid_time.UUIDTime() |
137 | 132 | |
138 | 133 | date_tuple = uuid_time_object.GetDate() |
139 | 134 | self.assertEqual(date_tuple, (None, None, None)) |
140 | 135 | |
136 | def testGetTimeOfDay(self): | |
137 | """Tests the GetTimeOfDay function.""" | |
138 | uuid_object = uuid.UUID('00911b54-9ef4-11e1-be53-525400123456') | |
139 | uuid_time_object = uuid_time.UUIDTime(timestamp=uuid_object.time) | |
140 | ||
141 | time_of_day_tuple = uuid_time_object.GetTimeOfDay() | |
142 | self.assertEqual(time_of_day_tuple, (1, 11, 1)) | |
143 | ||
144 | uuid_time_object = uuid_time.UUIDTime() | |
145 | ||
146 | time_of_day_tuple = uuid_time_object.GetTimeOfDay() | |
147 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
148 | ||
141 | 149 | |
142 | 150 | if __name__ == '__main__': |
143 | 151 | unittest.main() |
97 | 97 | date_tuple = webkit_time_object.GetDate() |
98 | 98 | self.assertEqual(date_tuple, (2010, 8, 12)) |
99 | 99 | |
100 | webkit_time_object._EPOCH.year = -1 | |
101 | ||
102 | date_tuple = webkit_time_object.GetDate() | |
103 | self.assertEqual(date_tuple, (None, None, None)) | |
104 | ||
105 | 100 | webkit_time_object = webkit_time.WebKitTime() |
106 | 101 | |
107 | 102 | date_tuple = webkit_time_object.GetDate() |
108 | 103 | self.assertEqual(date_tuple, (None, None, None)) |
109 | 104 | |
105 | def testGetTimeOfDay(self): | |
106 | """Tests the GetTimeOfDay function.""" | |
107 | webkit_time_object = webkit_time.WebKitTime(timestamp=12926120791546875) | |
108 | ||
109 | time_of_day_tuple = webkit_time_object.GetTimeOfDay() | |
110 | self.assertEqual(time_of_day_tuple, (21, 6, 31)) | |
111 | ||
112 | webkit_time_object = webkit_time.WebKitTime() | |
113 | ||
114 | time_of_day_tuple = webkit_time_object.GetTimeOfDay() | |
115 | self.assertEqual(time_of_day_tuple, (None, None, None)) | |
116 | ||
110 | 117 | |
111 | 118 | if __name__ == '__main__': |
112 | 119 | unittest.main() |