Code

Opened 5 years ago

Closed 5 years ago

#12261 closed (duplicate)

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

Reported by: versae 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: UI/UX:

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 versae 5 years ago.
strftime filling with zeros in years below 1000

Download all attachments as: .zip

Change History (3)

Changed 5 years ago by versae

strftime filling with zeros in years below 1000

comment:1 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset

comment:2 Changed 5 years ago by ramiro

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #10866.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.