Opened 14 years ago

Closed 14 years ago

#12261 closed (duplicate)

strftime function from django.utils.datetime_safe doesn't work properly in years below 1000

Reported by: Javier de la Rosa Owned by: nobody
Component: Core (Serialization) Version: 1.1
Severity: Keywords: datetime serialization strftime
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If a model has a DateTimeField attribute, in order to serialize the objects, django uses the format "%Y/%m/%d". However the function strftime doesn't handle properly the option "%Y" in years below 1000: instead to fill with zeros (0) until to complete the 4 digits, it uses spaces. Therefore, at deserialization time django raises a exception.

Currently

>>> datetime_safe.date(850, 8, 2).strftime("%Y/%m/%d")
' 850/00/02'

It must to be

>>> datetime_safe.date(850, 8, 2).strftime("%Y/%m/%d")
'0850/00/02'

The simplest patch is atached, but this issue can be deeper.

Attachments (1)

strftime_filling_with_zeros_years_below_1000.diff (400 bytes ) - added by Javier de la Rosa 14 years ago.
strftime filling with zeros in years below 1000

Download all attachments as: .zip

Change History (3)

by Javier de la Rosa, 14 years ago

strftime filling with zeros in years below 1000

comment:1 by Alex Gaynor, 14 years ago

Needs tests: set

comment:2 by Ramiro Morales, 14 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #10866.

Note: See TracTickets for help on using tickets.
Back to Top