From: <rb...@us...> - 2017-05-26 18:18:00
|
Revision: 14476 http://sourceforge.net/p/htmlunit/code/14476 Author: rbri Date: 2017-05-26 18:17:57 +0000 (Fri, 26 May 2017) Log Message: ----------- simulated system time zone is now configurable Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2017-05-25 18:12:48 UTC (rev 14475) +++ trunk/htmlunit/src/changes/changes.xml 2017-05-26 18:17:57 UTC (rev 14476) @@ -8,6 +8,9 @@ <body> <release version="2.27" date="???" description="GAE broken, FF52, Bugfixes"> + <action type="fix" dev="rbri" issue="1827"> + Simulated system time zone is now configurable (BrowserVersion.setSystemTimezone(String)). + </action> <action type="fix" dev="asashour" issue="1886"> JavaScript: fix Set/Map with undefined value. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-05-25 18:12:48 UTC (rev 14475) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersion.java 2017-05-26 18:17:57 UTC (rev 14476) @@ -107,6 +107,11 @@ private static final String LANGUAGE_ENGLISH_US = "en-US"; /** + * United States . + */ + private static final String TIMEZONE_NEW_YORK = "America/New_York"; + + /** * The X86 CPU class. */ private static final String CPU_CLASS_X86 = "x86"; @@ -349,6 +354,7 @@ private boolean onLine_ = true; private String platform_ = PLATFORM_WIN32; private String systemLanguage_ = LANGUAGE_ENGLISH_US; + private String systemTimezone_ = TIMEZONE_NEW_YORK; private String userAgent_; private String userLanguage_ = LANGUAGE_ENGLISH_US; private int browserVersionNumeric_; @@ -614,6 +620,15 @@ } /** + * Returns the system timezone, for example "America/New_York". + * Default value is {@link #TIMEZONE_NEW_YORK} if not explicitly configured. + * @return the system timezone + */ + public String getSystemTimezone() { + return systemTimezone_; + } + + /** * Returns the user agent string, for example "Mozilla/4.0 (compatible; MSIE 6.0b; Windows 98)". * @return the user agent string */ @@ -746,6 +761,13 @@ } /** + * @param systemTimezone the systemTimezone to set + */ + public void setSystemTimezone(final String systemTimezone) { + systemTimezone_ = systemTimezone; + } + + /** * @param userAgent the userAgent to set */ public void setUserAgent(final String userAgent) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java 2017-05-25 18:12:48 UTC (rev 14475) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/file/File.java 2017-05-26 18:17:57 UTC (rev 14476) @@ -23,6 +23,7 @@ import java.util.Date; import java.util.Locale; +import java.util.TimeZone; import org.apache.commons.lang3.time.FastDateFormat; @@ -73,13 +74,14 @@ final Date date = new Date(getLastModified()); final BrowserVersion browser = getBrowserVersion(); final Locale locale = new Locale(browser.getSystemLanguage()); + final TimeZone timezone = TimeZone.getTimeZone(browser.getSystemTimezone()); if (browser.hasFeature(JS_FILE_SHORT_DATE_FORMAT)) { - final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT_FF, locale); + final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT_FF, timezone, locale); return format.format(date); } - final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT, locale); + final FastDateFormat format = FastDateFormat.getInstance(LAST_MODIFIED_DATE_FORMAT, timezone, locale); return format.format(date); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileTest.java 2017-05-25 18:12:48 UTC (rev 14475) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/file/FileTest.java 2017-05-26 18:17:57 UTC (rev 14476) @@ -42,14 +42,14 @@ */ @Test @Alerts(CHROME = {"1", "ScriptExceptionTest1.txt", - "Sun Jul 26 2015 16:21:47 GMT+0200 (Central European Summer Time)", + "Sun Jul 26 2015 10:21:47 GMT-0400 (Eastern Daylight Time)", "1437920507000", "", "14", "text/plain"}, - FF45 = {"1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 16:21:47 GMT+0200", + FF45 = {"1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 10:21:47 GMT-0400", "1437920507000", "undefined", "14", "text/plain"}, - FF52 = {"1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 16:21:47 GMT+0200", + FF52 = {"1", "ScriptExceptionTest1.txt", "Sun Jul 26 2015 10:21:47 GMT-0400", "1437920507000", "", "14", "text/plain"}, IE = {"1", "ScriptExceptionTest1.txt", - "Sun Jul 26 2015 16:21:47 GMT+0200 (Central European Summer Time)", + "Sun Jul 26 2015 10:21:47 GMT-0400 (Eastern Daylight Time)", "undefined", "undefined", "14", "text/plain"}) public void properties() throws Exception { final String html |