From fbc7598a6bd238cc1ccd892dbf8e446f78fdfb0d Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Thu, 15 Nov 2018 09:17:42 +0100 Subject: [PATCH] JS: Simplify Date.getStdTimezoneOffset() refs #3607 --- public/js/icinga/timezone.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/public/js/icinga/timezone.js b/public/js/icinga/timezone.js index 7e695248f..3c0fb090a 100644 --- a/public/js/icinga/timezone.js +++ b/public/js/icinga/timezone.js @@ -10,25 +10,11 @@ * @returns {Number} */ Date.prototype.getStdTimezoneOffset = function() { - if (Date.maxTimezoneOffset !== undefined) { - return Date.maxTimezoneOffset; - } - var year = new Date().getFullYear(); - var previousOffset; + var offsetInJanuary = new Date(year, 0, 2).getTimezoneOffset(); + var offsetInJune = new Date(year, 5, 2).getTimezoneOffset(); - for (var i=0; i<12; i++) { - var d = new Date(year, i, 1); - if (previousOffset !== undefined) { - previousOffset = Math.max(previousOffset, d.getTimezoneOffset()); - } else { - previousOffset = d.getTimezoneOffset(); - } - } - - Date.maxTimezoneOffset = previousOffset; - - return Date.maxTimezoneOffset; + return Math.max(offsetInJanuary, offsetInJune); }; /**