Esempio n. 1
0
 @Override
 public final int diff(final Item it, final Collation coll, final InputInfo ii)
     throws QueryException {
   return it.type.isUntyped()
       ? coll == null ? Token.diff(string(), it.string(ii)) : coll.compare(string(), it.string(ii))
       : -it.diff(this, coll, ii);
 }
Esempio n. 2
0
 /**
  * Constructor.
  *
  * @param value value
  * @param type item type
  * @param ii input info
  * @throws QueryException query exception
  */
 private Dur(final byte[] value, final Type type, final InputInfo ii) throws QueryException {
   this(type);
   final String val = Token.string(value).trim();
   final Matcher mt = DUR.matcher(val);
   if (!mt.matches() || val.endsWith("P") || val.endsWith("T")) throw dateError(value, XDURR, ii);
   yearMonth(value, mt, ii);
   dayTime(value, mt, 6, ii);
 }
Esempio n. 3
0
 /**
  * Adds the time to the specified token builder.
  *
  * @param tb token builder
  */
 final void time(final TokenBuilder tb) {
   if (sec.remainder(DAYSECONDS).signum() == 0) return;
   tb.add('T');
   final long h = hou();
   if (h != 0) {
     tb.addLong(Math.abs(h));
     tb.add('H');
   }
   final long m = min();
   if (m != 0) {
     tb.addLong(Math.abs(m));
     tb.add('M');
   }
   final BigDecimal sc = sec();
   if (sc.signum() == 0) return;
   tb.add(Token.chopNumber(Token.token(sc.abs().toPlainString()))).add('S');
 }
Esempio n. 4
0
 @Override
 public final boolean eq(
     final Item it, final Collation coll, final StaticContext sc, final InputInfo ii)
     throws QueryException {
   return it.type.isUntyped()
       ? coll == null
           ? Token.eq(string(), it.string(ii))
           : coll.compare(string(), it.string(ii)) == 0
       : it.eq(this, coll, sc, ii);
 }
Esempio n. 5
0
  /**
   * Initializes the date format.
   *
   * @param d input
   * @param e example format
   * @param ii input info
   * @throws QueryException query exception
   */
  final void date(final byte[] d, final String e, final InputInfo ii) throws QueryException {
    final Matcher mt = DATE.matcher(Token.string(d).trim());
    if (!mt.matches()) throw dateError(d, e, ii);
    yea = toLong(mt.group(1), false, ii);
    // +1 is added to BC values to simplify computations
    if (yea < 0) yea++;
    mon = (byte) (Strings.toInt(mt.group(3)) - 1);
    day = (byte) (Strings.toInt(mt.group(4)) - 1);

    if (mon < 0 || mon >= 12 || day < 0 || day >= dpm(yea, mon)) throw dateError(d, e, ii);
    if (yea <= MIN_YEAR || yea > MAX_YEAR) throw DATERANGE_X_X.get(ii, type, chop(d, ii));
    zone(mt, 5, d, ii);
  }
Esempio n. 6
0
 @Override
 public byte[] string(final InputInfo ii) {
   final TokenBuilder tb = new TokenBuilder();
   final boolean ymd = yea != Long.MAX_VALUE;
   if (ymd) {
     if (yea <= 0) tb.add('-');
     prefix(tb, Math.abs(yea()), 4);
     tb.add('-');
     prefix(tb, mon(), 2);
     tb.add('-');
     prefix(tb, day(), 2);
   }
   if (hou >= 0) {
     if (ymd) tb.add('T');
     prefix(tb, hou(), 2);
     tb.add(':');
     prefix(tb, min(), 2);
     tb.add(':');
     if (sec.intValue() < 10) tb.add('0');
     tb.addExt(Token.chopNumber(Token.token(sec().abs().toPlainString())));
   }
   zone(tb);
   return tb.finish();
 }
Esempio n. 7
0
  /**
   * Initializes the time format.
   *
   * @param d input format
   * @param e expected format
   * @param ii input info
   * @throws QueryException query exception
   */
  final void time(final byte[] d, final String e, final InputInfo ii) throws QueryException {
    final Matcher mt = TIME.matcher(Token.string(d).trim());
    if (!mt.matches()) throw dateError(d, e, ii);

    hou = (byte) Strings.toInt(mt.group(1));
    min = (byte) Strings.toInt(mt.group(2));
    sec = toDecimal(mt.group(3), false, ii);
    if (min >= 60
        || sec.compareTo(BD60) >= 0
        || hou > 24
        || hou == 24 && (min > 0 || sec.compareTo(BigDecimal.ZERO) > 0)) throw dateError(d, e, ii);
    zone(mt, 5, d, ii);
    if (hou == 24) {
      hou = 0;
      add(DAYSECONDS);
    }
  }
Esempio n. 8
0
 @Override
 public final Duration toJava() {
   return ADate.DF.newDuration(Token.string(string(null)));
 }
Esempio n. 9
0
 /**
  * Prefixes the specified number of zero digits before a number.
  *
  * @param tb token builder
  * @param number number to be printed
  * @param zero maximum number of zero digits
  */
 static void prefix(final TokenBuilder tb, final long number, final int zero) {
   final byte[] t = Token.token(number);
   for (int i = t.length; i < zero; i++) tb.add('0');
   tb.add(t);
 }