Package ch.agent.t2.time

Examples of ch.agent.t2.time.Day


  }
 
  public void testGetFirstValue_5() {
    try {
      Series<Double> s = makeSeries(makeTimeSeries2());
      TimeIndex t = s.getTimeDomain().time("2011-06-03");
      assertEquals(201106.30,  s.getFirstObservation(t).getValue());
    } catch (Exception e) {
      fail(e.toString());
    }
  }
View Full Code Here


  public void testLargeGap_2() {
    try {
      // first get the maximum allowed allowed gap
      Series<Double> s = makeSeriesWithGap("2011-05-01", "2011-05-02");
      int maxGap = s.getValues(null).asIndexable().getMaxGap();
      TimeIndex date1 = s.getFirstObservation(null).getTime();
      TimeIndex date2 = date1.add(maxGap + 2); // the maximum allowed gap
     
      Series<Double> s2 = makeSeriesWithGap(date1.toString(), date2.toString());
      // force non-sparse time series (should fail because it creates a gap too large by 1)
      s2.getValues(null).asIndexable();
    } catch (Exception e) {
      fail(e.toString());
    }
View Full Code Here

  public void testLargeGap_3() {
    try {
      // first get the maximum allowed allowed gap
      Series<Double> s = makeSeriesWithGap("2011-05-01", "2011-05-02");
      int maxGap = s.getValues(null).asIndexable().getMaxGap();
      TimeIndex date1 = s.getFirstObservation(null).getTime();
      TimeIndex date2 = date1.add(maxGap + 2 + 1); // a gap too large by 1
     
      Series<Double> s2 = makeSeriesWithGap(date1.toString(), date2.toString());
      // force non-sparse time series (should fail because it creates a gap too large by 1)
      s2.getValues(null).asIndexable();
      expectException();
    } catch (Exception e) {
      assertException(e, K.T5019);
View Full Code Here

  }
 
  public void test_02() {
    try {
      UpdatableSeries<Double> s = db.getUpdatableSeries(SERIES, true).typeCheck(Double.class);
      TimeIndex t = s.getTimeDomain().time("2011-03-08");
      s.scanValue(t, "42");
      assertEquals(42.0, s.getValue(t));
    } catch (Exception e) {
      fail(e.toString());
    }
View Full Code Here

  }
 
  public void test_03() {
    try {
      Series<Double> s = db.getUpdatableSeries(SERIES, true).typeCheck(Double.class);
      TimeIndex t = s.getTimeDomain().time("2011-03-08");
      assertEquals(Double.NaN, s.getValue(t));
    } catch (Exception e) {
      fail(e.toString());
    }
  }
View Full Code Here

  }
 
  public void test_04() {
    try {
      UpdatableSeries<Double> s = db.getUpdatableSeries(SERIES, true).typeCheck(Double.class);
      TimeIndex t = s.getTimeDomain().time("2011-03-08");
      s.scanValue(t, "42");
      s.applyUpdates();
      assertEquals(42.0, s.getValue(t));
    } catch (Exception e) {
      fail(e.toString());
View Full Code Here

  }
 
  public void test_05() {
    try {
      Series<Double> s = db.getUpdatableSeries(SERIES, true).typeCheck(Double.class);
      TimeIndex t = s.getTimeDomain().time("2011-03-08");
      assertEquals(42.0, s.getValue(t));
      assertFalse(s.getSurrogate().inConstruction());
    } catch (Exception e) {
      fail(e.toString());
    }
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.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.