Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding calendar field validation to CalendarParser#parse #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @(#)$Id$
*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*
*/
package com.sun.msv.datatype.xsd.datetime;

Expand All @@ -14,34 +14,42 @@

/**
* Parses XML Schema date/time related types into {@link java.util.Calendar}.
*
*
* @author
* Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
*/
public final class CalendarParser extends AbstractCalendarParser {
public static GregorianCalendar parse( String format, String value ) throws IllegalArgumentException {
CalendarParser parser = new CalendarParser(format,value);
parser.parse();
return parser.cal;

GregorianCalendar cal = parser.cal;

// fail on invalid dates
cal.setLenient(false);
cal.getTimeInMillis();

return cal;
}

// this version is faster than new GregorianCalendar()
// which involves in setting the current time.
private final GregorianCalendar cal = new GregorianCalendar(0,0,0);

private CalendarParser( String format, String value ) {
super(format,value);

// erase all the fields to remove any trace of the current time.
cal.clear(Calendar.YEAR);
cal.clear(Calendar.MONTH);
cal.clear(Calendar.DAY_OF_MONTH);
}

protected void parseFractionSeconds() {
cal.set(Calendar.MILLISECOND,parseInt(1,3));
skipDigits();
}

protected void setTimeZone( java.util.TimeZone tz ) {
cal.setTimeZone(tz);
}
Expand Down