Package ch.agent.t2.time

Examples of ch.agent.t2.time.SubPeriodPattern


    db.commit();
  }

  public void testCreateSeries() {
    try {
      TimeDomain dom = Day.DOMAIN;
      UpdatableSeries<Double> s = db.getUpdatableSeries(SERIES, true).typeCheck(Double.class);
      TimeAddressable<Double> ts = TimeSeriesFactory.make(dom, Double.class);
      ts.put(dom.time("2011-05-01")201105.01);
      ts.put(dom.time("2011-05-02")201105.02);
      ts.put(dom.time("2011-06-01")201106.01);
      ts.put(dom.time("2011-06-30")201106.30);
      ts.put(dom.time("2011-07-01")201107.01);
      s.setValues(ts);
      s.applyUpdates();
      assertEquals("[2011-05-01, 2011-07-01]", s.getRange().toString());
    } catch (Exception e) {
      fail(e.toString());
View Full Code Here


        return 0;
    } else {
      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

        select_first_double2.setInt(2, sid);
        rs = select_first_double2.executeQuery();
      }
      if (rs.next()) {
        TimeDomain dom = time == null ? series.getTimeDomain() : time.getTimeDomain();
        TimeIndex t = dom.timeFromOffset(rs.getInt(1));
        obs = new Observation<Double>(t, rs.getDouble(2));
      }
    } catch (Exception e) {
        throw T2DBJMsg.exception(e, J.J50123, series.getName(true), time.toString());
    } finally {
View Full Code Here

        select_last_double2.setInt(2, sid);
        rs = select_last_double2.executeQuery();
      }
      if (rs.next()) {
        TimeDomain dom = time == null ? series.getTimeDomain() : time.getTimeDomain();
        TimeIndex t = dom.timeFromOffset(rs.getInt(1));
        obs = new Observation<Double>(t, rs.getDouble(2));
      }
    } catch (Exception e) {
        throw T2DBJMsg.exception(e, J.J50124, series.getName(true), time.toString());
    } finally {
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

    TimeDomain contextDomain = context.getTimeDomain();
    if (beginExpr == null) {
      return new Range(contextDomain);
    } else {
      // be more permissive with context and fix ranges invalidated by conversion
      TimeIndex begin = beginExpr.getDate(context);
      TimeIndex end = endExpr.getDate(context);
      if (begin == null || end == null) // (consequence of empty context range when context needed)
        return new Range(contextDomain);
      else if (begin.compareTo(end) > 0 && (beginExpr.needContext() || endExpr.needContext()))
        return new Range(contextDomain);
      else {
View Full Code Here

       * 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

TOP

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

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.