This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch wicket-7.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/wicket-7.x by this push:
new c998275 [WICKET-6781] time zone is determined on client side
c998275 is described below
commit c998275b103f9ea7e1c092f130523204659cf9d4
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Tue May 5 23:54:19 2020 +0700
[WICKET-6781] time zone is determined on client side
---
.../markup/html/pages/wicket-browser-info.js | 5 ++
.../wicket/protocol/http/ClientProperties.java | 66 ++++++++++++++--------
.../wicket/protocol/http/ClientPropertiesTest.java | 32 ++++++++++-
3 files changed, 78 insertions(+), 25 deletions(-)
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 cd0da94..10b0bcc 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
@@ -58,6 +58,11 @@
info.screenHeight =
window.screen.height;
info.screenColorDepth =
window.screen.colorDepth;
}
+ if (Intl && typeof(Intl.DateTimeFormat) ===
'function' &&
+
typeof(Intl.DateTimeFormat().resolvedOptions) === 'function') {
+ 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);
info.browserWidth = window.innerWidth ||
document.body.offsetWidth;
diff --git
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
index d172460..ebb291b 100644
---
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
+++
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/ClientProperties.java
@@ -38,17 +38,17 @@ import org.apache.wicket.util.string.AppendingStringBuffer;
* <p>
* A convenient way of letting Wicket do a sneaky redirect to {@link
BrowserInfoPage} (and back
* again) is to put this in your Application's init method:
- *
+ *
* <pre>
* getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
* </pre>
- *
+ *
* </p>
- *
+ *
* WARNING: Be sure you think about the dangers of depending on information
you pull from the client
* too much. They may be easily spoofed or inaccurate in other ways, and
properties like window and
* browser size are all too easy to be used naively.
- *
+ *
* @see BrowserInfoPage
* @author Frank Bille (frankbille)
*/
@@ -82,6 +82,7 @@ public class ClientProperties implements IClusterable
private int screenWidth = -1;
private String utcDSTOffset;
private String utcOffset;
+ private String jsTimeZone;
private String hostname;
private boolean javaScriptEnabled;
@@ -211,11 +212,19 @@ public class ClientProperties implements IClusterable
/**
* Get the client's time zone if that could be detected.
- *
+ *
* @return The client's time zone
*/
public TimeZone getTimeZone()
{
+ if (timeZone == null && jsTimeZone != null)
+ {
+ TimeZone temptimeZone =
TimeZone.getTimeZone(jsTimeZone);
+ if (jsTimeZone.equals(temptimeZone.getID()))
+ {
+ timeZone = temptimeZone;
+ }
+ }
if (timeZone == null)
{
String utc = getUtcOffset();
@@ -357,7 +366,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating support of JavaScript in the browser.
- *
+ *
* @return True if JavaScript is enabled
*/
public boolean isJavaScriptEnabled() {
@@ -367,7 +376,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Microsoft
Internet Explorer browser
* platform.
- *
+ *
* @return True if a derivative of the Microsoft Internet Explorer
browser platform.
*/
public boolean isBrowserInternetExplorer()
@@ -377,7 +386,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the KDE
Konqueror browser platform.
- *
+ *
* @return True if a derivative of the KDE Konqueror browser platform.
*/
public boolean isBrowserKonqueror()
@@ -387,7 +396,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Mozilla
1.0-1.8+ browser platform.
- *
+ *
* @return True if a derivative of the Mozilla 1.0-1.8+ browser
platform.
*/
public boolean isBrowserMozilla()
@@ -398,7 +407,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Mozilla
Firefox 1.0+ browser
* platform.
- *
+ *
* @return True if a derivative of the Mozilla Firefox 1.0+ browser
platform.
*/
public boolean isBrowserMozillaFirefox()
@@ -408,7 +417,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Opera
browser platform.
- *
+ *
* @return True if a derivative of the Opera browser platform.
*/
public boolean isBrowserOpera()
@@ -418,7 +427,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Apple Safari
browser platform.
- *
+ *
* @return True if a derivative of the Apple Safari browser platform.
*/
public boolean isBrowserSafari()
@@ -428,7 +437,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Chrome
browser platform.
- *
+ *
* @return True if a derivative of the Chrome browser platform.
*/
public boolean isBrowserChrome()
@@ -462,8 +471,8 @@ public class ClientProperties implements IClusterable
}
/**
- *
- *
+ *
+ *
* @return The client's navigator.cookieEnabled property.
*/
public boolean isNavigatorCookieEnabled()
@@ -496,7 +505,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Microsoft
Internet Explorer browser
* platform.
- *
+ *
* @param browserInternetExplorer
* True if a derivative of the Microsoft Internet Explorer
browser platform.
*/
@@ -507,7 +516,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the KDE
Konqueror browser platform.
- *
+ *
* @param browserKonqueror
* True if a derivative of the KDE Konqueror browser
platform.
*/
@@ -518,7 +527,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Mozilla
1.0-1.8+ browser platform.
- *
+ *
* @param browserMozilla
* True if a derivative of the Mozilla 1.0-1.8+ browser
platform.
*/
@@ -530,7 +539,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Mozilla
Firefox 1.0+ browser
* platform.
- *
+ *
* @param browserMozillaFirefox
* True if a derivative of the Mozilla Firefox 1.0+ browser
platform.
*/
@@ -541,7 +550,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Opera
browser platform.
- *
+ *
* @param browserOpera
* True if a derivative of the Opera browser platform.
*/
@@ -552,7 +561,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Apple Safari
browser platform.
- *
+ *
* @param browserSafari
* True if a derivative of the Apple Safari browser platform.
*/
@@ -563,7 +572,7 @@ public class ClientProperties implements IClusterable
/**
* Flag indicating that the browser is a derivative of the Chrome
browser platform.
- *
+ *
* @param browserChrome
* True if a derivative of the Chrome browser platform.
*/
@@ -728,7 +737,7 @@ public class ClientProperties implements IClusterable
/**
* Sets time zone.
- *
+ *
* @param timeZone
*/
public void setTimeZone(TimeZone timeZone)
@@ -755,6 +764,14 @@ public class ClientProperties implements IClusterable
}
/**
+ * @param jsTimeZone
+ */
+ public void setJsTimeZone(String jsTimeZone)
+ {
+ this.jsTimeZone = jsTimeZone;
+ }
+
+ /**
* @param javaScriptEnabled
* is JavaScript supported in the browser
*/
@@ -821,7 +838,7 @@ public class ClientProperties implements IClusterable
/**
* Read parameters.
- *
+ *
* @param parameters
* parameters sent from browser
*/
@@ -840,6 +857,7 @@ public class ClientProperties implements IClusterable
setScreenColorDepth(parameters.getParameterValue("screenColorDepth").toInt(-1));
setUtcOffset(parameters.getParameterValue("utcOffset").toString(null));
setUtcDSTOffset(parameters.getParameterValue("utcDSTOffset").toString(null));
+
setJsTimeZone(parameters.getParameterValue("jsTimeZone").toString(null));
setBrowserWidth(parameters.getParameterValue("browserWidth").toInt(-1));
setBrowserHeight(parameters.getParameterValue("browserHeight").toInt(-1));
setHostname(parameters.getParameterValue("hostname").toString("N/A"));
diff --git
a/wicket-core/src/test/java/org/apache/wicket/protocol/http/ClientPropertiesTest.java
b/wicket-core/src/test/java/org/apache/wicket/protocol/http/ClientPropertiesTest.java
index ddff8ee..036ff3b 100644
---
a/wicket-core/src/test/java/org/apache/wicket/protocol/http/ClientPropertiesTest.java
+++
b/wicket-core/src/test/java/org/apache/wicket/protocol/http/ClientPropertiesTest.java
@@ -23,7 +23,7 @@ import org.junit.Test;
/**
* Tests for ClientProperties that failed on Mac OS X Java platform.
- *
+ *
* @author Martijn Dashorst
*/
public class ClientPropertiesTest extends Assert
@@ -146,4 +146,34 @@ public class ClientPropertiesTest extends Assert
assertEquals(TimeZone.getTimeZone("AET"), props.getTimeZone());
}
+
+ /**
+ * WICKET-6781
+ *
+ * jsTimeZone "positive" test
+ */
+ @Test
+ public void timezoneJsPositive()
+ {
+ ClientProperties props = new ClientProperties();
+ props.setJsTimeZone("Asia/Novosibirsk");
+
+ assertEquals(TimeZone.getTimeZone("Asia/Novosibirsk"),
props.getTimeZone());
+ }
+
+ /**
+ * WICKET-6781
+ *
+ * jsTimeZone "negative" test
+ */
+ @Test
+ public void timezoneJsNegative()
+ {
+ ClientProperties props = new ClientProperties();
+ props.setUtcOffset("11");
+ props.setUtcDSTOffset("10");
+ props.setJsTimeZone("aaa");
+
+ assertEquals(TimeZone.getTimeZone("AET"), props.getTimeZone());
+ }
}