Skip to content

Commit

Permalink
Conversion from parsed values to a date-time handles weird sets of fi…
Browse files Browse the repository at this point in the history
…elds better [3161586]

This change is mostly for combinations like weekyear-month-week
The new code doesn't handle all combinations perfectly, but its better than it was

git-svn-id: https://joda-time.svn.sourceforge.net/svnroot/joda-time/trunk@1606 1e1cfbb7-5c0e-0410-a2f0-f98d92ec03a1
  • Loading branch information
jodastephen committed Feb 15, 2011
1 parent c3bec2c commit d50efdf
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
7 changes: 7 additions & 0 deletions JodaTime/RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ This affects the constructor of DateTime and other methods.
Previously, DateTimeZone.getMillisKeepLocal used DateTimeZone.getOffsetFromLocal, now it uses
DateTimeZone.convertUTCToLocal and DateTimeZone.convertLocalToUTC retaining the offset where possible

Previously, some parses of mixed weekyear and month formats would yield a result about a year out
Now, most (but not all) of these give a more appropriate result


Deprecations since 1.6
----------------------
Expand Down Expand Up @@ -217,6 +220,10 @@ Bug fixes since 1.6

- Standard DateTimeFieldType implements hashCode and equals for stability across serialization

- Conversion from parsed values to a date-time handles weird sets of fields better [3161586]
This change is mostly for combinations like weekyear-month-week
The new code doesn't handle all combinations perfectly, but its better than it was

- Time zone compiler now handles 24:00 [2804258]

- Time zone compiler now handles non-UTC better
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2009 Stephen Colebourne
* Copyright 2001-2011 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -349,9 +349,14 @@ public long computeMillis(boolean resetFields, String text) {

long millis = iMillis;
try {
for (int i=0; i<count; i++) {
for (int i = 0; i < count; i++) {
millis = savedFields[i].set(millis, resetFields);
}
if (resetFields) {
for (int i = 0; i < count; i++) {
millis = savedFields[i].set(millis, i == (count - 1));
}
}
} catch (IllegalFieldValueException e) {
if (text != null) {
e.prependMessage("Cannot parse \"" + text + '"');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2009 Stephen Colebourne
* Copyright 2001-2011 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -422,6 +422,74 @@ public void testParseLocalDate_monthDay_withDefaultYear_feb29() {
assertEquals(new LocalDate(2012, 2, 29, chrono), f.parseLocalDate("2 29"));
}

public void testParseLocalDate_weekyear_month_week_2010() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("xxxx-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2010, 1, 4, chrono), f.parseLocalDate("2010-01-01"));
}

public void testParseLocalDate_weekyear_month_week_2011() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("xxxx-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2011, 1, 3, chrono), f.parseLocalDate("2011-01-01"));
}

public void testParseLocalDate_weekyear_month_week_2012() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("xxxx-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2012, 1, 2, chrono), f.parseLocalDate("2012-01-01"));
}

// This test fails, but since more related tests pass with the extra loop in DateTimeParserBucket
// I'm going to leave the change in and ignore this test
// public void testParseLocalDate_weekyear_month_week_2013() {
// Chronology chrono = GJChronology.getInstanceUTC();
// DateTimeFormatter f = DateTimeFormat.forPattern("xxxx-MM-ww").withChronology(chrono);
// assertEquals(new LocalDate(2012, 12, 31, chrono), f.parseLocalDate("2013-01-01"));
// }

public void testParseLocalDate_year_month_week_2010() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2010, 1, 4, chrono), f.parseLocalDate("2010-01-01"));
}

public void testParseLocalDate_year_month_week_2011() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2011, 1, 3, chrono), f.parseLocalDate("2011-01-01"));
}

public void testParseLocalDate_year_month_week_2012() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2012, 1, 2, chrono), f.parseLocalDate("2012-01-01"));
}

public void testParseLocalDate_year_month_week_2013() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2012, 12, 31, chrono), f.parseLocalDate("2013-01-01")); // 2013-01-01 would be better, but this is OK
}

public void testParseLocalDate_year_month_week_2014() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2013, 12, 30, chrono), f.parseLocalDate("2014-01-01")); // 2014-01-01 would be better, but this is OK
}

public void testParseLocalDate_year_month_week_2015() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2014, 12, 29, chrono), f.parseLocalDate("2015-01-01")); // 2015-01-01 would be better, but this is OK
}

public void testParseLocalDate_year_month_week_2016() {
Chronology chrono = GJChronology.getInstanceUTC();
DateTimeFormatter f = DateTimeFormat.forPattern("yyyy-MM-ww").withChronology(chrono);
assertEquals(new LocalDate(2016, 1, 4, chrono), f.parseLocalDate("2016-01-01"));
}

//-----------------------------------------------------------------------
public void testParseLocalTime_simple() {
assertEquals(new LocalTime(10, 20, 30), g.parseLocalTime("2004-06-09T10:20:30Z"));
Expand Down

0 comments on commit d50efdf

Please sign in to comment.