From 9af40f5df13801ffadcc5ded7440e4616123959f Mon Sep 17 00:00:00 2001 From: Sven Grunewaldt Date: Wed, 16 Dec 2015 15:11:00 +0100 Subject: [PATCH] Fixed #25845 -- Fixed incorrect timezone warnings in custom admin templates. --- .../contrib/admin/static/admin/js/admin/DateTimeShortcuts.js | 4 ++-- docs/releases/1.9.1.txt | 4 ++++ js_tests/admin/DateTimeShortcuts.test.js | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js index fd7243ed95..43bbfcaf09 100644 --- a/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js +++ b/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js @@ -21,7 +21,7 @@ init: function() { var body = document.getElementsByTagName('body')[0]; var serverOffset = body.getAttribute('data-admin-utc-offset'); - if (serverOffset !== undefined) { + if (serverOffset) { var localOffset = new Date().getTimezoneOffset() * -60; DateTimeShortcuts.timezoneOffset = localOffset - serverOffset; } @@ -43,7 +43,7 @@ now: function() { var body = document.getElementsByTagName('body')[0]; var serverOffset = body.getAttribute('data-admin-utc-offset'); - if (serverOffset !== undefined) { + if (serverOffset) { var localNow = new Date(); var localOffset = localNow.getTimezoneOffset() * -60; localNow.setTime(localNow.getTime() + 1000 * (serverOffset - localOffset)); diff --git a/docs/releases/1.9.1.txt b/docs/releases/1.9.1.txt index 20fd723d2b..2e1aa7cbb1 100644 --- a/docs/releases/1.9.1.txt +++ b/docs/releases/1.9.1.txt @@ -46,3 +46,7 @@ Bugfixes * Fixed ``TypedChoiceField`` change detection with nullable fields (:ticket:`25942`). + +* Fixed incorrect timezone warnings in custom admin templates that don't have + a ``data-admin-utc-offset`` attribute in the ``body`` tag. + (:ticket:`25845`). diff --git a/js_tests/admin/DateTimeShortcuts.test.js b/js_tests/admin/DateTimeShortcuts.test.js index 2fc9d9a8c6..e993090233 100644 --- a/js_tests/admin/DateTimeShortcuts.test.js +++ b/js_tests/admin/DateTimeShortcuts.test.js @@ -16,4 +16,8 @@ test('init', function(assert) { assert.equal(shortcuts.length, 1); assert.equal(shortcuts.find('a:first').text(), 'Today'); assert.equal(shortcuts.find('a:last .date-icon').length, 1); + + // To prevent incorrect timezone warnings on date/time widgets, timezoneOffset + // should be 0 when a timezone offset isn't set in the HTML body attribute. + assert.equal(DateTimeShortcuts.timezoneOffset, 0); });