BAD DATE for dates in February

Bug #1576742 reported by mcam on 2016-04-29
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Charles Haley

Bug Description

The expression {pubdate:format_date(yyyy)} returns BAD DATE for dates in February in years which are not leap. I only noticed this problem with the 2.56 version. I'm running the 64-bit version on Windows 10.

mcam (mcam-u) on 2016-04-29
description: updated
description: updated

Changing the component for this bug.

 assignee cbhaley
 status triaged

Changed in calibre:
assignee: nobody → Charles Haley (cbhaley)
status: New → Triaged
Charles Haley (cbhaley) wrote :

It works fine for me. I tried it with 29/Feb/2016, 28/Feb/2016, 1/Feb/2016, 28/Feb/2015 and a host of other dates.

Can you give me some specific examples? Be sure to tell me what locale (language) you are using in calibre and in your operating system.

Changed in calibre:
status: Triaged → Incomplete
mcam (mcam-u) wrote :

It gives me a BAD DATE for any date in February EXCEPT if it's in a leap year. So it works OK for 29/Feb/2016, 28/Feb/2016, 1/Feb/2016 for me too, but gives a BAD DATE for 28/Feb/2015. My Windows display language is English (United States). In Calibre it is set to English (UK). This problem only cropped up in Calibre recently (possibly with the 2.56 update, or maybe the one before that) - it used to work just fine before.

Charles Haley (cbhaley) wrote :

It works for me.

I put the template {pubdate:format_date(yyyy)} in a column built from other columns, sorted the library by pubdate, and all the dates work. See the attached screen capture.

I am not saying it isn't happening to you, but I can't fix it until I can repeat it.

Have you set any of the tweaks that control dates, for example "gui_pubdate_display_format"?

mcam (mcam-u) wrote :

OK, from the screen capture I see that all your February dates are in 2016 - a leap year. Can you repeat with February dates in 2015 instead? For my part, I haven't changed any settings - I just updated my Calibre version.

mcam (mcam-u) wrote :

I'm attaching a screenshot - the YEAR column is defined as {pubdate:format_date(yyyy)}.

Charles Haley (cbhaley) wrote :

My screen capture shows Feb dates in 2015 and 2013.

I note in your screen capture that the pub date is displaying without a day. Have you changed the tweak?

mcam (mcam-u) wrote :

Yes, that's the problem - I tweaked gui_pubdate_display_format = "MMM yyyy". Reverting to "dd MMM yyyy" solves the issue. Of course, it's still a bug, since how the date is displayed should not effect it's underlying value, and only when it's a February date in a non-leap year (and only since recent updates). Thanks for your help in locating the source of the problem.

Charles Haley (cbhaley) wrote :

For various reasons I won't go into, the template language uses the displayed values, not the underlying values. This won't change.

The problem is not in calibre's code but is instead inside some python libraries. I don't know if/when those libraries changed. It could easily be the case that the problem is triggered by being after Feb, not by a calibre update.

I have a "fix", but given that I don't understand exactly why it is happening I cannot guarantee that the fix won't break something. My guess is that when a "day" is missing from the date, the python library assumes the last day of the month. When we are in a leap year that last day is wrong for all the non-leap years. The "fix" is to supply a default for the day that is in the middle of the month.

As I suspect that the fix is no worse than the problem, I will submit it.

Changed in calibre:
status: Incomplete → Fix Committed

Fixed in branch master. The fix will be in the next release. calibre is usually released every Friday.

 status fixreleased

Changed in calibre:
status: Fix Committed → Fix Released
Kovid Goyal (kovid) wrote :

Note that at least according to the docs of format_date() you can use {:'format_date(raw_field('pubdate'),'yyyy')'} to work on the underlying date rather than its string encoding.

mcam (mcam-u) wrote :

Thanks cbhaley and kovid. {:'format_date(raw_field('pubdate'),'yyyy')'} works fine.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers