!29 Fix datetime serialization

From: @linker99 
Reviewed-by: @Charlie_li 
Signed-off-by: @Charlie_li
This commit is contained in:
openeuler-ci-bot 2023-12-29 09:14:11 +00:00 committed by Gitee
commit 107b14c695
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,48 @@
From dffef385459c3bd49c33fd69b759485016a7f0b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Vejn=C3=A1r?= <vejnar.martin@gmail.com>
Date: Sat, 27 Oct 2018 21:47:28 +0200
Subject: [PATCH] Fix datetime serialization
---
pytoml/writer.py | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/pytoml/writer.py b/pytoml/writer.py
index 6eaf5d7..2d8afb5 100644
--- a/pytoml/writer.py
+++ b/pytoml/writer.py
@@ -48,13 +48,6 @@ def _escape_id(s):
def _format_list(v):
return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))
-# Formula from:
-# https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
-# Once support for py26 is dropped, this can be replaced by td.total_seconds()
-def _total_seconds(td):
- return ((td.microseconds
- + (td.seconds + td.days * 24 * 3600) * 10**6) / 10.0**6)
-
def _format_value(v):
if isinstance(v, bool):
return 'true' if v else 'false'
@@ -69,7 +62,7 @@ def _format_value(v):
return _escape_string(v)
elif isinstance(v, datetime.datetime):
offs = v.utcoffset()
- offs = _total_seconds(offs) // 60 if offs is not None else 0
+ offs = int(offs.total_seconds()) // 60 if offs is not None else 0
if offs == 0:
suffix = 'Z'
@@ -79,7 +72,7 @@ def _format_value(v):
else:
suffix = '-'
offs = -offs
- suffix = '{0}{1:.02}{2:.02}'.format(suffix, offs // 60, offs % 60)
+ suffix = '{0}{1:02}:{2:02}'.format(suffix, offs // 60, offs % 60)
if v.microsecond:
return v.strftime('%Y-%m-%dT%H:%M:%S.%f') + suffix
--
2.27.0

View File

@ -2,12 +2,13 @@
Name: python-%{github_name}
Version: 0.1.18
Release: 4
Release: 5
Summary: Parser for TOML
License: MIT
URL: https://github.com/avakar/%{github_name}
Source0: https://github.com/avakar/%{github_name}/archive/v%{version}/%{github_name}-%{version}.tar.gz
Patch0: Add-.vscode-and-.pytest_cache-to-.gitignore.patch
Patch1: Fix-datetime-serialization.patch
BuildArch: noarch
%global my_description \
@ -43,6 +44,9 @@ BuildRequires: python3-setuptools
%{python3_sitelib}/%{github_name}/
%changelog
* Fri Dec 29 2023 fandehui <fandehui@xfusion.com> - 0.1.18-5
- Fix datetime serialization
* Mon Dec 11 2023 fandehui <fandehui@xfusion.com> - 0.1.18-4
- Add .vscode and .pytest_cache to .gitignore