Skip to content

Commit 9b14152

Browse files
committed
Safe handling of old timestamps
1 parent 85b0ac6 commit 9b14152

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ This repository contains the Python library for using implementing the different
77
alt="Project Status"
88
src="https://img.shields.io/badge/Project%20Status-beta-orange"
99
>
10+
<img
11+
alt="GitHub Workflow Status"
12+
src="https://img.shields.io/github/actions/workflow/status/EnAccess/OpenPAYGO-python/ci-cd.yml"
13+
>
1014
<a href="https://github.com/EnAccess/OpenPAYGO-python/blob/main/LICENSE" target="_blank">
1115
<img
1216
alt="License"
@@ -313,6 +317,9 @@ def device_data():
313317

314318
## Changelog
315319

320+
### 2023-10-13 - v0.5.4
321+
- Safe handling of datetime before UNIX timestamp minimum when generating answer timestamp
322+
316323
### 2023-10-13 - v0.5.3
317324
- Fix handling of `last_request_timestamp` when checking auth
318325

openpaygo/metrics_response.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,14 @@ def expects_time_answer(self):
103103
def add_time_to_answer(self, target_datetime):
104104
data = self._get_simple_data()
105105
if data.get('active_until_timestamp_requested', False):
106-
self.response_dict['active_until_timestamp'] = target_datetime.timestamp()
106+
target_timestamp = 0
107+
if target_datetime:
108+
if target_datetime.year > 1970:
109+
target_timestamp = target_datetime.timestamp()
110+
self.response_dict['active_until_timestamp'] = target_timestamp
107111
elif data.get('active_seconds_left_requested', False):
108-
self.response_dict['active_seconds_left'] = (datetime.now() - target_datetime).total_seconds()
112+
seconds_left = (datetime.now() - target_datetime).total_seconds() if target_datetime else 0
113+
self.response_dict['active_seconds_left'] = seconds_left if seconds_left > 0 else 0
109114
else:
110115
raise ValueError('No time requested')
111116

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = openpaygo
3-
version = 0.5.3
3+
version = 0.5.4
44
description = OpenPAYGO library in Python
55
long_description = file: README.md
66
long_description_content_type = text/markdown

0 commit comments

Comments
 (0)