Package ch.agent.t2.time

Examples of ch.agent.t2.time.Day


 
  public void testGetLastValue_1() {
    try {
      Series<Double> s = makeSeries(makeTimeSeries());
      TimeDomain dom = s.getTimeDomain();
      Range range = new Range(dom.time("2011-05-15"), dom.time("2011-07-15"));
      TimeAddressable<Double> ts = s.getValues(range);
      Observation<Double> obs = ts.getLast(dom.time("2011-06-01"));
      assertEquals("2011-06-01", obs.getTime().toString());
    } catch (Exception e) {
      fail(e.toString());
View Full Code Here


 
  public void testGetLastValue_3() {
    try {
      Series<Double> s = makeSeries(makeTimeSeries());
      TimeDomain dom = s.getTimeDomain();
      Range range = new Range(dom.time("2011-05-15"), dom.time("2011-07-15"));
      TimeAddressable<Double> ts = s.getValues(range);
      Observation<Double> obs = ts.getLast(dom.time("2011-05-31"));
      assertNull(obs);
    } catch (Exception e) {
      fail(e.toString());
View Full Code Here

  public void testMoreSeries() {
    try {
      UpdatableSeries<Double> s = makeSeries(makeTimeSeries2()).edit();
      TimeAddressable<Double> ts = s.getValues(null);
      Range range = new Range(s.getTimeDomain(), "2011-05-01", "2011-07-03", Adjustment.NONE);
      assertEquals(64, range.getSize());
      assertEquals(range, ts.getRange());
      assertEquals(range, s.getRange());
    } catch (Exception e) {
      fail(e.toString());
    }
View Full Code Here

   * Reduce range with setRange().
   */
  public void testGetSeries04() {
    try {
      UpdatableSeries<Double> s = db.getSeries(SERIES, true).typeCheck(Double.class).edit();
      s.setRange(new Range(Day.DOMAIN.time("2011-05-02"), Day.DOMAIN.time("2011-06-30")));
      assertEquals("[2011-05-02, 2011-06-30]", s.getRange().toString());
    } catch (Exception e) {
      fail(e.toString());
    }
  }
View Full Code Here

      if (DUMP)
        System.out.println(t.getTimeDomain() + " " + s.getRange());
      assertEquals(9, s.getRange().getSize());
      if (DUMP)
        System.out.println(s.getValues(null));
      boolean done = s.setRange(new Range(t.getTimeDomain(), "2011-03-12", "2011-03-17", Adjustment.NONE));
      if (DUMP)
        System.out.println(s.getValues(null));
      assertFalse(done);
      done = s.setRange(new Range(t.getTimeDomain(), "2011-03-12", "2011-03-16", Adjustment.NONE));
      s.applyUpdates();
      if (DUMP)
        System.out.println(s.getValues(null));
      assertEquals(3, s.getRange().getSize());
      done = s.setRange(null);
View Full Code Here

    }
    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);
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

    long index = m.asLong() * 24L * 3600000L;
    return index = index - epoch;
  }
 
  private static long dayOrLessToMillisecSinceEpoch (TimeIndex t) throws T2Exception {
    long index = new SystemTime(t.toString()).asLong();
    return index - epoch;
  }
View Full Code Here

  private static final String SELECT_RANGE =
    "select min(date), max(date) from " + DB.VALUE_DOUBLE + " where series = ?";
  @Override
  public Range getRange(Series<Double> series) throws T2DBException {
    Range range = null;
    TimeDomain timeDomain = series.getTimeDomain();
    try {
      select_range = open(SELECT_RANGE, series, select_range);
      select_range.setInt(1, getId(series));
      ResultSet rs = select_range.executeQuery();
      if (rs.next()) {
        range = new Range(timeDomain.timeFromOffset(rs.getInt(1)), timeDomain.timeFromOffset(rs.getInt(2)));
        if (rs.wasNull())
          range = null;
      }
    } catch (Exception e) {
      throw T2DBJMsg.exception(e, J.J50122, series.getName(true));
View Full Code Here

        select_first_double2.setInt(1, sid);
        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

TOP

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

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.