|
8 | 8 |
|
9 | 9 |
|
10 | 10 | class APFSTime(posix_time.PosixTimeInNanoseconds): |
11 | | - """Apple File System (APFS) timestamp. |
| 11 | + """Apple File System (APFS) timestamp. |
12 | 12 |
|
13 | | - The APFS timestamp is a signed 64-bit integer that contains the number of |
14 | | - nanoseconds since 1970-01-01 00:00:00. |
| 13 | + The APFS timestamp is a signed 64-bit integer that contains the number of |
| 14 | + nanoseconds since 1970-01-01 00:00:00. |
15 | 15 |
|
16 | | - Attributes: |
17 | | - is_local_time (bool): True if the date and time value is in local time. |
18 | | - """ |
19 | | - |
20 | | - def _GetNormalizedTimestamp(self): |
21 | | - """Retrieves the normalized timestamp. |
22 | | -
|
23 | | - Returns: |
24 | | - decimal.Decimal: normalized timestamp, which contains the number of |
25 | | - seconds since January 1, 1970 00:00:00 and a fraction of second used |
26 | | - for increased precision, or None if the normalized timestamp cannot be |
27 | | - determined. |
28 | | - """ |
29 | | - if self._normalized_timestamp is None: |
30 | | - if (self._timestamp is not None and self._timestamp >= self._INT64_MIN and |
31 | | - self._timestamp <= self._INT64_MAX): |
32 | | - self._normalized_timestamp = ( |
33 | | - decimal.Decimal(self._timestamp) / |
34 | | - definitions.NANOSECONDS_PER_SECOND) |
35 | | - |
36 | | - if self._time_zone_offset: |
37 | | - self._normalized_timestamp -= self._time_zone_offset * 60 |
38 | | - |
39 | | - return self._normalized_timestamp |
40 | | - |
41 | | - def CopyFromDateTimeString(self, time_string): |
42 | | - """Copies a APFS timestamp from a date and time string. |
43 | | -
|
44 | | - Args: |
45 | | - time_string (str): date and time value formatted as: |
46 | | - YYYY-MM-DD hh:mm:ss.######[+-]##:## |
47 | | -
|
48 | | - Where # are numeric digits ranging from 0 to 9 and the seconds |
49 | | - fraction can be either 3, 6 or 9 digits. The time of day, seconds |
50 | | - fraction and time zone offset are optional. The default time zone |
51 | | - is UTC. |
52 | | -
|
53 | | - Raises: |
54 | | - ValueError: if the date and time value is not supported. |
55 | | - """ |
56 | | - super()._CopyFromDateTimeString(time_string) |
57 | | - |
58 | | - if (self._timestamp is None or self._timestamp < self._INT64_MIN or |
59 | | - self._timestamp > self._INT64_MAX): |
60 | | - raise ValueError('Date time value not supported.') |
61 | | - |
62 | | - def CopyToDateTimeString(self): |
63 | | - """Copies the APFS timestamp to a date and time string. |
64 | | -
|
65 | | - Returns: |
66 | | - str: date and time value formatted as: "YYYY-MM-DD hh:mm:ss.#########" or |
67 | | - None if the timestamp is missing or invalid. |
| 16 | + Attributes: |
| 17 | + is_local_time (bool): True if the date and time value is in local time. |
68 | 18 | """ |
69 | | - if (self._timestamp is None or self._timestamp < self._INT64_MIN or |
70 | | - self._timestamp > self._INT64_MAX): |
71 | | - return None |
72 | 19 |
|
73 | | - return super()._CopyToDateTimeString() |
| 20 | + def _GetNormalizedTimestamp(self): |
| 21 | + """Retrieves the normalized timestamp. |
| 22 | +
|
| 23 | + Returns: |
| 24 | + decimal.Decimal: normalized timestamp, which contains the number of |
| 25 | + seconds since January 1, 1970 00:00:00 and a fraction of second used |
| 26 | + for increased precision, or None if the normalized timestamp cannot be |
| 27 | + determined. |
| 28 | + """ |
| 29 | + if self._normalized_timestamp is None: |
| 30 | + if ( |
| 31 | + self._timestamp is not None |
| 32 | + and self._timestamp >= self._INT64_MIN |
| 33 | + and self._timestamp <= self._INT64_MAX |
| 34 | + ): |
| 35 | + self._normalized_timestamp = ( |
| 36 | + decimal.Decimal(self._timestamp) |
| 37 | + / definitions.NANOSECONDS_PER_SECOND |
| 38 | + ) |
| 39 | + |
| 40 | + if self._time_zone_offset: |
| 41 | + self._normalized_timestamp -= self._time_zone_offset * 60 |
| 42 | + |
| 43 | + return self._normalized_timestamp |
| 44 | + |
| 45 | + def CopyFromDateTimeString(self, time_string): |
| 46 | + """Copies a APFS timestamp from a date and time string. |
| 47 | +
|
| 48 | + Args: |
| 49 | + time_string (str): date and time value formatted as: |
| 50 | + YYYY-MM-DD hh:mm:ss.######[+-]##:## |
| 51 | +
|
| 52 | + Where # are numeric digits ranging from 0 to 9 and the seconds |
| 53 | + fraction can be either 3, 6 or 9 digits. The time of day, seconds |
| 54 | + fraction and time zone offset are optional. The default time zone |
| 55 | + is UTC. |
| 56 | +
|
| 57 | + Raises: |
| 58 | + ValueError: if the date and time value is not supported. |
| 59 | + """ |
| 60 | + super()._CopyFromDateTimeString(time_string) |
| 61 | + |
| 62 | + if ( |
| 63 | + self._timestamp is None |
| 64 | + or self._timestamp < self._INT64_MIN |
| 65 | + or self._timestamp > self._INT64_MAX |
| 66 | + ): |
| 67 | + raise ValueError("Date time value not supported.") |
| 68 | + |
| 69 | + def CopyToDateTimeString(self): |
| 70 | + """Copies the APFS timestamp to a date and time string. |
| 71 | +
|
| 72 | + Returns: |
| 73 | + str: date and time value formatted as: "YYYY-MM-DD hh:mm:ss.#########" or |
| 74 | + None if the timestamp is missing or invalid. |
| 75 | + """ |
| 76 | + if ( |
| 77 | + self._timestamp is None |
| 78 | + or self._timestamp < self._INT64_MIN |
| 79 | + or self._timestamp > self._INT64_MAX |
| 80 | + ): |
| 81 | + return None |
| 82 | + |
| 83 | + return super()._CopyToDateTimeString() |
74 | 84 |
|
75 | 85 |
|
76 | 86 | factory.Factory.RegisterDateTimeValues(APFSTime) |
0 commit comments