Commit f84f9243 authored by Bernd Kiefer's avatar Bernd Kiefer
Browse files

Fix XsdDateTime Date constructor and add one for long

parent 1d6dd5b1
......@@ -54,14 +54,18 @@ public final class XsdDateTime extends XsdAnySimpleType {
public XsdDateTime(Date d) {
this.year = d.getYear();
this.month = d.getMonth();
this.day = d.getDay();
this.year = d.getYear() + 1900;
this.month = d.getMonth() + 1;
this.day = d.getDate();
this.hour = d.getHours();
this.minute = d.getMinutes();
this.second = d.getSeconds();
}
public XsdDateTime(long msSinceEpoch) {
this(new Date(msSinceEpoch));
}
/**
*
*/
......
......@@ -4,6 +4,9 @@ import static org.junit.Assert.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import org.junit.Test;
......@@ -95,6 +98,24 @@ public class XsdSimpleTypesTest {
assertEquals("\"-2009-01-12T01:00:03.456\"^^<xsd:dateTime>", xt.toString(true));
assertEquals("-2009-01-12T01:00:03.456", xt.toName());
assertEquals("\"-2009-01-12T01:00:03.456\"^^<http://www.w3.org/2001/XMLSchema#dateTime>", xt.toString(false));
// Month starts at zero, day at one!
Date d = new Date(2001-1900, 8, 11, 11, 30, 00);
assertEquals("\"2001-09-11T11:30:00.0\"^^<xsd:dateTime>",
new XsdDateTime(d).toString(true));
assertEquals("\"2001-09-11T11:30:00.0\"^^<xsd:dateTime>",
new XsdDateTime(d.getTime()).toString(true));
Calendar rightNow = new GregorianCalendar();
rightNow.set(Calendar.YEAR, 2001);
rightNow.set(Calendar.MONTH, Calendar.SEPTEMBER);
rightNow.set(Calendar.DAY_OF_MONTH, 11);
rightNow.set(Calendar.HOUR_OF_DAY, 11);
rightNow.set(Calendar.MINUTE, 30);
rightNow.set(Calendar.SECOND, 00);
assertEquals("\"2001-09-11T11:30:00.0\"^^<xsd:dateTime>",
new XsdDateTime(rightNow.getTimeInMillis()).toString(true));
}
@Test
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment