From: <rb...@us...> - 2013-10-04 09:53:15
|
Revision: 8587 http://sourceforge.net/p/htmlunit/code/8587 Author: rbri Date: 2013-10-04 09:53:10 +0000 (Fri, 04 Oct 2013) Log Message: ----------- Date.toUTCString and Date.toGMTString now returns the correct format in IE mode. Date.toLocaleTimeString fixed in IE8 mode. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeDateTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/changes/changes.xml 2013-10-04 09:53:10 UTC (rev 8587) @@ -8,6 +8,12 @@ <body> <release version="2.13" date="???" description="Bugfixes"> + <action type="fix" dev="rbri"> + Date.toUTCString and Date.toGMTString now returns the correct format in IE mode. + </action> + <action type="fix" dev="rbri"> + Date.toLocaleTimeString fixed in IE8 mode. + </action> <action type="fix" dev="rbri" issue="1524"> Some debug log output added if HTMLDocument.canAlreadyBeParsed(String) returns false. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -769,9 +769,14 @@ JS_CONSTRUCTOR, /** Is Date.toLocaleTimeString() in 24-hour format. */ - @BrowserFeature({ @WebBrowser(CHROME), @WebBrowser(value = FF, minVersion = 17) }) + @BrowserFeature({ @WebBrowser(value = IE, minVersion = 8), @WebBrowser(value = FF, minVersion = 17), + @WebBrowser(CHROME) }) JS_DATE_LOCATE_TIME_24, + /** Is Date.toUTCString() and Date.toGMTString are returning UTC instead of GMT. */ + @BrowserFeature({ @WebBrowser(IE) }) + JS_DATE_USE_UTC, + /** */ @BrowserFeature(@WebBrowser(IE)) JS_DEFERRED, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ALLOW_CONST_ASSIGNMENT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_CONSTRUCTOR; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DATE_USE_UTC; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DEFINE_GETTER; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DONT_ENUM_FUNCTIONS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ECMA5_FUNCTIONS; @@ -331,6 +332,12 @@ final ScriptableObject datePrototype = (ScriptableObject) ScriptableObject.getClassPrototype(window, "Date"); datePrototype.defineFunctionProperties(new String[] {"toLocaleDateString", "toLocaleTimeString"}, DateCustom.class, ScriptableObject.DONTENUM); + + if (browserVersion.hasFeature(JS_DATE_USE_UTC)) { + datePrototype.defineFunctionProperties(new String[] {"toUTCString"}, + DateCustom.class, ScriptableObject.DONTENUM); + } + window.setPrototypes(prototypes); window.initialize(webWindow); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/DateCustom.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -21,11 +21,14 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.util.TimeZone; import net.sourceforge.htmlunit.corejs.javascript.Context; import net.sourceforge.htmlunit.corejs.javascript.Function; import net.sourceforge.htmlunit.corejs.javascript.Scriptable; +import org.apache.commons.lang3.time.DateFormatUtils; + import com.gargoylesoftware.htmlunit.BrowserVersion; /** @@ -33,9 +36,12 @@ * * @version $Revision$ * @author Ahmed Ashour + * @author Ronald Brill */ public final class DateCustom { + private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone("UTC"); + private DateCustom() { } private static Field DATE_FIELD_; @@ -76,6 +82,20 @@ return format.format(new Date(getDateValue(thisObj))); } + /** + * Converts a date to a UTC string. Special version for IE + * @param context the JavaScript context + * @param thisObj the scriptable + * @param args the arguments passed into the method + * @param function the function + * @return converted string + */ + public static String toUTCString( + final Context context, final Scriptable thisObj, final Object[] args, final Function function) { + final Date date = new Date(getDateValue(thisObj)); + return DateFormatUtils.format(date, "EEE, d MMM yyyy HH:mm:ss z", UTC_TIME_ZONE, Locale.ENGLISH); + } + private static long getDateValue(final Scriptable thisObj) { try { if (DATE_FIELD_ == null) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeDateTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeDateTest.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/NativeDateTest.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -155,6 +155,74 @@ * @throws Exception if the test fails */ @Test + @Alerts(DEFAULT = { "2005-12-03T07:14:15.000Z", "2005-07-12T11:04:15.000Z", + "2005-07-03T15:14:05.000Z" }, + IE6 = "", + IE8 = "") + public void toISOString() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " if (new Date().toISOString) {\n" + + " alert(new Date(2005, 11, 3, 8, 14, 15).toISOString());\n" + + " alert(new Date(2005, 6, 12, 13, 4, 15).toISOString());\n" + + " alert(new Date(2005, 6, 3, 17, 14, 5).toISOString());\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "Sat, 03 Dec 2005 07:14:15 GMT", "Tue, 12 Jul 2005 11:04:15 GMT", + "Sun, 03 Jul 2005 15:14:05 GMT" }, + IE = { "Sat, 3 Dec 2005 07:14:15 UTC", "Tue, 12 Jul 2005 11:04:15 UTC", + "Sun, 3 Jul 2005 15:14:05 UTC" }) + public void toUTCString() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " alert(new Date(2005, 11, 3, 8, 14, 15).toUTCString());\n" + + " alert(new Date(2005, 6, 12, 13, 4, 15).toUTCString());\n" + + " alert(new Date(2005, 6, 3, 17, 14, 5).toUTCString());\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = { "Sat, 03 Dec 2005 07:14:15 GMT", "Tue, 12 Jul 2005 11:04:15 GMT", + "Sun, 03 Jul 2005 15:14:05 GMT" }, + IE = { "Sat, 3 Dec 2005 07:14:15 UTC", "Tue, 12 Jul 2005 11:04:15 UTC", + "Sun, 3 Jul 2005 15:14:05 UTC" }) + public void toGMTString() throws Exception { + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " alert(new Date(2005, 11, 3, 8, 14, 15).toGMTString());\n" + + " alert(new Date(2005, 6, 12, 13, 4, 15).toGMTString());\n" + + " alert(new Date(2005, 6, 3, 17, 14, 5).toGMTString());\n" + + "}\n" + + "</script></head><body onload='test()'>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if the test fails + */ + @Test public void enumerable() throws Exception { final String html = "<html><head><title>foo</title><script>\n" @@ -174,15 +242,20 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "12:00:00 AM", - CHROME = "00:00:00", - FF17 = "00:00:00", - IE10 = "00:00:00") + @Alerts(DEFAULT = { "00:00:00", "07:08:09" }, + FF3_6 = { "12:00:00 AM", "07:08:09 AM" }, + FF10 = { "12:00:00 AM", "07:08:09 AM" }, + IE6 = { "12:00:00 AM", "07:08:09 AM" }) public void toLocaleTimeString() throws Exception { final String html = "<html><head><title>foo</title><script>\n" + "function test() {\n" + " alert(new Date(2000, 0, 1).toLocaleTimeString());\n" + + " var date = new Date(2013, 0, 1);\n" + + " date.setHours(7);\n" + + " date.setMinutes(8);\n" + + " date.setSeconds(9);\n" + + " alert(date.toLocaleTimeString());\n" + "}\n" + "</script></head><body onload='test()'>\n" + "</body></html>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-10-03 08:49:18 UTC (rev 8586) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-10-04 09:53:10 UTC (rev 8587) @@ -597,7 +597,8 @@ * @throws Exception if the test fails */ @Test - @Alerts({ "string", "Fri, 16 Oct 2009 13:59:47 GMT" }) + @Alerts(DEFAULT = { "string", "Fri, 16 Oct 2009 13:59:47 GMT" }, + IE = { "string", "Fri, 16 Oct 2009 13:59:47 UTC" }) public void lastModified() throws Exception { final List<NameValuePair> responseHeaders = new ArrayList<NameValuePair>(); responseHeaders.add(new NameValuePair("Last-Modified", "Fri, 16 Oct 2009 13:59:47 GMT")); |