1 package net.sf.saxon.functions; 2 import net.sf.saxon.expr.Expression; 3 import net.sf.saxon.expr.StaticContext; 4 import net.sf.saxon.expr.XPathContext; 5 import net.sf.saxon.om.Item; 6 import net.sf.saxon.trans.XPathException; 7 import net.sf.saxon.type.Type; 8 import net.sf.saxon.value.DateTimeValue; 9 import net.sf.saxon.value.DateValue; 10 import net.sf.saxon.value.SecondsDurationValue; 11 import net.sf.saxon.value.TimeValue; 12 13 19 20 21 public class CurrentDateTime extends SystemFunction { 22 23 27 28 public Expression preEvaluate(StaticContext env) { 29 return this; 30 } 31 32 35 36 public int getIntrinsicDependencies() { 37 return 0; 41 } 42 43 46 47 public Item evaluateItem(XPathContext context) throws XPathException { 48 DateTimeValue dt = DateTimeValue.getCurrentDateTime(context); 49 int targetType = getItemType().getPrimitiveType(); 50 switch (targetType) { 51 case Type.DATE_TIME: 52 return dt; 53 case Type.DATE: 54 return (DateValue)dt.convert(Type.DATE, context); 55 case Type.TIME: 56 return (TimeValue)dt.convert(Type.TIME, context); 57 case Type.DAY_TIME_DURATION: 58 case Type.DURATION: 59 return dt.getComponent(Component.TIMEZONE); 60 default: 61 throw new IllegalArgumentException ("Wrong target type for current date/time"); 62 } 63 } 64 65 68 69 public static SecondsDurationValue getImplicitTimezone(XPathContext context) throws XPathException { 70 DateTimeValue dt = DateTimeValue.getCurrentDateTime(context); 71 return (SecondsDurationValue)dt.getComponent(Component.TIMEZONE); 72 } 73 74 } 75 76 77 78 79 | Popular Tags |