1 package net.sf.saxon.value; 2 import net.sf.saxon.ConversionContext; 3 import net.sf.saxon.trans.XPathException; 4 5 import java.util.GregorianCalendar ; 6 7 8 9 12 13 public abstract class CalendarValue extends AtomicValue implements Comparable { 14 15 protected GregorianCalendar calendar; 17 protected boolean zoneSpecified; 18 19 public abstract CalendarValue add(DurationValue duration) throws XPathException; 20 21 29 30 public SecondsDurationValue subtract(CalendarValue other, ConversionContext context) throws XPathException { 31 CalendarValue v1 = this; 32 CalendarValue v2 = other; 33 if (v1.zoneSpecified != v2.zoneSpecified) { 34 SecondsDurationValue tz = SecondsDurationValue.fromMilliseconds(context.getImplicitTimezone() * 60000); 35 if (!v1.zoneSpecified) { 36 v1 = v1.setTimezone(tz); 37 } 38 if (!v2.zoneSpecified) { 39 v2 = v2.setTimezone(tz); 40 } 41 } 42 long t1 = v1.calendar.getTimeInMillis(); 43 long t2 = v2.calendar.getTimeInMillis(); 44 long diff = (t1 - t2); 45 return SecondsDurationValue.fromMilliseconds(diff); 46 } 47 48 54 55 public abstract CalendarValue removeTimezone() throws XPathException; 56 57 63 64 public abstract CalendarValue setTimezone(SecondsDurationValue tz) throws XPathException; 65 66 70 71 public abstract int compareTo(CalendarValue other, ConversionContext conversion); 72 } 73 74 92 | Popular Tags |