| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.value; |
| 9 |
|
| 10 |
import net.sf.saxon.trans.XPathException; |
| 11 |
import net.sf.saxon.tree.util.FastStringBuffer; |
| 12 |
import net.sf.saxon.type.AtomicType; |
| 13 |
import net.sf.saxon.type.BuiltInAtomicType; |
| 14 |
import net.sf.saxon.type.ConversionResult; |
| 15 |
import net.sf.saxon.type.ValidationFailure; |
| 16 |
|
| 17 |
import java.util.regex.Matcher; |
| 18 |
import java.util.regex.Pattern; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public class GMonthDayValue extends GDateValue { |
| 25 |
|
| 26 |
private static Pattern regex = |
| 27 |
Pattern.compile("--([0-9][0-9]-[0-9][0-9])(Z|[+-][0-9][0-9]:[0-9][0-9])?"); |
| 28 |
|
| 29 |
private GMonthDayValue() { |
| 30 |
} |
| 31 |
|
| 32 |
public static ConversionResult makeGMonthDayValue(CharSequence value) { |
| 33 |
Matcher m = regex.matcher(Whitespace.trimWhitespace(value)); |
| 34 |
if (!m.matches()) { |
| 35 |
return new ValidationFailure("Cannot convert '" + value + "' to a gMonthDay"); |
| 36 |
} |
| 37 |
GMonthDayValue g = new GMonthDayValue(); |
| 38 |
String base = m.group(1); |
| 39 |
String tz = m.group(2); |
| 40 |
String date = "2000-" + base + (tz == null ? "" : tz); |
| 41 |
g.typeLabel = BuiltInAtomicType.G_MONTH_DAY; |
| 42 |
return setLexicalValue(g, date, true); |
| 43 |
} |
| 44 |
|
| 45 |
public GMonthDayValue(byte month, byte day, int tz) { |
| 46 |
this(month, day, tz, BuiltInAtomicType.G_MONTH_DAY); |
| 47 |
} |
| 48 |
|
| 49 |
public GMonthDayValue(byte month, byte day, int tz, AtomicType type) { |
| 50 |
this.year = 2000; |
| 51 |
this.month = month; |
| 52 |
this.day = day; |
| 53 |
setTimezoneInMinutes(tz); |
| 54 |
this.typeLabel = type; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public AtomicValue copyAsSubType(AtomicType typeLabel) { |
| 64 |
GMonthDayValue v = new GMonthDayValue(month, day, getTimezoneInMinutes()); |
| 65 |
v.typeLabel = typeLabel; |
| 66 |
return v; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public BuiltInAtomicType getPrimitiveType() { |
| 77 |
return BuiltInAtomicType.G_MONTH_DAY; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
public CharSequence getPrimitiveStringValue() { |
| 82 |
|
| 83 |
FastStringBuffer sb = new FastStringBuffer(FastStringBuffer.C16); |
| 84 |
|
| 85 |
sb.append("--"); |
| 86 |
appendTwoDigits(sb, month); |
| 87 |
sb.append('-'); |
| 88 |
appendTwoDigits(sb, day); |
| 89 |
|
| 90 |
if (hasTimezone()) { |
| 91 |
appendTimezone(sb); |
| 92 |
} |
| 93 |
|
| 94 |
return sb; |
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public CalendarValue add(DurationValue duration) throws XPathException { |
| 109 |
XPathException err = new XPathException("Cannot add a duration to an xs:gMonthDay"); |
| 110 |
err.setErrorCode("XPTY0004"); |
| 111 |
throw err; |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public CalendarValue adjustTimezone(int tz) { |
| 123 |
DateTimeValue dt = (DateTimeValue) toDateTime().adjustTimezone(tz); |
| 124 |
return new GMonthDayValue(dt.getMonth(), dt.getDay(), dt.getTimezoneInMinutes()); |
| 125 |
} |
| 126 |
} |
| 127 |
|