From 4ce50927b077d356384e30e49650e55cc32ed26c Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 16 Oct 2021 10:10:35 +0200 Subject: [PATCH 1/2] clear timezone for datetime values --- app/scodoc/sco_excel.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/scodoc/sco_excel.py b/app/scodoc/sco_excel.py index f3fc0ba2..4258a16a 100644 --- a/app/scodoc/sco_excel.py +++ b/app/scodoc/sco_excel.py @@ -285,9 +285,15 @@ class ScoExcelSheet: def make_cell(self, value: any = None, style=None, comment=None): """Construit une cellule. - value -- contenu de la cellule (texte ou numérique) + value -- contenu de la cellule (texte, numérique, booléen ou date) style -- style par défaut (dictionnaire cf. excel_make_style) de la feuille si non spécifié """ + if value is False: + value = 0 + elif value is True: + value = 1 + if isinstance(value, datetime.datetime): + value = value.replace(tzinfo=None) # make date naive (cf https://openpyxl.readthedocs.io/en/latest/datetime.html#timezones) cell = WriteOnlyCell(self.ws, value or "") if style is None: style = self.default_style From 7cc9f6d1f4ec5b5289ce28004b3e4651113e5aa0 Mon Sep 17 00:00:00 2001 From: Place Jean-Marie Date: Sat, 16 Oct 2021 10:25:40 +0200 Subject: [PATCH 2/2] clear timezone for datetime object --- app/scodoc/sco_excel.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/scodoc/sco_excel.py b/app/scodoc/sco_excel.py index 4258a16a..2ae5b59c 100644 --- a/app/scodoc/sco_excel.py +++ b/app/scodoc/sco_excel.py @@ -288,10 +288,6 @@ class ScoExcelSheet: value -- contenu de la cellule (texte, numérique, booléen ou date) style -- style par défaut (dictionnaire cf. excel_make_style) de la feuille si non spécifié """ - if value is False: - value = 0 - elif value is True: - value = 1 if isinstance(value, datetime.datetime): value = value.replace(tzinfo=None) # make date naive (cf https://openpyxl.readthedocs.io/en/latest/datetime.html#timezones) cell = WriteOnlyCell(self.ws, value or "")