Package ch.agent.t2.time

Examples of ch.agent.t2.time.TimeIndex


       * So for higher resolutions, offsets are applied in the context
       * domain.
       */
      if (domain.compareResolutionTo(Resolution.DAY) < 0) {
        // apply the offset in the DAILY domain
        TimeIndex t = addOffset(TimeUtil.now(Day.DOMAIN));
        return t.convert(domain, Adjustment.DOWN);
      } else {
        // apply the offset in the context domain
        return addOffset(TimeUtil.now(domain));
      }
    }
View Full Code Here


   *
   * @param begin
   * @param keepBegin
   */
  private void eVRTodayLiteral(TimeDomain domain, DayExpression begin, boolean keepBegin) throws T2Exception {
    TimeIndex t = begin.getDate(domain);
    if (t.compareTo(time) > 0) {
      if (keepBegin)
        setTime(t);
      else {
        long diff = t.asLong() - time.asLong();
        long test = begin.offset + diff;
        if (Math.abs(test) <= Integer.MAX_VALUE)
          begin.incr((int)diff);
        else // change from TODAY to LITERAL
          begin.setTime(time);
View Full Code Here

   *
   * @param begin
   * @param keepBegin
   */
  private void eVRLiteralToday(TimeDomain domain, DayExpression begin, boolean keepBegin) throws T2Exception {
    TimeIndex t = getDate(domain);
    if (begin.time.compareTo(t) > 0) {
      if (keepBegin) {
        long diff = begin.time.asLong() - t.asLong();
        long test = offset + diff;
        if (Math.abs(test) <= Integer.MAX_VALUE)
          incr((int) diff);
        else
          // change from TODAY to LITERAL
View Full Code Here

        adjustment);
  }
 
  // convert "difficult" calendars to Day and increase resolution to milliseconds
  private static long yearOrMonthToMillisecSinceEpoch (long year, int month) throws T2Exception {
    TimeIndex m = Day.DOMAIN.time(year, month, 1, 0, 0, 0, 0, Adjustment.NONE);
    long index = m.asLong() * 24L * 3600000L;
    return index = index - epoch;
  }
View Full Code Here

   * @param domain a non-null time domain
   * @return the current time
   */
  public static TimeIndex now(TimeDomain domain) {
    try {
      TimeIndex t = new SystemTime();
      return t.convert(domain, Adjustment.DOWN);
    } catch (T2Exception e) {
      // should not occur because of the adjustment
      throw new RuntimeException(e);
    }
  }
View Full Code Here

      int compareResols = getTimeDomain().getResolution().compareTo(otherTime.getTimeDomain().getResolution());
      if (compareResols == 0) {
        // convert  both to unrestricted domain
        TimeDomainDefinition def = new TimeDomainDefinition(null, getTimeDomain().getResolution(), 0L);
        TimeDomain unrestrictedDomain = TimeDomainManager.getFactory().get(def, true);
        TimeIndex converted = convertOrThrowRTE(unrestrictedDomain, this);
        TimeIndex otherConverted = convertOrThrowRTE(unrestrictedDomain, otherTime);
        return converted.compareTo(otherConverted);
      } else if (compareResols < 0) {
        // convert  both to highest resolution
        TimeDomainDefinition def = new TimeDomainDefinition(null, otherTime.getTimeDomain().getResolution(), 0L);
        TimeDomain unrestrictedDomain = TimeDomainManager.getFactory().get(def, true);
        TimeIndex converted = convertOrThrowRTE(unrestrictedDomain, this);
        return converted.compareTo(otherTime);
      } else {
        // convert  both to highest resolution
        TimeDomainDefinition def = new TimeDomainDefinition(null, getTimeDomain().getResolution(), 0L);
        TimeDomain unrestrictedDomain = TimeDomainManager.getFactory().get(def, true);
        TimeIndex otherConverted = convertOrThrowRTE(unrestrictedDomain, otherTime);
        return compareTo(otherConverted);
      }
    }
  }
View Full Code Here

    if (month == 0) {
      month = 1;
      daysInPeriod = isLeap(year) ? 366 : 365;
    } else
      daysInPeriod = daysInMonth(year, month);
    TimeIndex t = new Day(year, month, 1);
    DayOfWeek firstOfPeriod = t.getDayOfWeek();
    int workRank = rank;
    if (workRank < 0)
      workRank = max; // try the max
    int week1Offset = name.ordinal() - firstOfPeriod.ordinal();
    if (week1Offset < 0)
View Full Code Here

      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

   * @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

   * @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

TOP

Related Classes of ch.agent.t2.time.TimeIndex

Copyright © 2018 www.massapicom. 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.