Examples of TimeParts


Examples of ch.agent.t2.time.TimeParts

      subPeriod = (int) (orig - time * sz); // can cast because getSize is int
    }
    if (basePeriodPattern != null)
      time = basePeriodPattern.expandIndex(time);
   
    TimeParts tp = new TimeParts();
    Resolution unit = this.baseUnit;
    switch (unit) {
    case YEAR:
      tp.setYear(time);
      break;
    case MONTH:
      tp.setYear(time / 12);
      tp.setMonth((int) (time - tp.getYear() * 12) + 1);
      break;
    case DAY:
      TimeTools.computeYMD(time, tp);
      break;
    case HOUR:
      long days = time / 24;
      tp.setHour((int) (time - days * 24));
      TimeTools.computeYMD(days, tp);
      break;
    case MIN:
      days = time/ (24 * 60);
      long minutes = time - days * 24 * 60;
      tp.setHour((int)(minutes / 60));
      tp.setMin((int) (minutes - tp.getHour() * 60));
      TimeTools.computeYMD(days, tp);
      break;
    case SEC:
      days = time / (24 * 60 * 60);
      long seconds = time - days * 24L * 60L * 60L;
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    case MSEC:
      days = time / (24L * 60L * 60L * 1000L);
      long millis = time - days * 24L * 60L * 60L * 1000L;
      seconds = millis / 1000L;
      tp.setUsec((int) (millis - seconds * 1000L) * 1000);
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    case USEC:
      days = time / (24L * 60L * 60L * 1000000L);
      long micros = time - days * 24L * 60L * 60L * 1000000L;
      seconds = micros / 1000000L;
      tp.setUsec((int) (micros - seconds * 1000000L));
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    default:
      throw new RuntimeException("bug: " + unit.name());
    }
   
    if (subPeriodPattern != null) {
      // there is something to do even when subPeriod = 0
      subPeriodPattern.fillInSubPeriod(subPeriod, tp);
    }
   
    // make sure nothing is negative
    if (tp.anyNegative())
      throw new RuntimeException(String.format("(bug) time=%d %s", time, tp.toString()));
     
    return tp;
  }
View Full Code Here

Examples of ch.agent.t2.time.TimeParts

   * @throws T2Exception
   */
  protected Time2(TimeDomain domain, long year, int month, int day, int hour, int min, int sec,
      int usec, Adjustment adjust) throws T2Exception {
    this(domain);
    TimeParts tp = new TimeParts();
    tp.setYear(year);
    tp.setMonth(month);
    tp.setDay(day);
    tp.setHour(hour);
    tp.setMin(min);
    tp.setSec(sec);
    tp.setUsec(usec);
    set(tp, adjust);
  }
View Full Code Here

Examples of ch.agent.t2.time.TimeParts

   * @param date a non-null string
   * @param adjust a non-null allowed adjustment mode
   * @throws T2Exception
   */
  private void set(String date, Adjustment adjust) throws T2Exception {
    TimeParts tp = domain.scan(date);
    set(tp, adjust);
  }
View Full Code Here

Examples of ch.agent.t2.time.TimeParts

   * @throws T2Exception
   */
  protected Time2(TimeDomain domain, long year, int month, int day, int hour, int min, int sec,
      int usec, Adjustment adjust) throws T2Exception {
    this(domain);
    TimeParts tp = new TimeParts();
    tp.setYear(year);
    tp.setMonth(month);
    tp.setDay(day);
    tp.setHour(hour);
    tp.setMin(min);
    tp.setSec(sec);
    tp.setUsec(usec);
    set(tp, adjust);
  }
View Full Code Here

Examples of ch.agent.t2.time.TimeParts

   * @param date a non-null string
   * @param adjust a non-null allowed adjustment mode
   * @throws T2Exception
   */
  private void set(String date, Adjustment adjust) throws T2Exception {
    TimeParts tp = domain.scan(date);
    set(tp, adjust);
  }
View Full Code Here

Examples of ch.agent.t2.time.TimeParts

      subPeriod = (int) (orig - time * sz); // can cast because getSize is int
    }
    if (basePeriodPattern != null)
      time = basePeriodPattern.expandIndex(time);
   
    TimeParts tp = new TimeParts();
    Resolution unit = this.baseUnit;
    switch (unit) {
    case YEAR:
      tp.setYear(time);
      break;
    case MONTH:
      tp.setYear(time / 12);
      tp.setMonth((int) (time - tp.getYear() * 12) + 1);
      break;
    case DAY:
      TimeTools.computeYMD(time, tp);
      break;
    case HOUR:
      long days = time / 24;
      tp.setHour((int) (time - days * 24));
      TimeTools.computeYMD(days, tp);
      break;
    case MIN:
      days = time/ (24 * 60);
      long minutes = time - days * 24 * 60;
      tp.setHour((int)(minutes / 60));
      tp.setMin((int) (minutes - tp.getHour() * 60));
      TimeTools.computeYMD(days, tp);
      break;
    case SEC:
      days = time / (24 * 60 * 60);
      long seconds = time - days * 24L * 60L * 60L;
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    case MSEC:
      days = time / (24L * 60L * 60L * 1000L);
      long millis = time - days * 24L * 60L * 60L * 1000L;
      seconds = millis / 1000L;
      tp.setUsec((int) (millis - seconds * 1000L) * 1000);
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    case USEC:
      days = time / (24L * 60L * 60L * 1000000L);
      long micros = time - days * 24L * 60L * 60L * 1000000L;
      seconds = micros / 1000000L;
      tp.setUsec((int) (micros - seconds * 1000000L));
      TimeTools.computeYMD(days, tp);
      TimeTools.computeHMS(seconds, tp);
      break;
    default:
      throw new RuntimeException("bug: " + unit.name());
    }
   
    if (subPeriodPattern != null) {
      // there is something to do even when subPeriod = 0
      subPeriodPattern.fillInSubPeriod(subPeriod, tp);
    }
   
    // make sure nothing is negative
    if (tp.anyNegative())
      throw new RuntimeException(String.format("(bug) time=%d %s", time, tp.toString()));
     
    return tp;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.