Skip to content

Commit

Permalink
test(test_date.py): add tests for negative timestamp evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
gutsytechster committed Jun 12, 2022
1 parent abc5d96 commit 4bc90c6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test_date.py
Expand Up @@ -726,6 +726,34 @@ def test_timestamp_in_microseconds(self):
datetime.fromtimestamp(1570308760).replace(microsecond=263111)
)

@parameterized.expand([
param(
input_timestamp='-1570308760',
negative_allowed=True,
result=datetime.fromtimestamp(-1570308760)
),
param(
input_timestamp='-1570308760',
negative_allowed=False,
result=None
),
param(
input_timestamp='1570308760',
negative_allowed=True,
result=None
),
param(
input_timestamp='1570308760',
negative_allowed=False,
result=datetime.fromtimestamp(1570308760)
)
])
def test_timestamp_with_negative(self, input_timestamp, negative_allowed, result):
self.assertEqual(
date.get_date_from_timestamp(input_timestamp, None, negative=negative_allowed),
result
)

@parameterized.expand([
param(date_string='15703087602631'),
param(date_string='157030876026xx'),
Expand Down
12 changes: 12 additions & 0 deletions tests/test_date_parser.py
Expand Up @@ -645,6 +645,18 @@ def test_parse_timestamp(self, date_string, expected):
self.then_date_obj_exactly_is(expected)
self.then_period_is('day')

@parameterized.expand([
param('-1484823450', expected=datetime(1922, 12, 13, 13, 2, 30)),
param('-1436745600000', expected=datetime(1924, 6, 22, 0, 0)),
param('-1015673450000001', expected=datetime(1937, 10, 25, 12, 29, 10, 1))
])
def test_parse_negative_timestamp(self, date_string, expected):
self.given_local_tz_offset(0)
self.given_parser(settings={'TO_TIMEZONE': 'UTC', 'PARSERS': ['negative-timestamp']})
self.when_date_is_parsed(date_string)
self.then_date_obj_exactly_is(expected)
self.then_period_is('day')

@parameterized.expand([
# Epoch timestamps.
param('1484823450', expected=datetime(2017, 1, 19, 10, 57, 30)),
Expand Down

0 comments on commit 4bc90c6

Please sign in to comment.