this.year = months / 12; this.month = months % 12;
	public YearMonthDurationValue(String str) throws XPathException {		super();		// format is: [+|-]PnYnM		if (str.length() < 3)			throw new XPathException("Type error: xs:duration should start with [+|-]P");		char ch;		StringBuffer buf = new StringBuffer();		int p = 0;		int state = 0;		int value = -1;		while (p < str.length()) {			ch = str.charAt(p);			switch (ch) {				case '-' :					if (state > 0)						throw new XPathException(							"Type error in xs:yearMonthDuration: "								+ str								+ ": - is not allowed here");					negative = true;					break;				case 'P' :					if (state > 0)						throw new XPathException(							"Type error in xs:yearMonthDuration: "								+ str								+ ": P is not allowed here");					state++;					break;				case 'Y' :					if (state != 1 || value < 0)						throw new XPathException(							"Type error in xs:yearMonthDuration: "								+ str								+ ": Y is not allowed to occur here");					year = value;					value = -1;					state++;					break;				case 'M' :					if (state > 2 || value < 0)						throw new XPathException(							"Type error in xs:yearMonthDuration: "								+ str								+ ": M is not allowed to occur here");					month = value;					state++;					value = -1;					break;				case '1' :				case '2' :				case '3' :				case '4' :				case '5' :				case '6' :				case '7' :				case '8' :				case '9' :				case '0' :					if (state < 1)						throw new XPathException(							"Type error in xs:yearMonthDuration: "								+ str								+ ": numeric value not allowed at this position");					buf.append(ch);					p++;					while (p < str.length()) {						ch = str.charAt(p);						if (ch == '1'							|| ch == '2'							|| ch == '3'							|| ch == '4'							|| ch == '5'							|| ch == '6'							|| ch == '7'							|| ch == '8'							|| ch == '9'							|| ch == '0')							buf.append(ch);						else {							value = Integer.parseInt(buf.toString());							buf.setLength(0);							p--;							break;						}						p++;					}					break;			}			p++;		}	}