aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-07-22 09:43:18 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-07-22 09:52:44 +0300
commit22c43d87175dd036cb45fe713ad22f4073056bf0 (patch)
treedc18e08e66944b62b86643b7a6080102a12e170f /library
parent38595c8a249ab9abf1e5214d104711b82d8d98c8 (diff)
downloadydb-22c43d87175dd036cb45fe713ad22f4073056bf0.tar.gz
Intermediate changes
Diffstat (limited to 'library')
-rw-r--r--library/python/monlib/encoder.pyx11
1 files changed, 9 insertions, 2 deletions
diff --git a/library/python/monlib/encoder.pyx b/library/python/monlib/encoder.pyx
index 05cf4fec9a..5387d40a88 100644
--- a/library/python/monlib/encoder.pyx
+++ b/library/python/monlib/encoder.pyx
@@ -8,6 +8,13 @@ import sys
from datetime import datetime
from os import dup
+if sys.version_info.major >= 3:
+ from datetime import timezone
+ EPOCH_AWARE = datetime.fromtimestamp(0, tz=timezone.utc)
+ EPOCH_NAIVE = EPOCH_AWARE.replace(tzinfo=None)
+else:
+ EPOCH_NAIVE = datetime.utcfromtimestamp(0)
+
cdef extern from "util/stream/fwd.h" nogil:
cdef cppclass TAdaptivelyBuffered[T]:
@@ -138,7 +145,7 @@ def dump(registry, fp, format='spack', **kwargs):
elif format == 'json':
indent = int(kwargs.get('indent', 0))
encoder = Encoder.create_json(fp, indent)
- timestamp = kwargs.get('timestamp', datetime.utcfromtimestamp(0))
+ timestamp = kwargs.get('timestamp', EPOCH_NAIVE)
registry.accept(timestamp, encoder)
encoder.close()
@@ -166,7 +173,7 @@ def dumps(registry, format='spack', **kwargs):
elif format == 'json':
indent = int(kwargs.get('indent', 0))
encoder = Encoder.create_json(None, indent)
- timestamp = kwargs.get('timestamp', datetime.utcfromtimestamp(0))
+ timestamp = kwargs.get('timestamp', EPOCH_NAIVE)
registry.accept(timestamp, encoder)
encoder.close()