Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.

Commit 3f7ad17

Browse files
committed
use local time when logging
1 parent b6783a3 commit 3f7ad17

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

p2p/persistence.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def str_to_time(as_str: str) -> datetime.datetime:
4848
return datetime.datetime.strptime(as_str, "%Y-%m-%dT%H:%M:%S")
4949

5050

51+
def utc_to_local(utc: datetime.datetime) -> datetime.datetime:
52+
local_tz = datetime.datetime.now().astimezone()
53+
return utc + local_tz.utcoffset()
54+
55+
5156
class BasePeerInfo(ABC, HasExtendedDebugLogger):
5257
@abstractmethod
5358
def record_failure(self, remote: Node, failure: BaseP2PError) -> None:
@@ -116,15 +121,17 @@ def _record_bad_node(self, remote: Node, timeout: int, reason: str) -> None:
116121
if bad_node:
117122
new_error_count = bad_node.error_count + 1
118123
usable_time = now + datetime.timedelta(seconds=timeout * new_error_count)
124+
local_time = utc_to_local(usable_time)
119125
self.logger.debug(
120-
'%s will not be retried until %s because %s', remote, usable_time, reason
126+
'%s will not be retried until %s because %s', remote, local_time, reason
121127
)
122128
self._update_bad_node(enode, usable_time, reason, new_error_count)
123129
return
124130

125131
usable_time = now + datetime.timedelta(seconds=timeout)
132+
local_time = utc_to_local(usable_time)
126133
self.logger.debug(
127-
'%s will not be retried until %s because %s', remote, usable_time, reason
134+
'%s will not be retried until %s because %s', remote, local_time, reason
128135
)
129136
self._insert_bad_node(enode, usable_time, reason, error_count=1)
130137

@@ -137,9 +144,10 @@ def should_connect_to(self, remote: Node) -> bool:
137144

138145
until = str_to_time(bad_node.until)
139146
if datetime.datetime.utcnow() < until:
147+
local_time = utc_to_local(until)
140148
self.logger.debug(
141149
'skipping %s, it failed because "%s" and is not usable until %s',
142-
remote, bad_node.reason, bad_node.until
150+
remote, bad_node.reason, local_time
143151
)
144152
return False
145153

0 commit comments

Comments
 (0)