Skip to content

Commit

Permalink
Do not set undefined time zone for copy from string (log2timeline#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Feb 23, 2024
1 parent e092d3b commit f9247c6
Show file tree
Hide file tree
Showing 36 changed files with 129 additions and 130 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
version: ['38']
version: ['39']
container:
image: registry.fedoraproject.org/fedora:${{ matrix.version }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions config/dpkg/changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dfdatetime (20240210-1) unstable; urgency=low
dfdatetime (20240220-1) unstable; urgency=low

* Auto-generated

-- Log2Timeline maintainers <[email protected]> Sat, 10 Feb 2024 07:26:17 +0100
-- Log2Timeline maintainers <[email protected]> Tue, 20 Feb 2024 19:10:25 +0100
2 changes: 1 addition & 1 deletion dfdatetime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
from dfdatetime import webkit_time


__version__ = '20240210'
__version__ = '20240220'
2 changes: 1 addition & 1 deletion dfdatetime/cocoa_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

timestamp = self._GetNumberOfSecondsFromElements(
year, month, day_of_month, hours, minutes, seconds)
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/delphi_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

if year > 9999:
raise ValueError(f'Unsupported year value: {year:d}.')
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/dotnet_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

if year > 9999:
raise ValueError(f'Unsupported year value: {year:d}.')
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/fake_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', None)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

self._normalized_timestamp = None
self._number_of_seconds = self._GetNumberOfSecondsFromElements(
Expand Down
4 changes: 2 additions & 2 deletions dfdatetime/fat_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def CopyFromDateTimeString(self, time_string):
hours = date_time_values.get('hours', 0)
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

if year < 1980 or year > (1980 + 0x7f):
raise ValueError(f'Year value not supported: {year!s}.')
Expand Down Expand Up @@ -266,7 +266,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

if year < 1980 or year > (1980 + 0x7f):
raise ValueError(f'Year value not supported: {year!s}.')
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/filetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

if year < 1601:
raise ValueError(f'Year value not supported: {year!s}.')
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/golang_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

if year < 0:
raise ValueError(f'Year value not supported: {year!s}.')
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/hfs_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def CopyFromDateTimeString(self, time_string):
hours = date_time_values.get('hours', 0)
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

if year < 1904 or year > 2040:
raise ValueError('Year value not supported.')
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/ole_automation_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

timestamp = self._GetNumberOfSecondsFromElements(
year, month, day_of_month, hours, minutes, seconds)
Expand Down
8 changes: 4 additions & 4 deletions dfdatetime/posix_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def CopyFromDateTimeString(self, time_string):
hours = date_time_values.get('hours', 0)
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

self._timestamp = self._GetNumberOfSecondsFromElements(
year, month, day_of_month, hours, minutes, seconds)
Expand Down Expand Up @@ -188,7 +188,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

milliseconds, _ = divmod(
nanoseconds, definitions.NANOSECONDS_PER_MILLISECOND)
Expand Down Expand Up @@ -294,7 +294,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

milliseconds, _ = divmod(
nanoseconds, definitions.NANOSECONDS_PER_MICROSECOND)
Expand Down Expand Up @@ -400,7 +400,7 @@ def _CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

timestamp = self._GetNumberOfSecondsFromElements(
year, month, day_of_month, hours, minutes, seconds)
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/rfc2579_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

deciseconds, _ = divmod(
nanoseconds, definitions.NANOSECONDS_PER_DECISECOND)
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/systemtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

milliseconds, _ = divmod(
nanoseconds, definitions.NANOSECONDS_PER_MILLISECOND)
Expand Down
4 changes: 2 additions & 2 deletions dfdatetime/time_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _CopyFromDateTimeValues(self, date_time_values):
hours = date_time_values.get('hours', 0)
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

self._normalized_timestamp = None
self._number_of_seconds = self._GetNumberOfSecondsFromElements(
Expand Down Expand Up @@ -954,7 +954,7 @@ def _CopyFromDateTimeValues(self, date_time_values):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

precision_helper = precisions.PrecisionHelperFactory.CreatePrecisionHelper(
self._precision)
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/uuid_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

if year < 1582:
raise ValueError('Year value not supported.')
Expand Down
2 changes: 1 addition & 1 deletion dfdatetime/webkit_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def CopyFromDateTimeString(self, time_string):
minutes = date_time_values.get('minutes', 0)
seconds = date_time_values.get('seconds', 0)
nanoseconds = date_time_values.get('nanoseconds', 0)
time_zone_offset = date_time_values.get('time_zone_offset', 0)
time_zone_offset = date_time_values.get('time_zone_offset', None)

microseconds, _ = divmod(
nanoseconds, definitions.NANOSECONDS_PER_MICROSECOND)
Expand Down
3 changes: 1 addition & 2 deletions docs/sources/Date-and-time-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ Supported date range | 1601-01-01 00:00:00.0000000 through ...
Storage granularity | 100-nanosecond intervals
Time zone | externally represented, typically UTC

The actual upper bound of the supported date range is unclear. Also see:
[Latest possible FILETIME](https://stackoverflow.com/questions/9999393/latest-possible-filetime)
The actual upper bound of the supported date range is unclear.

### Format

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = dfdatetime
version = 20240210
version = 20240220
description = Digital Forensics date and time (dfDateTime).
long_description = dfDateTime, or Digital Forensics date and time, provides date and time objects to preserve accuracy and precision.
long_description_content_type = text/plain
Expand Down
8 changes: 4 additions & 4 deletions tests/cocoa_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ def testCopyFromDateTimeString(self):

cocoa_time_object.CopyFromDateTimeString('2013-07-08')
self.assertEqual(cocoa_time_object._timestamp, 394934400.0)
self.assertEqual(cocoa_time_object._time_zone_offset, 0)
self.assertEqual(cocoa_time_object._time_zone_offset, None)

cocoa_time_object.CopyFromDateTimeString('2013-07-08 21:30:45')
self.assertEqual(cocoa_time_object._timestamp, 395011845.0)
self.assertEqual(cocoa_time_object._time_zone_offset, 0)
self.assertEqual(cocoa_time_object._time_zone_offset, None)

cocoa_time_object.CopyFromDateTimeString('2013-07-08 21:30:45.546875')
self.assertEqual(cocoa_time_object._timestamp, 395011845.546875)
self.assertEqual(cocoa_time_object._time_zone_offset, 0)
self.assertEqual(cocoa_time_object._time_zone_offset, None)

cocoa_time_object.CopyFromDateTimeString('2013-07-08 21:30:45.546875-01:00')
self.assertEqual(cocoa_time_object._timestamp, 395011845.546875)
Expand All @@ -80,7 +80,7 @@ def testCopyFromDateTimeString(self):

cocoa_time_object.CopyFromDateTimeString('2001-01-02 00:00:00')
self.assertEqual(cocoa_time_object._timestamp, 86400.0)
self.assertEqual(cocoa_time_object._time_zone_offset, 0)
self.assertEqual(cocoa_time_object._time_zone_offset, None)

def testCopyToDateTimeString(self):
"""Tests the CopyToDateTimeString function."""
Expand Down
8 changes: 4 additions & 4 deletions tests/delphi_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ def testCopyFromDateTimeString(self):

delphi_date_time_object.CopyFromDateTimeString('2013-06-18')
self.assertEqual(delphi_date_time_object._timestamp, 41443.0)
self.assertEqual(delphi_date_time_object._time_zone_offset, 0)
self.assertEqual(delphi_date_time_object._time_zone_offset, None)

delphi_date_time_object.CopyFromDateTimeString('2013-06-18 19:50:00')
self.assertEqual(delphi_date_time_object._timestamp, 41443.82638888889)
self.assertEqual(delphi_date_time_object._time_zone_offset, 0)
self.assertEqual(delphi_date_time_object._time_zone_offset, None)

delphi_date_time_object.CopyFromDateTimeString('2013-06-18 19:50:00.546875')
self.assertEqual(delphi_date_time_object._timestamp, 41443.826395218464)
self.assertEqual(delphi_date_time_object._time_zone_offset, 0)
self.assertEqual(delphi_date_time_object._time_zone_offset, None)

delphi_date_time_object.CopyFromDateTimeString(
'2013-06-18 19:50:00.546875-01:00')
Expand All @@ -122,7 +122,7 @@ def testCopyFromDateTimeString(self):

delphi_date_time_object.CopyFromDateTimeString('1899-12-31 00:00:00')
self.assertEqual(delphi_date_time_object._timestamp, 1.0)
self.assertEqual(delphi_date_time_object._time_zone_offset, 0)
self.assertEqual(delphi_date_time_object._time_zone_offset, None)

delphi_date_time_object = DelphiDateTimeInvalidYear()

Expand Down
6 changes: 3 additions & 3 deletions tests/dotnet_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def testCopyFromDateTimeString(self):

dotnet_date_time.CopyFromDateTimeString('2020-12-12')
self.assertEqual(dotnet_date_time._timestamp, 637433280000000000)
self.assertEqual(dotnet_date_time._time_zone_offset, 0)
self.assertEqual(dotnet_date_time._time_zone_offset, None)

dotnet_date_time.CopyFromDateTimeString('2020-12-12 12:12:12')
self.assertEqual(dotnet_date_time._timestamp, 637433719320000000)
self.assertEqual(dotnet_date_time._time_zone_offset, 0)
self.assertEqual(dotnet_date_time._time_zone_offset, None)

dotnet_date_time.CopyFromDateTimeString('2020-12-12 12:12:12.123')
self.assertEqual(dotnet_date_time._timestamp, 637433719321230000)
self.assertEqual(dotnet_date_time._time_zone_offset, 0)
self.assertEqual(dotnet_date_time._time_zone_offset, None)

def testCopyToDateTimeString(self):
"""Tests the CopyToDateTimeString function."""
Expand Down
8 changes: 4 additions & 4 deletions tests/fake_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ def testCopyFromDateTimeString(self):
fake_time_object.CopyFromDateTimeString('2010-08-12')
self.assertEqual(fake_time_object._number_of_seconds, 1281571200)
self.assertIsNone(fake_time_object._microseconds)
self.assertEqual(fake_time_object._time_zone_offset, 0)
self.assertEqual(fake_time_object._time_zone_offset, None)

fake_time_object.CopyFromDateTimeString('2010-08-12 21:06:31')
self.assertEqual(fake_time_object._number_of_seconds, 1281647191)
self.assertIsNone(fake_time_object._microseconds)
self.assertEqual(fake_time_object._time_zone_offset, 0)
self.assertEqual(fake_time_object._time_zone_offset, None)

fake_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546875')
self.assertEqual(fake_time_object._number_of_seconds, 1281647191)
self.assertEqual(fake_time_object._microseconds, 546875)
self.assertEqual(fake_time_object._time_zone_offset, 0)
self.assertEqual(fake_time_object._time_zone_offset, None)

fake_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546875-01:00')
self.assertEqual(fake_time_object._number_of_seconds, 1281647191)
Expand All @@ -80,7 +80,7 @@ def testCopyFromDateTimeString(self):
fake_time_object.CopyFromDateTimeString('1601-01-02 00:00:00')
self.assertEqual(fake_time_object._number_of_seconds, -11644387200)
self.assertIsNone(fake_time_object._microseconds)
self.assertEqual(fake_time_object._time_zone_offset, 0)
self.assertEqual(fake_time_object._time_zone_offset, None)

def testCopyToDateTimeString(self):
"""Tests the CopyToDateTimeString function."""
Expand Down
16 changes: 8 additions & 8 deletions tests/fat_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def testCopyFromDateTimeString(self):

fat_date_time_object.CopyFromDateTimeString('2010-08-12')
self.assertEqual(fat_date_time_object._number_of_seconds, 966038400)
self.assertEqual(fat_date_time_object._time_zone_offset, 0)
self.assertEqual(fat_date_time_object._time_zone_offset, None)

fat_date_time_object.CopyFromDateTimeString('2010-08-12 21:06:31')
self.assertEqual(fat_date_time_object._number_of_seconds, 966114391)
self.assertEqual(fat_date_time_object._time_zone_offset, 0)
self.assertEqual(fat_date_time_object._time_zone_offset, None)

fat_date_time_object.CopyFromDateTimeString('2010-08-12 21:06:31.546875')
self.assertEqual(fat_date_time_object._number_of_seconds, 966114391)
self.assertEqual(fat_date_time_object._time_zone_offset, 0)
self.assertEqual(fat_date_time_object._time_zone_offset, None)

fat_date_time_object.CopyFromDateTimeString(
'2010-08-12 21:06:31.546875-01:00')
Expand All @@ -74,7 +74,7 @@ def testCopyFromDateTimeString(self):

fat_date_time_object.CopyFromDateTimeString('1980-01-02 00:00:00')
self.assertEqual(fat_date_time_object._number_of_seconds, 86400)
self.assertEqual(fat_date_time_object._time_zone_offset, 0)
self.assertEqual(fat_date_time_object._time_zone_offset, None)

with self.assertRaises(ValueError):
fat_date_time_object.CopyFromDateTimeString('2200-01-02 00:00:00')
Expand Down Expand Up @@ -204,15 +204,15 @@ def testCopyFromDateTimeString(self):

fat_timestamp_object.CopyFromDateTimeString('2021-07-09')
self.assertEqual(fat_timestamp_object._timestamp, 131025600000)
self.assertEqual(fat_timestamp_object._time_zone_offset, 0)
self.assertEqual(fat_timestamp_object._time_zone_offset, None)

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)
self.assertEqual(fat_timestamp_object._time_zone_offset, None)

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)
self.assertEqual(fat_timestamp_object._time_zone_offset, None)

fat_timestamp_object.CopyFromDateTimeString(
'2021-07-09 22:11:30.246875-01:00')
Expand All @@ -226,7 +226,7 @@ def testCopyFromDateTimeString(self):

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)
self.assertEqual(fat_timestamp_object._time_zone_offset, None)

with self.assertRaises(ValueError):
fat_timestamp_object.CopyFromDateTimeString('2200-01-02 00:00:00')
Expand Down
Loading

0 comments on commit f9247c6

Please sign in to comment.