Project

General

Profile

Bug #9852

crash export json sur les dates avant 1900

Added by Thomas Noël about 7 years ago. Updated almost 7 years ago.

Status:
Fermé
Priority:
Normal
Assignee:
-
Target version:
Start date:
03 February 2016
Due date:
% Done:

0%

Estimated time:
Patch proposed:
No
Planning:

Description


Exception:
  type = '<type 'exceptions.ValueError'>', value = 'year out of range'

Stack trace (most recent call first):
  File "/usr/lib/python2.7/dist-packages/wcs/qommon/misc.py", line 401, in default
   399     def default(self, obj):
   400         if isinstance(obj, time.struct_time):
>  401             return datetime.datetime.utcfromtimestamp(time.mktime(obj)).isoformat() + 'Z'
   402         # Let the base class default method raise the TypeError
   403         return json.JSONEncoder.default(self, obj)

  locals:
     self = <qommon.misc.JSONEncoder object at 0x4778c10>
     obj = time.struct_time(tm_year=1899, tm_mon=12, tm_mday=31, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=365, tm_isdst=-1)

(en l'occurrence il s'agit d'erreur de saisie, mais bon [erreur de saisie du au widget datepicker qui supporte mal la saisie au clavier dans le champ]).


Related issues

Related to w.c.s. - Bug #9933: mauvaise entrée sur date picker → 31/12/1899Fermé10 February 2016

Actions

History

#1

Updated by Benjamin Dauvergne about 7 years ago

struct_time est dans la timezone locale et mktime reconvertie en timestamp UTC, le code suivant devrait éviter de passer par un timestamp:

import datetime
import dateutil.tz

def struct_time_to_isoformat(st):
    dt = datetime.datetime(*st[:6]).replace(tzinfo=dateutil.tz.tzlocal())
    dt = dt.astimezone(dateutil.tz.tzutc)
    return dt.replace(tzinfo=None).isoformat() + 'Z'

Il faudrait tester en énumérant pas mal de timestamp sur n années, convertir en struct_time et voir si ça matche toujours avec l'ancien code.

#2

Updated by Thomas Noël about 7 years ago

  • Target version set to v1.32
#3

Updated by Thomas Noël about 7 years ago

  • Target version deleted (v1.32)
#4

Updated by Frédéric Péters about 7 years ago

  • Related to Bug #7132: format des dates, conflit API json et workflow_data/form. added
#5

Updated by Frédéric Péters about 7 years ago

  • Related to deleted (Bug #7132: format des dates, conflit API json et workflow_data/form.)
#6

Updated by Frédéric Péters about 7 years ago

  • Related to Bug #9933: mauvaise entrée sur date picker → 31/12/1899 added
#7

Updated by Thomas Noël about 7 years ago

  • Target version set to v1.33
#8

Updated by Thomas Noël about 7 years ago

  • Target version changed from v1.33 to v1.34
#9

Updated by Thomas Noël about 7 years ago

  • Target version changed from v1.34 to v1.35
#10

Updated by Thomas Noël about 7 years ago

  • Target version changed from v1.35 to v1.37
#11

Updated by Thomas Noël almost 7 years ago

  • Status changed from Nouveau to Fermé

Also available in: Atom PDF