View Javadoc

1   /*
2    *  Copyright 2001-2011 Stephen Colebourne
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    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.joda.time.format;
17  
18  import java.io.CharArrayWriter;
19  import java.util.Locale;
20  import java.util.TimeZone;
21  
22  import junit.framework.TestCase;
23  import junit.framework.TestSuite;
24  
25  import org.joda.time.Chronology;
26  import org.joda.time.DateTime;
27  import org.joda.time.DateTimeConstants;
28  import org.joda.time.DateTimeUtils;
29  import org.joda.time.DateTimeZone;
30  import org.joda.time.LocalDate;
31  import org.joda.time.LocalDateTime;
32  import org.joda.time.LocalTime;
33  import org.joda.time.MutableDateTime;
34  import org.joda.time.ReadablePartial;
35  import org.joda.time.chrono.BuddhistChronology;
36  import org.joda.time.chrono.GJChronology;
37  import org.joda.time.chrono.ISOChronology;
38  
39  /**
40   * This class is a Junit unit test for DateTime Formating.
41   *
42   * @author Stephen Colebourne
43   */
44  public class TestDateTimeFormatter extends TestCase {
45  
46      private static final DateTimeZone UTC = DateTimeZone.UTC;
47      private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
48      private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
49      private static final DateTimeZone TOKYO = DateTimeZone.forID("Asia/Tokyo");
50      private static final DateTimeZone NEWYORK = DateTimeZone.forID("America/New_York");
51      private static final Chronology ISO_UTC = ISOChronology.getInstanceUTC();
52      private static final Chronology ISO_PARIS = ISOChronology.getInstance(PARIS);
53      private static final Chronology BUDDHIST_PARIS = BuddhistChronology.getInstance(PARIS);
54  
55      long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 
56                       366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 
57                       365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
58                       366 + 365;
59      // 2002-06-09
60      private long TEST_TIME_NOW =
61              (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
62  
63      private DateTimeZone originalDateTimeZone = null;
64      private TimeZone originalTimeZone = null;
65      private Locale originalLocale = null;
66      private DateTimeFormatter f = null;
67      private DateTimeFormatter g = null;
68  
69      public static void main(String[] args) {
70          junit.textui.TestRunner.run(suite());
71      }
72  
73      public static TestSuite suite() {
74          return new TestSuite(TestDateTimeFormatter.class);
75      }
76  
77      public TestDateTimeFormatter(String name) {
78          super(name);
79      }
80  
81      protected void setUp() throws Exception {
82          DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
83          originalDateTimeZone = DateTimeZone.getDefault();
84          originalTimeZone = TimeZone.getDefault();
85          originalLocale = Locale.getDefault();
86          DateTimeZone.setDefault(LONDON);
87          TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
88          Locale.setDefault(Locale.UK);
89          f = new DateTimeFormatterBuilder()
90                  .appendDayOfWeekShortText()
91                  .appendLiteral(' ')
92                  .append(ISODateTimeFormat.dateTimeNoMillis())
93                  .toFormatter();
94          g = ISODateTimeFormat.dateTimeNoMillis();
95      }
96  
97      protected void tearDown() throws Exception {
98          DateTimeUtils.setCurrentMillisSystem();
99          DateTimeZone.setDefault(originalDateTimeZone);
100         TimeZone.setDefault(originalTimeZone);
101         Locale.setDefault(originalLocale);
102         originalDateTimeZone = null;
103         originalTimeZone = null;
104         originalLocale = null;
105         f = null;
106         g = null;
107     }
108 
109     //-----------------------------------------------------------------------
110     public void testPrint_simple() {
111         DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
112         assertEquals("Wed 2004-06-09T10:20:30Z", f.print(dt));
113         
114         dt = dt.withZone(PARIS);
115         assertEquals("Wed 2004-06-09T12:20:30+02:00", f.print(dt));
116         
117         dt = dt.withZone(NEWYORK);
118         assertEquals("Wed 2004-06-09T06:20:30-04:00", f.print(dt));
119         
120         dt = dt.withChronology(BUDDHIST_PARIS);
121         assertEquals("Wed 2547-06-09T12:20:30+02:00", f.print(dt));
122     }
123 
124     //-----------------------------------------------------------------------
125     public void testPrint_locale() {
126         DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
127         assertEquals("mer. 2004-06-09T10:20:30Z", f.withLocale(Locale.FRENCH).print(dt));
128         assertEquals("Wed 2004-06-09T10:20:30Z", f.withLocale(null).print(dt));
129     }
130 
131     //-----------------------------------------------------------------------
132     public void testPrint_zone() {
133         DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
134         assertEquals("Wed 2004-06-09T06:20:30-04:00", f.withZone(NEWYORK).print(dt));
135         assertEquals("Wed 2004-06-09T12:20:30+02:00", f.withZone(PARIS).print(dt));
136         assertEquals("Wed 2004-06-09T10:20:30Z", f.withZone(null).print(dt));
137         
138         dt = dt.withZone(NEWYORK);
139         assertEquals("Wed 2004-06-09T06:20:30-04:00", f.withZone(NEWYORK).print(dt));
140         assertEquals("Wed 2004-06-09T12:20:30+02:00", f.withZone(PARIS).print(dt));
141         assertEquals("Wed 2004-06-09T10:20:30Z", f.withZoneUTC().print(dt));
142         assertEquals("Wed 2004-06-09T06:20:30-04:00", f.withZone(null).print(dt));
143     }
144 
145     //-----------------------------------------------------------------------
146     public void testPrint_chrono() {
147         DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
148         assertEquals("Wed 2004-06-09T12:20:30+02:00", f.withChronology(ISO_PARIS).print(dt));
149         assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(BUDDHIST_PARIS).print(dt));
150         assertEquals("Wed 2004-06-09T10:20:30Z", f.withChronology(null).print(dt));
151         
152         dt = dt.withChronology(BUDDHIST_PARIS);
153         assertEquals("Wed 2004-06-09T12:20:30+02:00", f.withChronology(ISO_PARIS).print(dt));
154         assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(BUDDHIST_PARIS).print(dt));
155         assertEquals("Wed 2004-06-09T10:20:30Z", f.withChronology(ISO_UTC).print(dt));
156         assertEquals("Wed 2547-06-09T12:20:30+02:00", f.withChronology(null).print(dt));
157     }
158 
159     //-----------------------------------------------------------------------
160     public void testPrint_bufferMethods() throws Exception {
161         DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
162         StringBuffer buf = new StringBuffer();
163         f.printTo(buf, dt);
164         assertEquals("Wed 2004-06-09T10:20:30Z", buf.toString());
165         
166         buf = new StringBuffer();
167         f.printTo(buf, dt.getMillis());
168         assertEquals("Wed 2004-06-09T11:20:30+01:00", buf.toString());
169         
170         buf = new StringBuffer();
171         ISODateTimeFormat.yearMonthDay().printTo(buf, dt.toYearMonthDay());
172         assertEquals("2004-06-09", buf.toString());
173         
174         buf = new StringBuffer();
175         try {
176             ISODateTimeFormat.yearMonthDay().printTo(buf, (ReadablePartial) null);
177             fail();
178         } catch (IllegalArgumentException ex) {}
179     }
180 
181     //-----------------------------------------------------------------------
182     public void testPrint_writerMethods() throws Exception {
183         DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
184         CharArrayWriter out = new CharArrayWriter();
185         f.printTo(out, dt);
186         assertEquals("Wed 2004-06-09T10:20:30Z", out.toString());
187         
188         out = new CharArrayWriter();
189         f.printTo(out, dt.getMillis());
190         assertEquals("Wed 2004-06-09T11:20:30+01:00", out.toString());
191         
192         out = new CharArrayWriter();
193         ISODateTimeFormat.yearMonthDay().printTo(out, dt.toYearMonthDay());
194         assertEquals("2004-06-09", out.toString());
195         
196         out = new CharArrayWriter();
197         try {
198             ISODateTimeFormat.yearMonthDay().printTo(out, (ReadablePartial) null);
199             fail();
200         } catch (IllegalArgumentException ex) {}
201     }
202 
203     //-----------------------------------------------------------------------
204     public void testPrint_appendableMethods() throws Exception {
205         DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
206         StringBuilder buf = new StringBuilder();
207         f.printTo(buf, dt);
208         assertEquals("Wed 2004-06-09T10:20:30Z", buf.toString());
209         
210         buf = new StringBuilder();
211         f.printTo(buf, dt.getMillis());
212         assertEquals("Wed 2004-06-09T11:20:30+01:00", buf.toString());
213         
214         buf = new StringBuilder();
215         ISODateTimeFormat.yearMonthDay().printTo(buf, dt.toLocalDate());
216         assertEquals("2004-06-09", buf.toString());
217         
218         buf = new StringBuilder();
219         try {
220             ISODateTimeFormat.yearMonthDay().printTo(buf, (ReadablePartial) null);
221             fail();
222         } catch (IllegalArgumentException ex) {}
223     }
224 
225     //-----------------------------------------------------------------------
226     public void testPrint_chrono_and_zone() {
227         DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC);
228         assertEquals("Wed 2004-06-09T10:20:30Z",
229                 f.withChronology(null).withZone(null).print(dt));
230         assertEquals("Wed 2004-06-09T12:20:30+02:00",
231                 f.withChronology(ISO_PARIS).withZone(null).print(dt));
232         assertEquals("Wed 2004-06-09T12:20:30+02:00",
233                 f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
234         assertEquals("Wed 2004-06-09T06:20:30-04:00",
235                 f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
236         assertEquals("Wed 2004-06-09T06:20:30-04:00",
237                 f.withChronology(null).withZone(NEWYORK).print(dt));
238         
239         dt = dt.withChronology(ISO_PARIS);
240         assertEquals("Wed 2004-06-09T12:20:30+02:00",
241                 f.withChronology(null).withZone(null).print(dt));
242         assertEquals("Wed 2004-06-09T12:20:30+02:00",
243                 f.withChronology(ISO_PARIS).withZone(null).print(dt));
244         assertEquals("Wed 2004-06-09T12:20:30+02:00",
245                 f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
246         assertEquals("Wed 2004-06-09T06:20:30-04:00",
247                 f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
248         assertEquals("Wed 2004-06-09T06:20:30-04:00",
249                 f.withChronology(null).withZone(NEWYORK).print(dt));
250         
251         dt = dt.withChronology(BUDDHIST_PARIS);
252         assertEquals("Wed 2547-06-09T12:20:30+02:00",
253                 f.withChronology(null).withZone(null).print(dt));
254         assertEquals("Wed 2004-06-09T12:20:30+02:00",
255                 f.withChronology(ISO_PARIS).withZone(null).print(dt));
256         assertEquals("Wed 2004-06-09T12:20:30+02:00",
257                 f.withChronology(ISO_PARIS).withZone(PARIS).print(dt));
258         assertEquals("Wed 2004-06-09T06:20:30-04:00",
259                 f.withChronology(ISO_PARIS).withZone(NEWYORK).print(dt));
260         assertEquals("Wed 2547-06-09T06:20:30-04:00",
261                 f.withChronology(null).withZone(NEWYORK).print(dt));
262     }
263 
264     public void testWithGetLocale() {
265         DateTimeFormatter f2 = f.withLocale(Locale.FRENCH);
266         assertEquals(Locale.FRENCH, f2.getLocale());
267         assertSame(f2, f2.withLocale(Locale.FRENCH));
268         
269         f2 = f.withLocale(null);
270         assertEquals(null, f2.getLocale());
271         assertSame(f2, f2.withLocale(null));
272     }
273 
274     public void testWithGetZone() {
275         DateTimeFormatter f2 = f.withZone(PARIS);
276         assertEquals(PARIS, f2.getZone());
277         assertSame(f2, f2.withZone(PARIS));
278         
279         f2 = f.withZone(null);
280         assertEquals(null, f2.getZone());
281         assertSame(f2, f2.withZone(null));
282     }
283 
284     public void testWithGetChronology() {
285         DateTimeFormatter f2 = f.withChronology(BUDDHIST_PARIS);
286         assertEquals(BUDDHIST_PARIS, f2.getChronology());
287         assertSame(f2, f2.withChronology(BUDDHIST_PARIS));
288         
289         f2 = f.withChronology(null);
290         assertEquals(null, f2.getChronology());
291         assertSame(f2, f2.withChronology(null));
292     }
293 
294     public void testWithGetPivotYear() {
295         DateTimeFormatter f2 = f.withPivotYear(13);
296         assertEquals(new Integer(13), f2.getPivotYear());
297         assertSame(f2, f2.withPivotYear(13));
298         
299         f2 = f.withPivotYear(new Integer(14));
300         assertEquals(new Integer(14), f2.getPivotYear());
301         assertSame(f2, f2.withPivotYear(new Integer(14)));
302         
303         f2 = f.withPivotYear(null);
304         assertEquals(null, f2.getPivotYear());
305         assertSame(f2, f2.withPivotYear(null));
306     }
307 
308     public void testWithGetOffsetParsedMethods() {
309         DateTimeFormatter f2 = f;
310         assertEquals(false, f2.isOffsetParsed());
311         assertEquals(null, f2.getZone());
312         
313         f2 = f.withOffsetParsed();
314         assertEquals(true, f2.isOffsetParsed());
315         assertEquals(null, f2.getZone());
316         
317         f2 = f2.withZone(PARIS);
318         assertEquals(false, f2.isOffsetParsed());
319         assertEquals(PARIS, f2.getZone());
320         
321         f2 = f2.withOffsetParsed();
322         assertEquals(true, f2.isOffsetParsed());
323         assertEquals(null, f2.getZone());
324         
325         f2 = f.withOffsetParsed();
326         assertNotSame(f, f2);
327         DateTimeFormatter f3 = f2.withOffsetParsed();
328         assertSame(f2, f3);
329     }
330 
331     public void testPrinterParserMethods() {
332         DateTimeFormatter f2 = new DateTimeFormatter(f.getPrinter(), f.getParser());
333         assertEquals(f.getPrinter(), f2.getPrinter());
334         assertEquals(f.getParser(), f2.getParser());
335         assertEquals(true, f2.isPrinter());
336         assertEquals(true, f2.isParser());
337         assertNotNull(f2.print(0L));
338         assertNotNull(f2.parseDateTime("Thu 1970-01-01T00:00:00Z"));
339         
340         f2 = new DateTimeFormatter(f.getPrinter(), null);
341         assertEquals(f.getPrinter(), f2.getPrinter());
342         assertEquals(null, f2.getParser());
343         assertEquals(true, f2.isPrinter());
344         assertEquals(false, f2.isParser());
345         assertNotNull(f2.print(0L));
346         try {
347             f2.parseDateTime("Thu 1970-01-01T00:00:00Z");
348             fail();
349         } catch (UnsupportedOperationException ex) {}
350         
351         f2 = new DateTimeFormatter(null, f.getParser());
352         assertEquals(null, f2.getPrinter());
353         assertEquals(f.getParser(), f2.getParser());
354         assertEquals(false, f2.isPrinter());
355         assertEquals(true, f2.isParser());
356         try {
357             f2.print(0L);
358             fail();
359         } catch (UnsupportedOperationException ex) {}
360         assertNotNull(f2.parseDateTime("Thu 1970-01-01T00:00:00Z"));
361     }
362 
363     //-----------------------------------------------------------------------
364     public void testParseLocalDate_simple() {
365         assertEquals(new LocalDate(2004, 6, 9), g.parseLocalDate("2004-06-09T10:20:30Z"));
366         assertEquals(new LocalDate(2004, 6, 9), g.parseLocalDate("2004-06-09T10:20:30+18:00"));
367         assertEquals(new LocalDate(2004, 6, 9), g.parseLocalDate("2004-06-09T10:20:30-18:00"));
368         assertEquals(new LocalDate(2004, 6, 9, BUDDHIST_PARIS),
369                 g.withChronology(BUDDHIST_PARIS).parseLocalDate("2004-06-09T10:20:30Z"));
370         try {
371             g.parseDateTime("ABC");
372             fail();
373         } catch (IllegalArgumentException ex) {}
374     }
375 
376     public void testParseLocalDate_yearOfEra() {
377         Chronology chrono = GJChronology.getInstanceUTC();
378         DateTimeFormatter f = DateTimeFormat
379             .forPattern("YYYY-MM GG")
380             .withChronology(chrono)
381             .withLocale(Locale.UK);
382         
383         LocalDate date = new LocalDate(2005, 10, 1, chrono);
384         assertEquals(date, f.parseLocalDate("2005-10 AD"));
385         assertEquals(date, f.parseLocalDate("2005-10 CE"));
386         
387         date = new LocalDate(-2005, 10, 1, chrono);
388         assertEquals(date, f.parseLocalDate("2005-10 BC"));
389         assertEquals(date, f.parseLocalDate("2005-10 BCE"));
390     }
391 
392     public void testParseLocalDate_yearOfCentury() {
393         Chronology chrono = GJChronology.getInstanceUTC();
394         DateTimeFormatter f = DateTimeFormat
395             .forPattern("yy M d")
396             .withChronology(chrono)
397             .withLocale(Locale.UK)
398             .withPivotYear(2050);
399         
400         LocalDate date = new LocalDate(2050, 8, 4, chrono);
401         assertEquals(date, f.parseLocalDate("50 8 4"));
402     }
403 
404     public void testParseLocalDate_monthDay_feb29() {
405         Chronology chrono = GJChronology.getInstanceUTC();
406         DateTimeFormatter f = DateTimeFormat
407             .forPattern("M d")
408             .withChronology(chrono)
409             .withLocale(Locale.UK);
410         
411         assertEquals(new LocalDate(2000, 2, 29, chrono), f.parseLocalDate("2 29"));
412     }
413 
414     public void testParseLocalDate_monthDay_withDefaultYear_feb29() {
415         Chronology chrono = GJChronology.getInstanceUTC();
416         DateTimeFormatter f = DateTimeFormat
417             .forPattern("M d")
418             .withChronology(chrono)
419             .withLocale(Locale.UK)
420             .withDefaultYear(2012);
421         
422         assertEquals(new LocalDate(2012, 2, 29, chrono), f.parseLocalDate("2 29"));
423     }
424 
425     public void testParseLocalDate_weekyear_month_week_2010() {
426         Chronology chrono = GJChronology.getInstanceUTC();
427         DateTimeFormatter f = DateTimeFormat.forPattern("xxxx-MM-ww").withChronology(chrono);
428         assertEquals(new LocalDate(2010, 1, 4, chrono), f.parseLocalDate("2010-01-01"));
429     }
430 
431     public void testParseLocalDate_weekyear_month_week_2011() {
432         Chronology chrono = GJChronology.getInstanceUTC();
433         DateTimeFormatter f = DateTimeFormat.forPattern("xxxx-MM-ww").withChronology(chrono);
434         assertEquals(new LocalDate(2011, 1, 3, chrono), f.parseLocalDate("2011-01-01"));
435     }
436 
437     public void testParseLocalDate_weekyear_month_week_2012() {
438         Chronology chrono = GJChronology.getInstanceUTC();
439         DateTimeFormatter f = DateTimeFormat.forPattern("xxxx-MM-ww").withChronology(chrono);
440         assertEquals(new LocalDate(2012, 1, 2, chrono), f.parseLocalDate("2012-01-01"));
441     }
442 
443 // This test fails, but since more related tests pass with the extra loop in DateTimeParserBucket
444 // I'm going to leave the change in and ignore this test
445 //    public void testParseLocalDate_weekyear_month_week_2013() {
446 //        Chronology chrono = GJChronology.getInstanceUTC();
447 //        DateTimeFormatter f = DateTimeFormat.forPattern("xxxx-MM-ww").withChronology(chrono);
448 //        assertEquals(new LocalDate(2012, 12, 31, chrono), f.parseLocalDate("2013-01-01"));
449 //    }
450 
451     public void testParseLocalDate_year_month_week_2010() {
452         Chronology chrono = GJChronology.getInstanceUTC();
453         DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
454         assertEquals(new LocalDate(2010, 1, 4, chrono), f.parseLocalDate("2010-01-01"));
455     }
456 
457     public void testParseLocalDate_year_month_week_2011() {
458         Chronology chrono = GJChronology.getInstanceUTC();
459         DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
460         assertEquals(new LocalDate(2011, 1, 3, chrono), f.parseLocalDate("2011-01-01"));
461     }
462 
463     public void testParseLocalDate_year_month_week_2012() {
464         Chronology chrono = GJChronology.getInstanceUTC();
465         DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
466         assertEquals(new LocalDate(2012, 1, 2, chrono), f.parseLocalDate("2012-01-01"));
467     }
468 
469     public void testParseLocalDate_year_month_week_2013() {
470         Chronology chrono = GJChronology.getInstanceUTC();
471         DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
472         assertEquals(new LocalDate(2012, 12, 31, chrono), f.parseLocalDate("2013-01-01"));  // 2013-01-01 would be better, but this is OK
473     }
474 
475     public void testParseLocalDate_year_month_week_2014() {
476         Chronology chrono = GJChronology.getInstanceUTC();
477         DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
478         assertEquals(new LocalDate(2013, 12, 30, chrono), f.parseLocalDate("2014-01-01"));  // 2014-01-01 would be better, but this is OK
479     }
480 
481     public void testParseLocalDate_year_month_week_2015() {
482         Chronology chrono = GJChronology.getInstanceUTC();
483         DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
484         assertEquals(new LocalDate(2014, 12, 29, chrono), f.parseLocalDate("2015-01-01"));  // 2015-01-01 would be better, but this is OK
485     }
486 
487     public void testParseLocalDate_year_month_week_2016() {
488         Chronology chrono = GJChronology.getInstanceUTC();
489         DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
490         assertEquals(new LocalDate(2016, 1, 4, chrono), f.parseLocalDate("2016-01-01"));
491     }
492 
493     //-----------------------------------------------------------------------
494     public void testParseLocalTime_simple() {
495         assertEquals(new LocalTime(10, 20, 30), g.parseLocalTime("2004-06-09T10:20:30Z"));
496         assertEquals(new LocalTime(10, 20, 30), g.parseLocalTime("2004-06-09T10:20:30+18:00"));
497         assertEquals(new LocalTime(10, 20, 30), g.parseLocalTime("2004-06-09T10:20:30-18:00"));
498         assertEquals(new LocalTime(10, 20, 30, 0, BUDDHIST_PARIS),
499                 g.withChronology(BUDDHIST_PARIS).parseLocalTime("2004-06-09T10:20:30Z"));
500         try {
501             g.parseDateTime("ABC");
502             fail();
503         } catch (IllegalArgumentException ex) {}
504     }
505 
506     //-----------------------------------------------------------------------
507     public void testParseLocalDateTime_simple() {
508         assertEquals(new LocalDateTime(2004, 6, 9, 10, 20, 30), g.parseLocalDateTime("2004-06-09T10:20:30Z"));
509         assertEquals(new LocalDateTime(2004, 6, 9, 10, 20, 30), g.parseLocalDateTime("2004-06-09T10:20:30+18:00"));
510         assertEquals(new LocalDateTime(2004, 6, 9, 10, 20, 30), g.parseLocalDateTime("2004-06-09T10:20:30-18:00"));
511         assertEquals(new LocalDateTime(2004, 6, 9, 10, 20, 30, 0, BUDDHIST_PARIS),
512                 g.withChronology(BUDDHIST_PARIS).parseLocalDateTime("2004-06-09T10:20:30Z"));
513         try {
514             g.parseDateTime("ABC");
515             fail();
516         } catch (IllegalArgumentException ex) {}
517     }
518 
519     public void testParseLocalDateTime_monthDay_feb29() {
520         Chronology chrono = GJChronology.getInstanceUTC();
521         DateTimeFormatter f = DateTimeFormat
522             .forPattern("M d H m")
523             .withChronology(chrono)
524             .withLocale(Locale.UK);
525         
526         assertEquals(new LocalDateTime(2000, 2, 29, 13, 40, 0, 0, chrono), f.parseLocalDateTime("2 29 13 40"));
527     }
528 
529     public void testParseLocalDateTime_monthDay_withDefaultYear_feb29() {
530         Chronology chrono = GJChronology.getInstanceUTC();
531         DateTimeFormatter f = DateTimeFormat
532             .forPattern("M d H m")
533             .withChronology(chrono)
534             .withLocale(Locale.UK)
535             .withDefaultYear(2012);
536         
537         assertEquals(new LocalDateTime(2012, 2, 29, 13, 40, 0, 0, chrono), f.parseLocalDateTime("2 29 13 40"));
538     }
539 
540     //-----------------------------------------------------------------------
541     public void testParseDateTime_simple() {
542         DateTime expect = null;
543         expect = new DateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
544         assertEquals(expect, g.parseDateTime("2004-06-09T10:20:30Z"));
545         
546         try {
547             g.parseDateTime("ABC");
548             fail();
549         } catch (IllegalArgumentException ex) {}
550     }
551 
552     public void testParseDateTime_zone() {
553         DateTime expect = null;
554         expect = new DateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
555         assertEquals(expect, g.withZone(LONDON).parseDateTime("2004-06-09T10:20:30Z"));
556         
557         expect = new DateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
558         assertEquals(expect, g.withZone(null).parseDateTime("2004-06-09T10:20:30Z"));
559         
560         expect = new DateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
561         assertEquals(expect, g.withZone(PARIS).parseDateTime("2004-06-09T10:20:30Z"));
562     }
563 
564     public void testParseDateTime_zone2() {
565         DateTime expect = null;
566         expect = new DateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
567         assertEquals(expect, g.withZone(LONDON).parseDateTime("2004-06-09T06:20:30-04:00"));
568         
569         expect = new DateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
570         assertEquals(expect, g.withZone(null).parseDateTime("2004-06-09T06:20:30-04:00"));
571         
572         expect = new DateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
573         assertEquals(expect, g.withZone(PARIS).parseDateTime("2004-06-09T06:20:30-04:00"));
574     }
575 
576     public void testParseDateTime_zone3() {
577         DateTimeFormatter h = new DateTimeFormatterBuilder()
578         .append(ISODateTimeFormat.date())
579         .appendLiteral('T')
580         .append(ISODateTimeFormat.timeElementParser())
581         .toFormatter();
582         
583         DateTime expect = null;
584         expect = new DateTime(2004, 6, 9, 10, 20, 30, 0, LONDON);
585         assertEquals(expect, h.withZone(LONDON).parseDateTime("2004-06-09T10:20:30"));
586         
587         expect = new DateTime(2004, 6, 9, 10, 20, 30, 0, LONDON);
588         assertEquals(expect, h.withZone(null).parseDateTime("2004-06-09T10:20:30"));
589         
590         expect = new DateTime(2004, 6, 9, 10, 20, 30, 0, PARIS);
591         assertEquals(expect, h.withZone(PARIS).parseDateTime("2004-06-09T10:20:30"));
592     }
593 
594     public void testParseDateTime_simple_precedence() {
595         DateTime expect = null;
596         // use correct day of week
597         expect = new DateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
598         assertEquals(expect, f.parseDateTime("Wed 2004-06-09T10:20:30Z"));
599         
600         // use wrong day of week
601         expect = new DateTime(2004, 6, 7, 11, 20, 30, 0, LONDON);
602         // DayOfWeek takes precedence, because week < month in length
603         assertEquals(expect, f.parseDateTime("Mon 2004-06-09T10:20:30Z"));
604     }
605 
606     public void testParseDateTime_offsetParsed() {
607         DateTime expect = null;
608         expect = new DateTime(2004, 6, 9, 10, 20, 30, 0, UTC);
609         assertEquals(expect, g.withOffsetParsed().parseDateTime("2004-06-09T10:20:30Z"));
610         
611         expect = new DateTime(2004, 6, 9, 6, 20, 30, 0, DateTimeZone.forOffsetHours(-4));
612         assertEquals(expect, g.withOffsetParsed().parseDateTime("2004-06-09T06:20:30-04:00"));
613         
614         expect = new DateTime(2004, 6, 9, 10, 20, 30, 0, UTC);
615         assertEquals(expect, g.withZone(PARIS).withOffsetParsed().parseDateTime("2004-06-09T10:20:30Z"));
616         expect = new DateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
617         assertEquals(expect, g.withOffsetParsed().withZone(PARIS).parseDateTime("2004-06-09T10:20:30Z"));
618     }
619 
620     public void testParseDateTime_chrono() {
621         DateTime expect = null;
622         expect = new DateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
623         assertEquals(expect, g.withChronology(ISO_PARIS).parseDateTime("2004-06-09T10:20:30Z"));
624         
625         expect = new DateTime(2004, 6, 9, 11, 20, 30, 0,LONDON);
626         assertEquals(expect, g.withChronology(null).parseDateTime("2004-06-09T10:20:30Z"));
627         
628         expect = new DateTime(2547, 6, 9, 12, 20, 30, 0, BUDDHIST_PARIS);
629         assertEquals(expect, g.withChronology(BUDDHIST_PARIS).parseDateTime("2547-06-09T10:20:30Z"));
630         
631         expect = new DateTime(2004, 6, 9, 10, 29, 51, 0, BUDDHIST_PARIS); // zone is +00:09:21 in 1451
632         assertEquals(expect, g.withChronology(BUDDHIST_PARIS).parseDateTime("2004-06-09T10:20:30Z"));
633     }
634 
635     //-----------------------------------------------------------------------
636     public void testParseMutableDateTime_simple() {
637         MutableDateTime expect = null;
638         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
639         assertEquals(expect, g.parseMutableDateTime("2004-06-09T10:20:30Z"));
640         
641         try {
642             g.parseMutableDateTime("ABC");
643             fail();
644         } catch (IllegalArgumentException ex) {}
645     }
646 
647     public void testParseMutableDateTime_zone() {
648         MutableDateTime expect = null;
649         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
650         assertEquals(expect, g.withZone(LONDON).parseMutableDateTime("2004-06-09T10:20:30Z"));
651         
652         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
653         assertEquals(expect, g.withZone(null).parseMutableDateTime("2004-06-09T10:20:30Z"));
654         
655         expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
656         assertEquals(expect, g.withZone(PARIS).parseMutableDateTime("2004-06-09T10:20:30Z"));
657     }
658 
659     public void testParseMutableDateTime_zone2() {
660         MutableDateTime expect = null;
661         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
662         assertEquals(expect, g.withZone(LONDON).parseMutableDateTime("2004-06-09T06:20:30-04:00"));
663         
664         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
665         assertEquals(expect, g.withZone(null).parseMutableDateTime("2004-06-09T06:20:30-04:00"));
666         
667         expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
668         assertEquals(expect, g.withZone(PARIS).parseMutableDateTime("2004-06-09T06:20:30-04:00"));
669     }
670 
671     public void testParseMutableDateTime_zone3() {
672         DateTimeFormatter h = new DateTimeFormatterBuilder()
673         .append(ISODateTimeFormat.date())
674         .appendLiteral('T')
675         .append(ISODateTimeFormat.timeElementParser())
676         .toFormatter();
677         
678         MutableDateTime expect = null;
679         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, LONDON);
680         assertEquals(expect, h.withZone(LONDON).parseMutableDateTime("2004-06-09T10:20:30"));
681         
682         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, LONDON);
683         assertEquals(expect, h.withZone(null).parseMutableDateTime("2004-06-09T10:20:30"));
684         
685         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, PARIS);
686         assertEquals(expect, h.withZone(PARIS).parseMutableDateTime("2004-06-09T10:20:30"));
687     }
688 
689     public void testParseMutableDateTime_simple_precedence() {
690         MutableDateTime expect = null;
691         // use correct day of week
692         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
693         assertEquals(expect, f.parseDateTime("Wed 2004-06-09T10:20:30Z"));
694         
695         // use wrong day of week
696         expect = new MutableDateTime(2004, 6, 7, 11, 20, 30, 0, LONDON);
697         // DayOfWeek takes precedence, because week < month in length
698         assertEquals(expect, f.parseDateTime("Mon 2004-06-09T10:20:30Z"));
699     }
700 
701     public void testParseMutableDateTime_offsetParsed() {
702         MutableDateTime expect = null;
703         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, UTC);
704         assertEquals(expect, g.withOffsetParsed().parseMutableDateTime("2004-06-09T10:20:30Z"));
705         
706         expect = new MutableDateTime(2004, 6, 9, 6, 20, 30, 0, DateTimeZone.forOffsetHours(-4));
707         assertEquals(expect, g.withOffsetParsed().parseMutableDateTime("2004-06-09T06:20:30-04:00"));
708         
709         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, UTC);
710         assertEquals(expect, g.withZone(PARIS).withOffsetParsed().parseMutableDateTime("2004-06-09T10:20:30Z"));
711         expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
712         assertEquals(expect, g.withOffsetParsed().withZone(PARIS).parseMutableDateTime("2004-06-09T10:20:30Z"));
713     }
714 
715     public void testParseMutableDateTime_chrono() {
716         MutableDateTime expect = null;
717         expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
718         assertEquals(expect, g.withChronology(ISO_PARIS).parseMutableDateTime("2004-06-09T10:20:30Z"));
719         
720         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0,LONDON);
721         assertEquals(expect, g.withChronology(null).parseMutableDateTime("2004-06-09T10:20:30Z"));
722         
723         expect = new MutableDateTime(2547, 6, 9, 12, 20, 30, 0, BUDDHIST_PARIS);
724         assertEquals(expect, g.withChronology(BUDDHIST_PARIS).parseMutableDateTime("2547-06-09T10:20:30Z"));
725         
726         expect = new MutableDateTime(2004, 6, 9, 10, 29, 51, 0, BUDDHIST_PARIS); // zone is +00:09:21 in 1451
727         assertEquals(expect, g.withChronology(BUDDHIST_PARIS).parseMutableDateTime("2004-06-09T10:20:30Z"));
728     }
729 
730     //-----------------------------------------------------------------------
731     public void testParseInto_simple() {
732         MutableDateTime expect = null;
733         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
734         MutableDateTime result = new MutableDateTime(0L);
735         assertEquals(20, g.parseInto(result, "2004-06-09T10:20:30Z", 0));
736         assertEquals(expect, result);
737         
738         try {
739             g.parseInto(null, "2004-06-09T10:20:30Z", 0);
740             fail();
741         } catch (IllegalArgumentException ex) {}
742         
743         assertEquals(~0, g.parseInto(result, "ABC", 0));
744         assertEquals(~10, g.parseInto(result, "2004-06-09", 0));
745         assertEquals(~13, g.parseInto(result, "XX2004-06-09T", 2));
746     }
747 
748     public void testParseInto_zone() {
749         MutableDateTime expect = null;
750         MutableDateTime result = null;
751         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
752         result = new MutableDateTime(0L);
753         assertEquals(20, g.withZone(LONDON).parseInto(result, "2004-06-09T10:20:30Z", 0));
754         assertEquals(expect, result);
755         
756         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
757         result = new MutableDateTime(0L);
758         assertEquals(20, g.withZone(null).parseInto(result, "2004-06-09T10:20:30Z", 0));
759         assertEquals(expect, result);
760         
761         expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
762         result = new MutableDateTime(0L);
763         assertEquals(20, g.withZone(PARIS).parseInto(result, "2004-06-09T10:20:30Z", 0));
764         assertEquals(expect, result);
765     }
766 
767     public void testParseInto_zone2() {
768         MutableDateTime expect = null;
769         MutableDateTime result = null;
770         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
771         result = new MutableDateTime(0L);
772         assertEquals(25, g.withZone(LONDON).parseInto(result, "2004-06-09T06:20:30-04:00", 0));
773         assertEquals(expect, result);
774         
775         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
776         assertEquals(25, g.withZone(null).parseInto(result, "2004-06-09T06:20:30-04:00", 0));
777         assertEquals(expect, result);
778         
779         expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
780         assertEquals(25, g.withZone(PARIS).parseInto(result, "2004-06-09T06:20:30-04:00", 0));
781         assertEquals(expect, result);
782     }
783 
784     public void testParseInto_zone3() {
785         DateTimeFormatter h = new DateTimeFormatterBuilder()
786         .append(ISODateTimeFormat.date())
787         .appendLiteral('T')
788         .append(ISODateTimeFormat.timeElementParser())
789         .toFormatter();
790         
791         MutableDateTime expect = null;
792         MutableDateTime result = null;
793         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, LONDON);
794         result = new MutableDateTime(0L);
795         assertEquals(19, h.withZone(LONDON).parseInto(result, "2004-06-09T10:20:30", 0));
796         assertEquals(expect, result);
797         
798         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, LONDON);
799         result = new MutableDateTime(0L);
800         assertEquals(19, h.withZone(null).parseInto(result, "2004-06-09T10:20:30", 0));
801         assertEquals(expect, result);
802         
803         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, PARIS);
804         result = new MutableDateTime(0L);
805         assertEquals(19, h.withZone(PARIS).parseInto(result, "2004-06-09T10:20:30", 0));
806         assertEquals(expect, result);
807     }
808 
809     public void testParseInto_simple_precedence() {
810         MutableDateTime expect = null;
811         MutableDateTime result = null;
812         expect = new MutableDateTime(2004, 6, 7, 11, 20, 30, 0, LONDON);
813         result = new MutableDateTime(0L);
814         // DayOfWeek takes precedence, because week < month in length
815         assertEquals(24, f.parseInto(result, "Mon 2004-06-09T10:20:30Z", 0));
816         assertEquals(expect, result);
817     }
818 
819     public void testParseInto_offsetParsed() {
820         MutableDateTime expect = null;
821         MutableDateTime result = null;
822         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, UTC);
823         result = new MutableDateTime(0L);
824         assertEquals(20, g.withOffsetParsed().parseInto(result, "2004-06-09T10:20:30Z", 0));
825         assertEquals(expect, result);
826         
827         expect = new MutableDateTime(2004, 6, 9, 6, 20, 30, 0, DateTimeZone.forOffsetHours(-4));
828         result = new MutableDateTime(0L);
829         assertEquals(25, g.withOffsetParsed().parseInto(result, "2004-06-09T06:20:30-04:00", 0));
830         assertEquals(expect, result);
831         
832         expect = new MutableDateTime(2004, 6, 9, 10, 20, 30, 0, UTC);
833         result = new MutableDateTime(0L);
834         assertEquals(20, g.withZone(PARIS).withOffsetParsed().parseInto(result, "2004-06-09T10:20:30Z", 0));
835         assertEquals(expect, result);
836         expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
837         result = new MutableDateTime(0L);
838         assertEquals(20, g.withOffsetParsed().withZone(PARIS).parseInto(result, "2004-06-09T10:20:30Z", 0));
839         assertEquals(expect, result);
840     }
841 
842     public void testParseInto_chrono() {
843         MutableDateTime expect = null;
844         MutableDateTime result = null;
845         expect = new MutableDateTime(2004, 6, 9, 12, 20, 30, 0, PARIS);
846         result = new MutableDateTime(0L);
847         assertEquals(20, g.withChronology(ISO_PARIS).parseInto(result, "2004-06-09T10:20:30Z", 0));
848         assertEquals(expect, result);
849         
850         expect = new MutableDateTime(2004, 6, 9, 11, 20, 30, 0, LONDON);
851         result = new MutableDateTime(0L);
852         assertEquals(20, g.withChronology(null).parseInto(result, "2004-06-09T10:20:30Z", 0));
853         assertEquals(expect, result);
854         
855         expect = new MutableDateTime(2547, 6, 9, 12, 20, 30, 0, BUDDHIST_PARIS);
856         result = new MutableDateTime(0L);
857         assertEquals(20, g.withChronology(BUDDHIST_PARIS).parseInto(result, "2547-06-09T10:20:30Z", 0));
858         assertEquals(expect, result);
859         
860         expect = new MutableDateTime(2004, 6, 9, 10, 29, 51, 0, BUDDHIST_PARIS);
861         result = new MutableDateTime(0L);
862         assertEquals(20, g.withChronology(BUDDHIST_PARIS).parseInto(result, "2004-06-09T10:20:30Z", 0));
863         assertEquals(expect, result);
864     }
865 
866     public void testParseInto_monthOnly() {
867         DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
868         MutableDateTime result = new MutableDateTime(2004, 1, 9, 12, 20, 30, 0, LONDON);
869         assertEquals(1, f.parseInto(result, "5", 0));
870         assertEquals(new MutableDateTime(2004, 5, 9, 12, 20, 30, 0, LONDON), result);
871     }
872 
873     public void testParseInto_monthOnly_baseStartYear() {
874         DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
875         MutableDateTime result = new MutableDateTime(2004, 1, 1, 12, 20, 30, 0, TOKYO);
876         assertEquals(1, f.parseInto(result, "5", 0));
877         assertEquals(new MutableDateTime(2004, 5, 1, 12, 20, 30, 0, TOKYO), result);
878     }
879 
880     public void testParseInto_monthOnly_parseStartYear() {
881         DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
882         MutableDateTime result = new MutableDateTime(2004, 2, 1, 12, 20, 30, 0, TOKYO);
883         assertEquals(1, f.parseInto(result, "1", 0));
884         assertEquals(new MutableDateTime(2004, 1, 1, 12, 20, 30, 0, TOKYO), result);
885     }
886 
887     public void testParseInto_monthOnly_baseEndYear() {
888         DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
889         MutableDateTime result = new MutableDateTime(2004, 12, 31, 12, 20, 30, 0, TOKYO);
890         assertEquals(1, f.parseInto(result, "5", 0));
891         assertEquals(new MutableDateTime(2004, 5, 31, 12, 20, 30, 0, TOKYO), result);
892    }
893 
894     public void testParseInto_monthOnly_parseEndYear() {
895         DateTimeFormatter f = DateTimeFormat.forPattern("M").withLocale(Locale.UK);
896         MutableDateTime result = new MutableDateTime(2004, 1, 31, 12, 20, 30, 0,TOKYO);
897         assertEquals(2, f.parseInto(result, "12", 0));
898         assertEquals(new MutableDateTime(2004, 12, 31, 12, 20, 30, 0, TOKYO), result);
899     }
900 
901     public void testParseInto_monthDay_feb29() {
902         DateTimeFormatter f = DateTimeFormat.forPattern("M d").withLocale(Locale.UK);
903         MutableDateTime result = new MutableDateTime(2004, 1, 9, 12, 20, 30, 0, LONDON);
904         assertEquals(4, f.parseInto(result, "2 29", 0));
905         assertEquals(new MutableDateTime(2004, 2, 29, 12, 20, 30, 0, LONDON), result);
906     }
907 
908     public void testParseInto_monthDay_withDefaultYear_feb29() {
909         DateTimeFormatter f = DateTimeFormat.forPattern("M d").withDefaultYear(2012);
910         MutableDateTime result = new MutableDateTime(2004, 1, 9, 12, 20, 30, 0, LONDON);
911         assertEquals(4, f.parseInto(result, "2 29", 0));
912         assertEquals(new MutableDateTime(2004, 2, 29, 12, 20, 30, 0, LONDON), result);
913     }
914 
915     public void testParseMillis_fractionOfSecondLong() {
916         DateTimeFormatter f = new DateTimeFormatterBuilder()
917             .appendSecondOfDay(2).appendLiteral('.').appendFractionOfSecond(1, 9)
918                 .toFormatter().withZoneUTC();
919         assertEquals(10512, f.parseMillis("10.5123456"));
920         assertEquals(10512, f.parseMillis("10.512999"));
921     }
922 
923     //-----------------------------------------------------------------------
924     // Ensure time zone name switches properly at the zone DST transition.
925     public void testZoneNameNearTransition() {
926         DateTime inDST_1  = new DateTime(2005, 10, 30, 1, 0, 0, 0, NEWYORK);
927         DateTime inDST_2  = new DateTime(2005, 10, 30, 1, 59, 59, 999, NEWYORK);
928         DateTime onDST    = new DateTime(2005, 10, 30, 2, 0, 0, 0, NEWYORK);
929         DateTime outDST   = new DateTime(2005, 10, 30, 2, 0, 0, 1, NEWYORK);
930         DateTime outDST_2 = new DateTime(2005, 10, 30, 2, 0, 1, 0, NEWYORK);
931 
932         DateTimeFormatter fmt = DateTimeFormat.forPattern("yyy-MM-dd HH:mm:ss.S zzzz");
933         assertEquals("2005-10-30 01:00:00.0 Eastern Daylight Time", fmt.print(inDST_1));
934         assertEquals("2005-10-30 01:59:59.9 Eastern Daylight Time", fmt.print(inDST_2));
935         assertEquals("2005-10-30 02:00:00.0 Eastern Standard Time", fmt.print(onDST));
936         assertEquals("2005-10-30 02:00:00.0 Eastern Standard Time", fmt.print(outDST));
937         assertEquals("2005-10-30 02:00:01.0 Eastern Standard Time", fmt.print(outDST_2));
938     }
939 
940     // Ensure time zone name switches properly at the zone DST transition.
941     public void testZoneShortNameNearTransition() {
942         DateTime inDST_1  = new DateTime(2005, 10, 30, 1, 0, 0, 0, NEWYORK);
943         DateTime inDST_2  = new DateTime(2005, 10, 30, 1, 59, 59, 999, NEWYORK);
944         DateTime onDST    = new DateTime(2005, 10, 30, 2, 0, 0, 0, NEWYORK);
945         DateTime outDST   = new DateTime(2005, 10, 30, 2, 0, 0, 1, NEWYORK);
946         DateTime outDST_2 = new DateTime(2005, 10, 30, 2, 0, 1, 0, NEWYORK);
947 
948         DateTimeFormatter fmt = DateTimeFormat.forPattern("yyy-MM-dd HH:mm:ss.S z");
949         assertEquals("2005-10-30 01:00:00.0 EDT", fmt.print(inDST_1));
950         assertEquals("2005-10-30 01:59:59.9 EDT", fmt.print(inDST_2));
951         assertEquals("2005-10-30 02:00:00.0 EST", fmt.print(onDST));
952         assertEquals("2005-10-30 02:00:00.0 EST", fmt.print(outDST));
953         assertEquals("2005-10-30 02:00:01.0 EST", fmt.print(outDST_2));
954     }
955 
956 }