Exemple #1
0
 @Override
 public byte[] string(final InputInfo ii) {
   final TokenBuilder tb = new TokenBuilder();
   final int ss = sec.signum();
   if (mon < 0 || ss < 0) tb.add('-');
   date(tb);
   time(tb);
   if (mon == 0 && ss == 0) tb.add("T0S");
   return tb.finish();
 }
Exemple #2
0
 /**
  * Adds the time zone to the specified token builder.
  *
  * @param tb token builder
  */
 void zone(final TokenBuilder tb) {
   if (tz == Short.MAX_VALUE) return;
   if (tz == 0) {
     tb.add('Z');
   } else {
     tb.add(tz > 0 ? '+' : '-');
     prefix(tb, Math.abs(tz) / 60, 2);
     tb.add(':');
     prefix(tb, Math.abs(tz) % 60, 2);
   }
 }
Exemple #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');
 }
Exemple #4
0
 /**
  * Adds the date to the specified token builder.
  *
  * @param tb token builder
  */
 final void date(final TokenBuilder tb) {
   tb.add('P');
   final long y = yea();
   if (y != 0) {
     tb.addLong(Math.abs(y));
     tb.add('Y');
   }
   final long m = mon();
   if (m != 0) {
     tb.addLong(Math.abs(m));
     tb.add('M');
   }
   final long d = day();
   if (d != 0) {
     tb.addLong(Math.abs(d));
     tb.add('D');
   }
 }
Exemple #5
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();
 }
Exemple #6
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);
 }