question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong year in format_date for date in first week of year

See original GitHub issue

How to duplicate:

$ python
Python 2.7.11+ (default, Apr 17 2016, 14:00:29) 
[GCC 5.3.1 20160413] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import date, datetime, time
>>> from babel.dates import format_date, format_datetime, format_time
>>> d = date(2016, 1, 2)
>>> format_date(d, format= 'd. MMMM YYYY',locale='en')
u'2. January 2016'
>>> format_date(d, format= 'd. MMMM YYYY',locale='de_DE')
u'2. Januar 2015'
>>> 

Package python-flask-babel 0.9-2.1 in Ubuntu 16.04 (older version are affected too)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
jun66j5commented, Jun 17, 2016

Not a bug. Try yyyy (lower case) instead of YYYY.

According to http://babel.pocoo.org/en/latest/dates.html#date-fields:

  • y: Replaced by the year. Normally the length specifies the padding, but for two letters it also specifies the maximum length.
  • Y: Same as y but uses the ISO year-week calendar.

See also https://en.wikipedia.org/wiki/ISO_week_date.

>>> import babel
>>> from babel.dates import format_date
>>> from datetime import datetime
>>> babel.__version__
'2.2.0'
>>> t = datetime(2016, 1, 2)
>>> format_date(t, 'd. MMMM yyyy', locale='en_US')
u'2. January 2016'
>>> format_date(t, 'd. MMMM yyyy', locale='de_DE')
u'2. Januar 2016'
>>> format_date(t, 'YYYY-ww', locale='en_US')
u'2016-01'
>>> format_date(t, 'YYYY-ww', locale='de_DE')
u'2015-53'
0reactions
akxcommented, Nov 21, 2016

The documentation was improved by @ldwoolley in #450, so closing. Thanks 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does formatting a date return the wrong year?
i18n dates are formatted using IntlDateFormatter , which use ISO date format patterns, where YYYY doesn't just mean Full year, but Full week- ......
Read more >
Format or DatePar functions return a wrong week number for a ...
For more information and a workaround, see Format or DatePart functions can return wrong week number for last Monday in Year.
Read more >
6 Ways to Fix Dates Formatted as Text in Excel
Step 3 of the Wizard: Choose 'Date' from the 'Column Data Format' options and choose your date format from the drop down list...
Read more >
Custom Date Formats - Tableau Help
Display the date as a complete date (including day, month, and year), formatted according to your system's short date format setting. The default...
Read more >
How to change Excel date format and create custom formatting
The first part of our tutorial focuses of formatting dates in Excel ... you want to convert an American date format (month/day/year) to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found