コード例 #1
0
 /**
  * Get a component of the value. Returns null if the timezone component is requested and is not
  * present.
  */
 public AtomicValue getComponent(int component) throws XPathException {
   switch (component) {
     case Component.YEAR_ALLOWING_ZERO:
       return Int64Value.makeIntegerValue(year);
     case Component.YEAR:
       return Int64Value.makeIntegerValue(year > 0 ? year : year - 1);
     case Component.MONTH:
       return Int64Value.makeIntegerValue(month);
     case Component.DAY:
       return Int64Value.makeIntegerValue(day);
     case Component.HOURS:
       return Int64Value.makeIntegerValue(hour);
     case Component.MINUTES:
       return Int64Value.makeIntegerValue(minute);
     case Component.SECONDS:
       BigDecimal d = BigDecimal.valueOf(microsecond);
       d = d.divide(DecimalValue.BIG_DECIMAL_ONE_MILLION, 6, BigDecimal.ROUND_HALF_UP);
       d = d.add(BigDecimal.valueOf(second));
       return new DecimalValue(d);
     case Component.WHOLE_SECONDS: // (internal use only)
       return Int64Value.makeIntegerValue(second);
     case Component.MICROSECONDS:
       // internal use only
       return new Int64Value(microsecond);
     case Component.TIMEZONE:
       if (hasTimezone()) {
         return DayTimeDurationValue.fromMilliseconds(getTimezoneInMinutes() * 60 * 1000);
       } else {
         return null;
       }
     default:
       throw new IllegalArgumentException("Unknown component for dateTime: " + component);
   }
 }