mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
MNT-19261/REPO-3324 ISO8601DateFormat now handles Julian dates
This commit is contained in:
@@ -27,10 +27,8 @@ import java.util.TimeZone;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.IllegalInstantException;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.*;
|
||||
import org.joda.time.chrono.GJChronology;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
@@ -215,7 +213,8 @@ public class ISO8601DateFormat
|
||||
DateTimeZone dtz = DateTimeZone.forTimeZone(timezone);
|
||||
try
|
||||
{
|
||||
DateTime dateTime = new DateTime(isoDate, dtz);
|
||||
Chronology chrono = GJChronology.getInstance(dtz);
|
||||
DateTime dateTime = new DateTime(isoDate, chrono);
|
||||
Date date = dateTime.toDate();
|
||||
return date;
|
||||
}
|
||||
|
@@ -51,6 +51,63 @@ public class ISO8601DateFormatTest extends TestCase
|
||||
assertEquals(date2, dateAfter2);
|
||||
}
|
||||
|
||||
public void test19000101()
|
||||
{
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
String test = "1900-01-01";
|
||||
Date date = ISO8601DateFormat.parse(test);
|
||||
String strDate = ISO8601DateFormat.format(date);
|
||||
Date dateAfter = ISO8601DateFormat.parse(strDate);
|
||||
assertEquals(date, dateAfter);
|
||||
}
|
||||
|
||||
public void test18991231()
|
||||
{
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
String test = "1899-12-31";
|
||||
Date date = ISO8601DateFormat.parse(test);
|
||||
String strDate = ISO8601DateFormat.format(date);
|
||||
Date dateAfter = ISO8601DateFormat.parse(strDate);
|
||||
assertEquals(date, dateAfter);
|
||||
}
|
||||
|
||||
public void test18800207()
|
||||
{
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
String test = "1880-02-07";
|
||||
Date date = ISO8601DateFormat.parse(test);
|
||||
String strDate = ISO8601DateFormat.format(date);
|
||||
Date dateAfter = ISO8601DateFormat.parse(strDate);
|
||||
assertEquals(date, dateAfter);
|
||||
}
|
||||
|
||||
public void test15000207() // MNT-19261 JULIAN CALENDAR
|
||||
{
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
String test = "1500-02-07";
|
||||
Date date = ISO8601DateFormat.parse(test);
|
||||
String strDate = ISO8601DateFormat.format(date); // 1500-02-07T00:00:00.000Z
|
||||
Date dateAfter = ISO8601DateFormat.parse(strDate);
|
||||
// Before MNT-19261 Expected Wed Jan 29 03:06:28 GMT 1500 Actual Mon Jan 20 03:06:28 GMT 1500
|
||||
// After MNT-19261 Expected and Actual: Fri Feb 07 00:00:00 GMT 1500
|
||||
assertEquals(date, dateAfter);
|
||||
}
|
||||
|
||||
public void test10661014() // Battle of Hastings
|
||||
{
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
|
||||
|
||||
String test = "10661014";
|
||||
Date date = ISO8601DateFormat.parse(test);
|
||||
String strDate = ISO8601DateFormat.format(date);
|
||||
Date dateAfter = ISO8601DateFormat.parse(strDate);
|
||||
assertEquals(date, dateAfter);
|
||||
}
|
||||
|
||||
public void testFormat()
|
||||
{
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("PST")); // Any timezone other than UTC
|
||||
|
Reference in New Issue
Block a user