This is an automated email from the ASF dual-hosted git repository.

bitstorm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/wicket.git


The following commit(s) were added to refs/heads/master by this push:
     new 57f00f599a Fix Southern Hemisphere DST detection in browser info 
(#1975)
57f00f599a is described below

commit 57f00f599ae5d09f32fc908bcc438f1db22bb76f
Author: Poojana Kaveesh Sellahewa <[email protected]>
AuthorDate: Sun Nov 22 01:31:49 2026 +0530

    Fix Southern Hemisphere DST detection in browser info (#1975)
---
 testing/wicket-js-tests/Gruntfile.js               |  3 +-
 .../markup/html/pages/wicket-browser-info.js       |  8 ++-
 wicket-core/src/test/js/all.html                   |  2 +
 wicket-core/src/test/js/browser-info.js            | 73 ++++++++++++++++++++++
 4 files changed, 83 insertions(+), 3 deletions(-)

diff --git a/testing/wicket-js-tests/Gruntfile.js 
b/testing/wicket-js-tests/Gruntfile.js
index a921235bd4..04ae85f792 100644
--- a/testing/wicket-js-tests/Gruntfile.js
+++ b/testing/wicket-js-tests/Gruntfile.js
@@ -65,7 +65,8 @@ module.exports = function(grunt) {
                        "../../wicket-core/src/test/js/timer.js",
                        "../../wicket-core/src/test/js/trusted-types.js",
                        "../../wicket-core/src/test/js/trusted-types-off.js",
-                       "../../wicket-core/src/test/js/upload-to-resource.js"
+                       "../../wicket-core/src/test/js/upload-to-resource.js",
+                       "../../wicket-core/src/test/js/browser-info.js"
                ],
                extensionsTestsJs = [
                        "../../wicket-extensions/src/test/js/palette-test.js",
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
index 10b0bccfc5..ad69d7f579 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
+++ 
b/wicket-core/src/main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js
@@ -63,8 +63,12 @@
                                        var jsTimeZone = 
Intl.DateTimeFormat().resolvedOptions().timeZone;
                                        info.jsTimeZone = jsTimeZone ? 
jsTimeZone : null;
                                }
-                               info.utcOffset = (new Date(new 
Date().getFullYear(), 0, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
-                               info.utcDSTOffset = (new Date(new 
Date().getFullYear(), 6, 1, 0, 0, 0, 0).getTimezoneOffset() / -60);
+                               // Standard time has the smaller UTC offset, 
regardless of hemisphere.
+                               var year = new Date().getFullYear();
+                               var januaryOffset = new Date(year, 0, 
1).getTimezoneOffset() / -60;
+                               var julyOffset = new Date(year, 6, 
1).getTimezoneOffset() / -60;
+                               info.utcOffset = Math.min(januaryOffset, 
julyOffset);
+                               info.utcDSTOffset = Math.max(januaryOffset, 
julyOffset);
                                info.browserWidth =  window.innerWidth || 
document.body.offsetWidth;
                                info.browserHeight =  window.innerHeight || 
document.body.offsetHeight;
                                info.hostname =  window.location.hostname;
diff --git a/wicket-core/src/test/js/all.html b/wicket-core/src/test/js/all.html
index ef2f3ab0e1..9955a7d708 100644
--- a/wicket-core/src/test/js/all.html
+++ b/wicket-core/src/test/js/all.html
@@ -188,6 +188,7 @@
                }
        </script>
        <script type="text/javascript" 
src="../../main/java/org/apache/wicket/markup/html/form/upload/resource/FileUploadToResourceField.js"></script>
+       <script type="text/javascript" 
src="../../main/java/org/apache/wicket/markup/html/pages/wicket-browser-info.js"></script>
        <script type="text/javascript" src="qunit/qunit.js"></script>
        <script type="text/javascript" src="qunit/blanket.min.js"></script>
 
@@ -204,5 +205,6 @@
        <script type="text/javascript" src="ajax.js"></script>
        <script type="text/javascript" src="timer.js"></script>
        <script type="text/javascript" src="upload-to-resource.js"></script>
+       <script type="text/javascript" src="browser-info.js"></script>
 </body>
 </html>
diff --git a/wicket-core/src/test/js/browser-info.js 
b/wicket-core/src/test/js/browser-info.js
new file mode 100644
index 0000000000..64c6e693ea
--- /dev/null
+++ b/wicket-core/src/test/js/browser-info.js
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*global QUnit: true */
+
+Wicket.Event.add(window, 'domready', function() {
+       "use strict";
+
+       const { module, test } = QUnit;
+
+       module("Wicket.BrowserInfo");
+
+       // Mock timezone offsets for January and July without relying on the 
test machine's TZ.
+       function collectWithOffsets(januaryMinutes, julyMinutes) {
+               var original = Date.prototype.getTimezoneOffset;
+               Date.prototype.getTimezoneOffset = function() {
+                       if (this.getMonth() === 0) {
+                               return januaryMinutes;
+                       }
+                       if (this.getMonth() === 6) {
+                               return julyMinutes;
+                       }
+                       return original.call(this);
+               };
+               try {
+                       return Wicket.BrowserInfo.collect();
+               } finally {
+                       Date.prototype.getTimezoneOffset = original;
+               }
+       }
+
+       test("Northern hemisphere: standard and daylight offsets", assert => {
+               // New York: January UTC-5, July UTC-4.
+               var info = collectWithOffsets(300, 240);
+               assert.strictEqual(info.utcOffset, -5);
+               assert.strictEqual(info.utcDSTOffset, -4);
+       });
+
+       test("Southern hemisphere: January is daylight saving time", assert => {
+               // Sydney: January UTC+11, July UTC+10.
+               var info = collectWithOffsets(-660, -600);
+               assert.strictEqual(info.utcOffset, 10);
+               assert.strictEqual(info.utcDSTOffset, 11);
+       });
+
+       test("No daylight saving time", assert => {
+               // Colombo: UTC+5:30 throughout the year.
+               var info = collectWithOffsets(-330, -330);
+               assert.strictEqual(info.utcOffset, 5.5);
+               assert.strictEqual(info.utcDSTOffset, 5.5);
+       });
+
+       test("Southern hemisphere: half-hour daylight saving time", assert => {
+               // Lord Howe Island: January UTC+11, July UTC+10:30.
+               var info = collectWithOffsets(-660, -630);
+               assert.strictEqual(info.utcOffset, 10.5);
+               assert.strictEqual(info.utcDSTOffset, 11);
+       });
+});

Reply via email to