From ab2d34ba3fe95d0324d544ca2ca92c2bf0b533aa Mon Sep 17 00:00:00 2001 From: akoskaaa Date: Sun, 3 Apr 2016 18:53:11 +0200 Subject: [PATCH] Fixed #25856 -- Added %B support to Date.strftime. This enables the admin to display the correct localized month name if %B is used in the date format. --- django/contrib/admin/static/admin/js/calendar.js | 1 + django/contrib/admin/static/admin/js/core.js | 7 +++++++ js_tests/admin/core.test.js | 1 + 3 files changed, 9 insertions(+) diff --git a/django/contrib/admin/static/admin/js/calendar.js b/django/contrib/admin/static/admin/js/calendar.js index 8432ebd1bf..57655602ee 100644 --- a/django/contrib/admin/static/admin/js/calendar.js +++ b/django/contrib/admin/static/admin/js/calendar.js @@ -204,4 +204,5 @@ depends on core.js for utility functions like removeChildren or quickElement } }; window.Calendar = Calendar; + window.CalendarNamespace = CalendarNamespace; })(); diff --git a/django/contrib/admin/static/admin/js/core.js b/django/contrib/admin/static/admin/js/core.js index a5164ccd47..edccdc0217 100644 --- a/django/contrib/admin/static/admin/js/core.js +++ b/django/contrib/admin/static/admin/js/core.js @@ -153,8 +153,15 @@ function findPosY(obj) { return this.getTwoDigitHour() + ':' + this.getTwoDigitMinute() + ':' + this.getTwoDigitSecond(); }; + Date.prototype.getFullMonthName = function() { + return typeof window.CalendarNamespace === "undefined" + ? this.getTwoDigitMonth() + : window.CalendarNamespace.monthsOfYear[this.getMonth()]; + }; + Date.prototype.strftime = function(format) { var fields = { + B: this.getFullMonthName(), c: this.toString(), d: this.getTwoDigitDate(), H: this.getTwoDigitHour(), diff --git a/js_tests/admin/core.test.js b/js_tests/admin/core.test.js index 43fb27a7af..7f0a4d6fda 100644 --- a/js_tests/admin/core.test.js +++ b/js_tests/admin/core.test.js @@ -54,6 +54,7 @@ test('Date.getHourMinuteSecond', function(assert) { test('Date.strftime', function(assert) { var date = new Date(2014, 6, 1, 11, 0, 5); assert.equal(date.strftime('%Y-%m-%d %H:%M:%S'), '2014-07-01 11:00:05'); + assert.equal(date.strftime('%B %d, %Y'), 'July 01, 2014'); }); test('String.strptime', function(assert) {