View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript;
16  
17  import java.util.TimeZone;
18  
19  import org.htmlunit.BrowserVersion;
20  import org.htmlunit.WebDriverTestCase;
21  import org.htmlunit.junit.annotation.Alerts;
22  import org.htmlunit.junit.annotation.BuggyWebDriver;
23  import org.htmlunit.junit.annotation.HtmlUnitNYI;
24  import org.junit.jupiter.api.Test;
25  
26  /**
27   * Test for the Date support.
28   *
29   * @author Ronald Brill
30   */
31  public class NativeDate2Test extends WebDriverTestCase {
32  
33      /**
34       * @throws Exception if the test fails
35       */
36      @Test
37      @Alerts("2021-12-18T22:23:00.000Z")
38      public void ctorDateTimeStringGMT() throws Exception {
39          ctorDateTimeString("new Date('2021-12-18T22:23:00.000+00:00').toISOString()");
40      }
41  
42      /**
43       * @throws Exception if the test fails
44       */
45      @Test
46      @Alerts("2021-12-18T22:23:00.000Z")
47      public void ctorDateTimeStringGMT2() throws Exception {
48          ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 GMT').toISOString()");
49      }
50  
51      /**
52       * @throws Exception if the test fails
53       */
54      @Test
55      @Alerts("2021-12-18T22:23:00.000Z")
56      public void ctorDateTimeStringUTC() throws Exception {
57          ctorDateTimeString("new Date('2021-12-18T22:23:00.000+00:00').toISOString()");
58      }
59  
60      /**
61       * @throws Exception if the test fails
62       */
63      @Test
64      @Alerts("2021-12-18T22:23:00.000Z")
65      public void ctorDateTimeStringUTC2() throws Exception {
66          ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 UTC').toISOString()");
67      }
68  
69      /**
70       * @throws Exception if the test fails
71       */
72      @Test
73      @Alerts("2021-12-18T22:23:00.000Z")
74      public void ctorDateTimeStringUT() throws Exception {
75          ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 UT').toISOString()");
76      }
77  
78      /**
79       * @throws Exception if the test fails
80       */
81      @Test
82      @Alerts("2021-12-18T12:23:00.000Z")
83      public void ctorDateTimeStringEST() throws Exception {
84          ctorDateTimeString("new Date('2021-12-18T17:23:00.000+05:00').toISOString()");
85      }
86  
87      /**
88       * @throws Exception if the test fails
89       */
90      @Test
91      @Alerts("2021-12-19T03:23:00.000Z")
92      public void ctorDateTimeStringEST2() throws Exception {
93          ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 EST').toISOString()");
94      }
95  
96      /**
97       * @throws Exception if the test fails
98       */
99      @Test
100     @Alerts("2021-12-19T02:23:00.000Z")
101     public void ctorDateTimeStringEDT() throws Exception {
102         ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 EDT').toISOString()");
103     }
104 
105     /**
106      * @throws Exception if the test fails
107      */
108     @Test
109     @Alerts("2021-12-19T04:23:00.000Z")
110     public void ctorDateTimeStringCST() throws Exception {
111         ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 CST').toISOString()");
112     }
113 
114     /**
115      * @throws Exception if the test fails
116      */
117     @Test
118     @Alerts("2021-12-19T03:23:00.000Z")
119     public void ctorDateTimeStringCDT() throws Exception {
120         ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 CDT').toISOString()");
121     }
122 
123     /**
124      * @throws Exception if the test fails
125      */
126     @Test
127     @Alerts("2021-12-19T05:23:00.000Z")
128     public void ctorDateTimeStringMST() throws Exception {
129         ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 MST').toISOString()");
130     }
131 
132     /**
133      * @throws Exception if the test fails
134      */
135     @Test
136     @Alerts("2021-12-19T04:23:00.000Z")
137     public void ctorDateTimeStringMDT() throws Exception {
138         ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 MDT').toISOString()");
139     }
140 
141     /**
142      * @throws Exception if the test fails
143      */
144     @Test
145     @Alerts("2021-12-19T06:23:00.000Z")
146     public void ctorDateTimeStringPST() throws Exception {
147         ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 PST').toISOString()");
148     }
149 
150     /**
151      * @throws Exception if the test fails
152      */
153     @Test
154     @Alerts("2021-12-19T05:23:00.000Z")
155     public void ctorDateTimeStringPDT() throws Exception {
156         ctorDateTimeString("new Date('Sat, 18 Dec 2021 22:23:00 PDT').toISOString()");
157     }
158 
159     /**
160      * @throws Exception if the test fails
161      */
162     @Test
163     @Alerts("2021-12-18T18:23:00.000Z")
164     public void ctorDateTimeStringBerlin() throws Exception {
165         ctorDateTimeString("new Date('2021-12-18T17:23:00.000-01:00').toISOString()");
166     }
167 
168     /**
169      * @throws Exception if the test fails
170      */
171     @Test
172     @Alerts("2021-12-19T02:23:00.000Z")
173     public void ctorDateTimeStringTokyo() throws Exception {
174         ctorDateTimeString("new Date('2021-12-18T17:23:00.000-09:00').toISOString()");
175     }
176 
177     /**
178      * @throws Exception if the test fails
179      */
180     @Test
181     @Alerts("2021-12-19T02:23:00.000Z")
182     public void ctorDateTimeStringJST() throws Exception {
183         ctorDateTimeString("new Date('2021-12-18T17:23:00.000-09:00').toISOString()");
184     }
185 
186     /**
187      * @throws Exception if the test fails
188      */
189     @Test
190     @Alerts("2021-12-18T12:23:00.000Z")
191     public void ctorDateTimeStringNewYork() throws Exception {
192         ctorDateTimeString("new Date('2021-12-18T17:23:00.000+05:00').toISOString()");
193     }
194 
195     private void ctorDateTimeString(final String js) throws Exception {
196         final String html = DOCTYPE_HTML
197             + "<html><body><script>\n"
198             + LOG_TITLE_FUNCTION
199             + "log(" + js + ");\n"
200             + "</script>\n"
201             + "</body></html>";
202 
203         loadPageVerifyTitle2(html);
204     }
205 
206     /**
207      * @throws Exception if the test fails
208      */
209     @Test
210     @Alerts("2021-12-18T22:23:00.000Z")
211     @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z",
212             FF_ESR = "2021-12-18T21:23:00.000Z")
213     public void ctorDateTimeGMT() throws Exception {
214         ctorDateTime("GMT");
215     }
216 
217     /**
218      * @throws Exception if the test fails
219      */
220     @Test
221     @Alerts("2021-12-18T22:23:00.000Z")
222     @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z",
223             FF_ESR = "2021-12-18T21:23:00.000Z")
224     public void ctorDateTimeUTC() throws Exception {
225         ctorDateTime("UTC");
226     }
227 
228     /**
229      * @throws Exception if the test fails
230      */
231     @Test
232     @Alerts("2021-12-19T03:23:00.000Z")
233     @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z",
234             FF_ESR = "2021-12-18T21:23:00.000Z")
235     public void ctorDateTimeEST() throws Exception {
236         ctorDateTime("EST");
237     }
238 
239     /**
240      * @throws Exception if the test fails
241      */
242     @Test
243     @Alerts("2021-12-18T21:23:00.000Z")
244     public void ctorDateTimeBerlin() throws Exception {
245         ctorDateTime("Europe/Berlin");
246     }
247 
248     /**
249      * @throws Exception if the test fails
250      */
251     @Test
252     @Alerts("2021-12-18T13:23:00.000Z")
253     @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z",
254             FF_ESR = "2021-12-18T21:23:00.000Z")
255     public void ctorDateTimeTokyo() throws Exception {
256         ctorDateTime("Asia/Tokyo");
257     }
258 
259     /**
260      * @throws Exception if the test fails
261      */
262     @Test
263     @Alerts("2021-12-18T13:23:00.000Z")
264     @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z",
265             FF_ESR = "2021-12-18T21:23:00.000Z")
266     public void ctorDateTimeJST() throws Exception {
267         ctorDateTime("JST");
268     }
269 
270     /**
271      * @throws Exception if the test fails
272      */
273     @Test
274     @Alerts("2021-12-19T03:23:00.000Z")
275     @BuggyWebDriver(FF = "2021-12-18T21:23:00.000Z",
276             FF_ESR = "2021-12-18T21:23:00.000Z")
277     public void ctorDateTimeNewYork() throws Exception {
278         ctorDateTime("America/New_York");
279     }
280 
281     private void ctorDateTime(final String tz) throws Exception {
282         final String html = DOCTYPE_HTML
283             + "<html><body><script>\n"
284             + LOG_TITLE_FUNCTION
285             + "log(new Date('2021-12-18T22:23').toISOString());\n"
286             + "</script>\n"
287             + "</body></html>";
288 
289         shutDownAll();
290         try {
291             final BrowserVersion.BrowserVersionBuilder builder
292                 = new BrowserVersion.BrowserVersionBuilder(getBrowserVersion());
293             builder.setSystemTimezone(TimeZone.getTimeZone(tz));
294             setBrowserVersion(builder.build());
295 
296             loadPageVerifyTitle2(html);
297         }
298         finally {
299             shutDownAll();
300         }
301     }
302 
303     /**
304      * @throws Exception if the test fails
305      */
306     @Test
307     @Alerts("2021-12-18T00:00:00.000Z")
308     public void ctorDateGMT() throws Exception {
309         ctorDate("GMT");
310     }
311 
312     /**
313      * @throws Exception if the test fails
314      */
315     @Test
316     @Alerts("2021-12-18T00:00:00.000Z")
317     public void ctorDateUTC() throws Exception {
318         ctorDate("UTC");
319     }
320 
321     /**
322      * @throws Exception if the test fails
323      */
324     @Test
325     @Alerts("2021-12-18T00:00:00.000Z")
326     public void ctorDateEST() throws Exception {
327         ctorDate("EST");
328     }
329 
330     /**
331      * @throws Exception if the test fails
332      */
333     @Test
334     @Alerts("2021-12-18T00:00:00.000Z")
335     public void ctorDateBerlin() throws Exception {
336         ctorDate("Europe/Berlin");
337     }
338 
339     /**
340      * @throws Exception if the test fails
341      */
342     @Test
343     @Alerts("2021-12-18T00:00:00.000Z")
344     public void ctorDateNewYork() throws Exception {
345         ctorDate("America/New_York");
346     }
347 
348     /**
349      * @throws Exception if the test fails
350      */
351     @Test
352     @Alerts("2021-12-18T00:00:00.000Z")
353     public void ctorDateTokyo() throws Exception {
354         ctorDate("Asia/Tokyo");
355     }
356 
357     /**
358      * @throws Exception if the test fails
359      */
360     @Test
361     @Alerts("2021-12-18T00:00:00.000Z")
362     public void ctorDateJST() throws Exception {
363         ctorDate("JST");
364     }
365 
366     private void ctorDate(final String tz) throws Exception {
367         final String html = DOCTYPE_HTML
368             + "<html><body><script>\n"
369             + LOG_TITLE_FUNCTION
370             + "log(new Date('2021-12-18').toISOString());\n"
371             + "</script>\n"
372             + "</body></html>";
373 
374         shutDownAll();
375         try {
376             final BrowserVersion.BrowserVersionBuilder builder
377                 = new BrowserVersion.BrowserVersionBuilder(getBrowserVersion());
378             builder.setSystemTimezone(TimeZone.getTimeZone(tz));
379             setBrowserVersion(builder.build());
380 
381             loadPageVerifyTitle2(html);
382         }
383         finally {
384             shutDownAll();
385         }
386     }
387 
388     /**
389      * @throws Exception if the test fails
390      */
391     @Test
392     @Alerts("2000-02-28T23:59:59.000Z")
393     public void ctorInt() throws Exception {
394         final String html = DOCTYPE_HTML
395             + "<html><body><script>\n"
396             + LOG_TITLE_FUNCTION
397             + "log(new Date(951782399000).toISOString());\n"
398             + "</script>\n"
399             + "</body></html>";
400 
401         loadPageVerifyTitle2(html);
402     }
403 
404     /**
405      * @throws Exception if the test fails
406      */
407     @Test
408     @Alerts("2035-11-30T01:46:40.000Z")
409     public void ctorDouble() throws Exception {
410         final String html = DOCTYPE_HTML
411             + "<html><body><script>\n"
412             + LOG_TITLE_FUNCTION
413             + "log(new Date(208e10).toISOString());\n"
414             + "</script>\n"
415             + "</body></html>";
416 
417         loadPageVerifyTitle2(html);
418     }
419 
420     /**
421      * @throws Exception if the test fails
422      */
423     @Test
424     @Alerts("12/18/2021, 10:23:00 PM")
425     @HtmlUnitNYI(CHROME = "12/18/21, 10:23 PM",
426             EDGE = "12/18/21, 10:23 PM",
427             FF = "12/18/21, 10:23 PM",
428             FF_ESR = "12/18/21, 10:23 PM")
429     public void toLocaleEnUs() throws Exception {
430         toLocale("new Date('2021-12-18T22:23').toLocaleString('en-US')");
431     }
432 
433     /**
434      * @throws Exception if the test fails
435      */
436     @Test
437     @Alerts("12/18/2021")
438     @HtmlUnitNYI(CHROME = "12/18/21",
439             EDGE = "12/18/21",
440             FF = "12/18/21",
441             FF_ESR = "12/18/21")
442     public void toLocaleEnUsDate() throws Exception {
443         toLocale("new Date('2021-12-18T22:23').toLocaleDateString('en-US')");
444     }
445 
446     /**
447      * @throws Exception if the test fails
448      */
449     @Test
450     @Alerts("10:23:00 PM")
451     @HtmlUnitNYI(CHROME = "10:23 PM",
452             EDGE = "10:23 PM",
453             FF = "10:23 PM",
454             FF_ESR = "10:23 PM")
455     public void toLocaleEnUsTime() throws Exception {
456         toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('en-US')");
457     }
458 
459     /**
460      * @throws Exception if the test fails
461      */
462     @Test
463     @Alerts("18.12.2021, 22:23:00")
464     @HtmlUnitNYI(CHROME = "18.12.21, 22:23",
465             EDGE = "18.12.21, 22:23",
466             FF = "18.12.21, 22:23",
467             FF_ESR = "18.12.21, 22:23")
468     public void toLocaleDeDe() throws Exception {
469         toLocale("new Date('2021-12-18T22:23').toLocaleString('de-DE')");
470     }
471 
472     /**
473      * @throws Exception if the test fails
474      */
475     @Test
476     @Alerts("18.12.2021")
477     @HtmlUnitNYI(CHROME = "18.12.21",
478             EDGE = "18.12.21",
479             FF = "18.12.21",
480             FF_ESR = "18.12.21")
481     public void toLocaleDeDeDate() throws Exception {
482         toLocale("new Date('2021-12-18T22:23').toLocaleDateString('de-DE')");
483     }
484 
485     /**
486      * @throws Exception if the test fails
487      */
488     @Test
489     @Alerts("22:23:00")
490     @HtmlUnitNYI(CHROME = "22:23",
491             EDGE = "22:23",
492             FF = "22:23",
493             FF_ESR = "22:23")
494     public void toLocaleDeDeTime() throws Exception {
495         toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('de-DE')");
496     }
497 
498     /**
499      * @throws Exception if the test fails
500      */
501     @Test
502     @Alerts("2021/12/18 22:23:00")
503     @HtmlUnitNYI(CHROME = "2021/12/18 22:23",
504             EDGE = "2021/12/18 22:23",
505             FF = "2021/12/18 22:23",
506             FF_ESR = "2021/12/18 22:23")
507     public void toLocaleJaJp() throws Exception {
508         toLocale("new Date('2021-12-18T22:23').toLocaleString('ja-JP')");
509     }
510 
511     /**
512      * @throws Exception if the test fails
513      */
514     @Test
515     @Alerts("2021/12/18")
516     public void toLocaleJaJpDate() throws Exception {
517         toLocale("new Date('2021-12-18T22:23').toLocaleDateString('ja-JP')");
518     }
519 
520     /**
521      * @throws Exception if the test fails
522      */
523     @Test
524     @Alerts("22:23:00")
525     @HtmlUnitNYI(CHROME = "22:23",
526             EDGE = "22:23",
527             FF = "22:23",
528             FF_ESR = "22:23")
529     public void toLocaleJaJpTime() throws Exception {
530         toLocale("new Date('2021-12-18T22:23').toLocaleTimeString('ja-JP')");
531     }
532 
533     /**
534      * @throws Exception if the test fails
535      */
536     @Test
537     @Alerts("2021/12/18 22:23:00")
538     @HtmlUnitNYI(CHROME = "2021/12/18 22:23",
539             EDGE = "2021/12/18 22:23",
540             FF = "2021/12/18 22:23",
541             FF_ESR = "2021/12/18 22:23")
542     public void toLocaleArray() throws Exception {
543         toLocale("new Date('2021-12-18T22:23').toLocaleString(['foo', 'ja-JP', 'en-US'])");
544     }
545 
546     /**
547      * @throws Exception if the test fails
548      */
549     @Test
550     @Alerts("2021/12/18")
551     public void toLocaleArrayDate() throws Exception {
552         toLocale("new Date('2021-12-18T22:23').toLocaleDateString(['foo', 'ja-JP', 'en-US'])");
553     }
554 
555     /**
556      * @throws Exception if the test fails
557      */
558     @Test
559     @Alerts("22:23:00")
560     @HtmlUnitNYI(CHROME = "22:23",
561             EDGE = "22:23",
562             FF = "22:23",
563             FF_ESR = "22:23")
564     public void toLocaleArrayTime() throws Exception {
565         toLocale("new Date('2021-12-18T22:23').toLocaleTimeString(['foo', 'ja-JP', 'en-US'])");
566     }
567 
568     private void toLocale(final String js) throws Exception {
569         final String html = DOCTYPE_HTML
570             + "<html><body><script>\n"
571             + LOG_TITLE_FUNCTION
572             + "log(" + js + ");\n"
573             + "</script>\n"
574             + "</body></html>";
575 
576         shutDownAll();
577         try {
578             final BrowserVersion.BrowserVersionBuilder builder
579                 = new BrowserVersion.BrowserVersionBuilder(getBrowserVersion());
580             builder.setSystemTimezone(TimeZone.getTimeZone("GMT"));
581             setBrowserVersion(builder.build());
582 
583             loadPageVerifyTitle2(html);
584         }
585         finally {
586             shutDownAll();
587         }
588     }
589 
590     /**
591      * @throws Exception if the test fails
592      */
593     @Test
594     @Alerts("Sat Dec 18 2021")
595     public void toDateStringGMT() throws Exception {
596         toDateString("GMT");
597     }
598 
599     /**
600      * @throws Exception if the test fails
601      */
602     @Test
603     @Alerts("Sat Dec 18 2021")
604     public void toDateStringUTC() throws Exception {
605         toDateString("UTC");
606     }
607 
608     /**
609      * @throws Exception if the test fails
610      */
611     @Test
612     @Alerts("Sat Dec 18 2021")
613     public void toDateStringEST() throws Exception {
614         toDateString("EST");
615     }
616 
617     /**
618      * @throws Exception if the test fails
619      */
620     @Test
621     @Alerts("Sat Dec 18 2021")
622     public void toDateStringBerlin() throws Exception {
623         toDateString("Europe/Berlin");
624     }
625 
626     /**
627      * @throws Exception if the test fails
628      */
629     @Test
630     @Alerts("Sat Dec 18 2021")
631     public void toDateStringNewYork() throws Exception {
632         toDateString("America/New_York");
633     }
634 
635     /**
636      * @throws Exception if the test fails
637      */
638     @Test
639     @Alerts("Sun Dec 19 2021")
640     @BuggyWebDriver(FF = "Sat Dec 18 2021",
641             FF_ESR = "Sat Dec 18 2021")
642     public void toDateStringTokyo() throws Exception {
643         toDateString("Asia/Tokyo");
644     }
645 
646     /**
647      * @throws Exception if the test fails
648      */
649     @Test
650     @Alerts("Sun Dec 19 2021")
651     @BuggyWebDriver(FF = "Sat Dec 18 2021",
652             FF_ESR = "Sat Dec 18 2021")
653     public void toDateStringJST() throws Exception {
654         toDateString("JST");
655     }
656 
657     private void toDateString(final String tz) throws Exception {
658         final String html = DOCTYPE_HTML
659             + "<html><body><script>\n"
660             + LOG_TITLE_FUNCTION
661             + "log(new Date('Sat, 18 Dec 2021 22:23:00 UTC').toDateString());\n"
662             + "</script>\n"
663             + "</body></html>";
664 
665         shutDownAll();
666         try {
667             final BrowserVersion.BrowserVersionBuilder builder
668                 = new BrowserVersion.BrowserVersionBuilder(getBrowserVersion());
669             builder.setSystemTimezone(TimeZone.getTimeZone(tz));
670             setBrowserVersion(builder.build());
671 
672             loadPageVerifyTitle2(html);
673         }
674         finally {
675             shutDownAll();
676         }
677     }
678 
679     /**
680      * @throws Exception if the test fails
681      */
682     @Test
683     @Alerts("22:23:00 GMT+0000 (Greenwich Mean Time)")
684     @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)",
685             FF_ESR = "23:23:00 GMT+0100 (Central European Standard Time)")
686     @HtmlUnitNYI(CHROME = "22:23:00 GMT-0000 (GMT)",
687             EDGE = "22:23:00 GMT-0000 (GMT)",
688             FF = "22:23:00 GMT-0000 (GMT)",
689             FF_ESR = "22:23:00 GMT-0000 (GMT)")
690     public void toTimeStringGMT() throws Exception {
691         toTimeString("GMT");
692     }
693 
694     /**
695      * @throws Exception if the test fails
696      */
697     @Test
698     @Alerts("22:23:00 GMT+0000 (Coordinated Universal Time)")
699     @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)",
700             FF_ESR = "23:23:00 GMT+0100 (Central European Standard Time)")
701     @HtmlUnitNYI(CHROME = "22:23:00 GMT-0000 (UTC)",
702             EDGE = "22:23:00 GMT-0000 (UTC)",
703             FF = "22:23:00 GMT-0000 (UTC)",
704             FF_ESR = "22:23:00 GMT-0000 (UTC)")
705     public void toTimeStringUTC() throws Exception {
706         toTimeString("UTC");
707     }
708 
709     /**
710      * @throws Exception if the test fails
711      */
712     @Test
713     @Alerts("17:23:00 GMT-0500 (Eastern Standard Time)")
714     @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)",
715             FF_ESR = "23:23:00 GMT+0100 (Central European Standard Time)")
716     @HtmlUnitNYI(CHROME = "17:23:00 GMT-0500 (-05:00)",
717             EDGE = "17:23:00 GMT-0500 (-05:00)",
718             FF = "17:23:00 GMT-0500 (-05:00)",
719             FF_ESR = "17:23:00 GMT-0500 (-05:00)")
720     public void toTimeStringEST() throws Exception {
721         toTimeString("EST");
722     }
723 
724     /**
725      * @throws Exception if the test fails
726      */
727     @Test
728     @Alerts("23:23:00 GMT+0100 (Central European Standard Time)")
729     @HtmlUnitNYI(CHROME = "23:23:00 GMT+0100 (CET)",
730             EDGE = "23:23:00 GMT+0100 (CET)",
731             FF = "23:23:00 GMT+0100 (CET)",
732             FF_ESR = "23:23:00 GMT+0100 (CET)")
733     public void toTimeStringBerlin() throws Exception {
734         toTimeString("Europe/Berlin");
735     }
736 
737     /**
738      * @throws Exception if the test fails
739      */
740     @Test
741     @Alerts("17:23:00 GMT-0500 (Eastern Standard Time)")
742     @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)",
743             FF_ESR = "23:23:00 GMT+0100 (Central European Standard Time)")
744     @HtmlUnitNYI(CHROME = "17:23:00 GMT-0500 (EST)",
745             EDGE = "17:23:00 GMT-0500 (EST)",
746             FF = "17:23:00 GMT-0500 (EST)",
747             FF_ESR = "17:23:00 GMT-0500 (EST)")
748     public void toTimeStringNewYork() throws Exception {
749         toTimeString("America/New_York");
750     }
751 
752     /**
753      * @throws Exception if the test fails
754      */
755     @Test
756     @Alerts("07:23:00 GMT+0900 (Japan Standard Time)")
757     @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)",
758             FF_ESR = "23:23:00 GMT+0100 (Central European Standard Time)")
759     @HtmlUnitNYI(CHROME = "07:23:00 GMT+0900 (JST)",
760             EDGE = "07:23:00 GMT+0900 (JST)",
761             FF = "07:23:00 GMT+0900 (JST)",
762             FF_ESR = "07:23:00 GMT+0900 (JST)")
763     public void toTimeStringTokyo() throws Exception {
764         toTimeString("Asia/Tokyo");
765     }
766 
767     /**
768      * @throws Exception if the test fails
769      */
770     @Test
771     @Alerts("07:23:00 GMT+0900 (Japan Standard Time)")
772     @BuggyWebDriver(FF = "23:23:00 GMT+0100 (Central European Standard Time)",
773             FF_ESR = "23:23:00 GMT+0100 (Central European Standard Time)")
774     @HtmlUnitNYI(CHROME = "07:23:00 GMT+0900 (JST)",
775             EDGE = "07:23:00 GMT+0900 (JST)",
776             FF = "07:23:00 GMT+0900 (JST)",
777             FF_ESR = "07:23:00 GMT+0900 (JST)")
778     public void toTimeStringJST() throws Exception {
779         toTimeString("JST");
780     }
781 
782     private void toTimeString(final String tz) throws Exception {
783         final String html = DOCTYPE_HTML
784             + "<html><body><script>\n"
785             + LOG_TITLE_FUNCTION
786             + "log(new Date('Sat, 18 Dec 2021 22:23:00 UTC').toTimeString());\n"
787             + "</script>\n"
788             + "</body></html>";
789 
790         shutDownAll();
791         try {
792             final BrowserVersion.BrowserVersionBuilder builder
793                 = new BrowserVersion.BrowserVersionBuilder(getBrowserVersion());
794             builder.setSystemTimezone(TimeZone.getTimeZone(tz));
795             setBrowserVersion(builder.build());
796 
797             loadPageVerifyTitle2(html);
798         }
799         finally {
800             shutDownAll();
801         }
802     }
803 
804     /**
805      * @throws Exception if the test fails
806      */
807     @Test
808     @Alerts("Sat, 18 Dec 2021 22:23:00 GMT")
809     public void toUTCStringGMT() throws Exception {
810         toUTCString("GMT");
811     }
812 
813     /**
814      * @throws Exception if the test fails
815      */
816     @Test
817     @Alerts("Sat, 18 Dec 2021 22:23:00 GMT")
818     public void toUTCStringUTC() throws Exception {
819         toUTCString("UTC");
820     }
821 
822     /**
823      * @throws Exception if the test fails
824      */
825     @Test
826     @Alerts("Sat, 18 Dec 2021 22:23:00 GMT")
827     public void toUTCStringEST() throws Exception {
828         toUTCString("EST");
829     }
830 
831     /**
832      * @throws Exception if the test fails
833      */
834     @Test
835     @Alerts("Sat, 18 Dec 2021 22:23:00 GMT")
836     public void toUTCStringBerlin() throws Exception {
837         toUTCString("Europe/Berlin");
838     }
839 
840     /**
841      * @throws Exception if the test fails
842      */
843     @Test
844     @Alerts("Sat, 18 Dec 2021 22:23:00 GMT")
845     public void toUTCStringNewYork() throws Exception {
846         toUTCString("America/New_York");
847     }
848 
849     /**
850      * @throws Exception if the test fails
851      */
852     @Test
853     @Alerts("Sat, 18 Dec 2021 22:23:00 GMT")
854     public void toUTCStringTokyo() throws Exception {
855         toUTCString("Asia/Tokyo");
856     }
857 
858     /**
859      * @throws Exception if the test fails
860      */
861     @Test
862     @Alerts("Sat, 18 Dec 2021 22:23:00 GMT")
863     public void toUTCStringJST() throws Exception {
864         toUTCString("JST");
865     }
866 
867     private void toUTCString(final String tz) throws Exception {
868         final String html = DOCTYPE_HTML
869             + "<html><body><script>\n"
870             + LOG_TITLE_FUNCTION
871             + "log(new Date('Sat, 18 Dec 2021 22:23:00 UTC').toUTCString());\n"
872             + "</script>\n"
873             + "</body></html>";
874 
875         shutDownAll();
876         try {
877             final BrowserVersion.BrowserVersionBuilder builder
878                 = new BrowserVersion.BrowserVersionBuilder(getBrowserVersion());
879             builder.setSystemTimezone(TimeZone.getTimeZone(tz));
880             setBrowserVersion(builder.build());
881 
882             loadPageVerifyTitle2(html);
883         }
884         finally {
885             shutDownAll();
886         }
887     }
888 
889     /**
890      * @throws Exception if the test fails
891      */
892     @Test
893     @Alerts("0")
894     @BuggyWebDriver(FF = "-60",
895             FF_ESR = "-60")
896     public void timezoneOffsetGMT() throws Exception {
897         timezoneOffset("GMT");
898     }
899 
900     /**
901      * @throws Exception if the test fails
902      */
903     @Test
904     @Alerts("0")
905     @BuggyWebDriver(FF = "-60",
906             FF_ESR = "-60")
907     public void timezoneOffsetUTC() throws Exception {
908         timezoneOffset("UTC");
909     }
910 
911     /**
912      * @throws Exception if the test fails
913      */
914     @Test
915     @Alerts("300")
916     @BuggyWebDriver(FF = "-60",
917             FF_ESR = "-60")
918     public void timezoneOffsetEST() throws Exception {
919         timezoneOffset("EST");
920     }
921 
922     /**
923      * @throws Exception if the test fails
924      */
925     @Test
926     @Alerts("-60")
927     public void timezoneOffsetBerlin() throws Exception {
928         timezoneOffset("Europe/Berlin");
929     }
930 
931     /**
932      * @throws Exception if the test fails
933      */
934     @Test
935     @Alerts("300")
936     @BuggyWebDriver(FF = "-60",
937             FF_ESR = "-60")
938     public void timezoneOffsetNewYork() throws Exception {
939         timezoneOffset("America/New_York");
940     }
941 
942     /**
943      * @throws Exception if the test fails
944      */
945     @Test
946     @Alerts("-540")
947     @BuggyWebDriver(FF = "-60",
948             FF_ESR = "-60")
949     public void timezoneOffsetTokyo() throws Exception {
950         timezoneOffset("Asia/Tokyo");
951     }
952 
953     /**
954      * @throws Exception if the test fails
955      */
956     @Test
957     @Alerts("-540")
958     @BuggyWebDriver(FF = "-60",
959             FF_ESR = "-60")
960     public void timezoneOffsetJST() throws Exception {
961         timezoneOffset("JST");
962     }
963 
964     private void timezoneOffset(final String tz) throws Exception {
965         final String html = DOCTYPE_HTML
966             + "<html><body><script>\n"
967             + LOG_TITLE_FUNCTION
968             + "log(new Date(0).getTimezoneOffset());\n"
969             + "</script>\n"
970             + "</body></html>";
971 
972         shutDownAll();
973         try {
974             final BrowserVersion.BrowserVersionBuilder builder
975                 = new BrowserVersion.BrowserVersionBuilder(getBrowserVersion());
976             builder.setSystemTimezone(TimeZone.getTimeZone(tz));
977             setBrowserVersion(builder.build());
978 
979             loadPageVerifyTitle2(html);
980         }
981         finally {
982             shutDownAll();
983         }
984     }
985 }