public DateTimeValue(String dateTime) throws XPathException { Perl5Util util = new Perl5Util(); if (!util.match(regex, dateTime)) throw new XPathException( "Type error: string " + dateTime + " cannot be cast into an xs:dateTime"); String part = util.group(1); int era = 1; if (part != null && part.equals("-")) era = -1; part = util.group(2); int year = Integer.parseInt(part) * era; part = util.group(3); int month = Integer.parseInt(part); part = util.group(4); int day = Integer.parseInt(part); part = util.group(5); int hour = Integer.parseInt(part); part = util.group(6); int minutes = Integer.parseInt(part); part = util.group(7); int seconds = Integer.parseInt(part); part = util.group(9); int millis = 0; if (part != null) { if (part.length() < 3) part += "00"; if (part.length() > 3) part = part.substring(0, 3); millis = Integer.parseInt(part); } part = util.group(10); if (part != null && part.length() > 0 && (!part.equals("Z"))) { if (!util.match(tzre, part)) throw new XPathException("Type error: error in  timezone: " + part); explicitTimeZone = true; part = util.group(2); tzOffset = Integer.parseInt(part) * 60; part = util.group(3); if (part != null) { int tzminute = Integer.parseInt(part); tzOffset += tzminute; } part = util.group(1); if (part.equals("-")) tzOffset *= -1; } SimpleTimeZone zone = new SimpleTimeZone(tzOffset * 60000, "LLL"); if(explicitTimeZone) calendar = new GregorianCalendar(zone); else { calendar = new GregorianCalendar(); tzOffset = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000; } calendar.setLenient(false); calendar.set(year, month - 1, day, hour, minutes, seconds); calendar.set(Calendar.MILLISECOND, millis); if(explicitTimeZone) calendar.set(Calendar.ZONE_OFFSET, tzOffset * 60000); try { date = calendar.getTime(); } catch (Exception e) { throw new XPathException( "Type error: string " + dateTime + " cannot be cast into an xs:dateTime"); }
public DateTimeValue() { calendar = new GregorianCalendar(); tzOffset = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000; date = calendar.getTime();
	public DateTimeValue(String dateTime) throws XPathException {		Perl5Util util = new Perl5Util();		if (!util.match(regex, dateTime))			throw new XPathException(				"Type error: string " + dateTime + " cannot be cast into an xs:dateTime");		String part = util.group(1);		int era = 1;		if (part != null && part.equals("-"))			era = -1;		part = util.group(2);		int year = Integer.parseInt(part) * era;		part = util.group(3);		int month = Integer.parseInt(part);		part = util.group(4);		int day = Integer.parseInt(part);		part = util.group(5);		int hour = Integer.parseInt(part);		part = util.group(6);		int minutes = Integer.parseInt(part);		part = util.group(7);		int seconds = Integer.parseInt(part);		part = util.group(9);		int millis = 0;		if (part != null) {			if (part.length() < 3)				part += "00";			if (part.length() > 3)				part = part.substring(0, 3);			millis = Integer.parseInt(part);		}		part = util.group(10);		if (part != null && part.length() > 0 && (!part.equals("Z"))) {			if (!util.match(tzre, part))				throw new XPathException("Type error: error in  timezone: " + part);			explicitTimeZone = true;			part = util.group(2);			tzOffset = Integer.parseInt(part) * 60;			part = util.group(3);			if (part != null) {				int tzminute = Integer.parseInt(part);				tzOffset += tzminute;			}			part = util.group(1);			if (part.equals("-"))				tzOffset *= -1;		}		SimpleTimeZone zone = new SimpleTimeZone(tzOffset * 60000, "LLL");		if(explicitTimeZone)			calendar = new GregorianCalendar(zone);		else {			calendar = new GregorianCalendar();			tzOffset = (calendar.get(Calendar.ZONE_OFFSET) + calendar.get(Calendar.DST_OFFSET)) / 60000;		}		calendar.setLenient(false);		calendar.set(year, month - 1, day, hour, minutes, seconds);		calendar.set(Calendar.MILLISECOND, millis);		if(explicitTimeZone)			calendar.set(Calendar.ZONE_OFFSET, tzOffset * 60000);		try {			date = calendar.getTime();		} catch (Exception e) {			throw new XPathException(				"Type error: string " + dateTime + " cannot be cast into an xs:dateTime");		}	}