Package com.ibm.icu.util

Examples of com.ibm.icu.util.GregorianCalendar


   * @throws SQLException Thrown when the connection to the database failed.
   */
  public void testBuildDataTableRows() throws SQLException {
    // Build Timestamp, Date ant Time objects for the date February 8, 2008
    // 09:01:10. Set their values in the table.
    GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    gc.set(2008, 1, 8, 9, 1, 10);
    // Set the milliseconds explicitly, otherwise the milliseconds from the
    // time the gc was initialized are used.
    gc.set(GregorianCalendar.MILLISECOND, 0);

    Date date = new Date(gc.getTimeInMillis());
    Time time = new Time(gc.get(GregorianCalendar.HOUR), gc.get(GregorianCalendar.MINUTE),
        gc.get(GregorianCalendar.SECOND));
    Timestamp timestamp = new Timestamp(
        gc.get(GregorianCalendar.YEAR) - 1900, gc.get(GregorianCalendar.MONTH),
        gc.get(GregorianCalendar.DAY_OF_MONTH), gc.get(GregorianCalendar.HOUR),
        gc.get(GregorianCalendar.MINUTE), gc.get(GregorianCalendar.SECOND), 0);

    // Create the table rows.
    List<Object> row1 =
        Lists.<Object>newArrayList(100, "Yaron", null, 'M', 1000, false, date,
            timestamp, time);
View Full Code Here


      }
      data.addColumns(cd);

      List<ReadingHistory> readings =
          ofy().load().type(ReadingHistory.class).ancestor(sensor).list();
      GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
      // without a timezone of GMT, you will get:
      // can't create DateTimeValue from GregorianCalendar that is not GMT.
      // and if you want your graph in a TZ other than GMT? Nope.
      for (ReadingHistory reading : readings) {
        cal.setTime(new Date(reading.getTimestamp().getTime()));
        if (sensor.getType() == Sensor.Type.TEMPERATURE || sensor.getType() == Sensor.Type.HUMIDITY) {
          data.addRowFromValues(cal, new Double(reading.getHigh()), new Double(reading.getLow()));
        } else if (sensor.getType() == Sensor.Type.LIGHT) {
          data.addRowFromValues(cal, new Double(reading.getAverage()));
        } else if (sensor.getType() == Sensor.Type.WINDSPEED) {
View Full Code Here

          ofy().load().type(Sensor.class).id(Long.parseLong(request.getParameter("id"))).now();
      Date cutoffdate = new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24 * 7));
      List<Reading> readings =
          ofy().load().type(Reading.class).ancestor(sensor).filter("timestamp >", cutoffdate)
              .list();
      GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
      // without a timezone of GMT, you will get:
      // can't create DateTimeValue from GregorianCalendar that is not GMT.
      // and if you want your graph in a TZ other than GMT? Nope.
      for (Reading reading : readings) {
        cal.setTime(new Date(reading.getTimestamp().getTime() - (7 * 60 * 60 * 1000))); // convert
                                                                                        // timezones...TODO
                                                                                        // fix this
                                                                                        // kludge
        data.addRowFromValues(cal, new Double(reading.getValue()));
      }
View Full Code Here

   *     parameters is illegal.
   */
  public DateTimeValue(int year, int month, int dayOfMonth, int hours,
      int minutes, int seconds, int milliseconds) {
    // Constructs a GregorianCalendar with the given date and time.
    calendar = new GregorianCalendar(year, month, dayOfMonth, hours,
        minutes, seconds);
    calendar.set(GregorianCalendar.MILLISECOND, milliseconds);
    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));

    // Check input.
View Full Code Here

   *     parameters is illegal.
   */
  public DateValue(int year, int month, int dayOfMonth) {
    // Constructs a GregorianCalendar with the given date set in
    // the default time zone.
    GregorianCalendar calendar =
        new GregorianCalendar(year, month, dayOfMonth);

    // Input check. If the date is invalid the calendar object will output
    // different fields for year, month and/or dayOfMonth.
    // A RunTimeException is thrown here since it is very unusual for structured
    // data to be incorrect.
    if ((calendar.get(GregorianCalendar.YEAR) != year)
        || (calendar.get(GregorianCalendar.MONTH) != month)
        || (calendar.get(GregorianCalendar.DAY_OF_MONTH) != dayOfMonth)) {
      throw new IllegalArgumentException("Invalid java date (yyyy-MM-dd): "
          + year + '-' + month + '-' + dayOfMonth);
    }
    // Assign internal variables.
    this.year = year;
View Full Code Here

  @Override
  public Calendar getObjectToFormat() {
    if (isNull()) {
      return null;
    }
    GregorianCalendar cal = new GregorianCalendar(year, month, dayOfMonth);
    cal.setTimeZone(TimeZone.getTimeZone("GMT"));
    return cal;
  }
View Full Code Here

    if (isNull()) {
      return null;
    }

    // Set GMT TimeZone.
    Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
    // Set to some predefined default. Don't change this default.
    cal.set(Calendar.YEAR, 1899);
    cal.set(Calendar.MONTH, Calendar.DECEMBER);
    cal.set(Calendar.DAY_OF_MONTH, 30);
    // Set the TimeOfDay based on this TimeOfDayValue.
    cal.set(Calendar.HOUR_OF_DAY, hours);
    cal.set(Calendar.MINUTE, minutes);
    cal.set(Calendar.SECOND, seconds);
    cal.set(Calendar.MILLISECOND, milliseconds);

    return cal;
  }
View Full Code Here

      StringBuilder sb, boolean includeFormatting, boolean isLastColumn,
      boolean renderDateAsDateConstructor) {
    Value value = cell.getValue();
    ValueType type = cell.getType();
    StringBuilder valueJson = new StringBuilder();
    GregorianCalendar calendar;
    String escapedFormattedString = "";
    boolean isJsonNull = false;

    // Prepare a Json string representing the current value.
    DateValue dateValue;
    TimeOfDayValue timeOfDayValue;
    if ((value == null) || (value.isNull())) {
      valueJson.append("null");
      isJsonNull = true;
    } else {
      switch (type) {
        case BOOLEAN:
          valueJson.append(((BooleanValue) value).getValue());
          break;
        case DATE:
          valueJson.append("Date(");
          dateValue = (DateValue) value;
          valueJson.append(dateValue.getYear()).append(",");
          valueJson.append(dateValue.getMonth()).append(",");
          valueJson.append(dateValue.getDayOfMonth());
          valueJson.append(")");
          if (renderDateAsDateConstructor) {
            // Rendering date as a call to Date constructor, e.g new Date(2011,1,1)
            valueJson.insert(0, "new ");
          } else {
            // Rendering date in string format, e.g "Date(2011,1,1)"
            valueJson.insert(0, "\"");
            valueJson.append("\"");          
          }
          break;
        case NUMBER:
          valueJson.append(((NumberValue) value).getValue());
          break;
        case TEXT:
          valueJson.append("\"");
          valueJson.append(EscapeUtil.jsonEscape(value.toString()));
          valueJson.append("\"");
          break;
        case TIMEOFDAY:
          valueJson.append("[");
          timeOfDayValue = (TimeOfDayValue) value;
          valueJson.append(timeOfDayValue.getHours()).append(",");
          valueJson.append(timeOfDayValue.getMinutes()).append(",");
          valueJson.append(timeOfDayValue.getSeconds()).append(",");
          valueJson.append(timeOfDayValue.getMilliseconds());
          valueJson.append("]");
          break;
        case DATETIME:
          calendar = ((DateTimeValue) value).getCalendar();
          valueJson.append("Date(");
          valueJson.append(calendar.get(GregorianCalendar.YEAR)).append(",");
          valueJson.append(calendar.get(GregorianCalendar.MONTH)).append(",");
          valueJson.append(calendar.get(GregorianCalendar.DAY_OF_MONTH));
          valueJson.append(",");
          valueJson.append(calendar.get(GregorianCalendar.HOUR_OF_DAY));
          valueJson.append(",");
          valueJson.append(calendar.get(GregorianCalendar.MINUTE)).append(",");
          valueJson.append(calendar.get(GregorianCalendar.SECOND));
          valueJson.append(")");
          if (renderDateAsDateConstructor) {
            // Rendering date as a call to Date constructor, e.g new Date(2011,1,1,0,0,0)
            valueJson.insert(0, "new ");
          } else {
View Full Code Here

      // Do nothing, this is the expected behavior.
    }

    // Test creating a DateValue.
    try {
      GregorianCalendar calendar = new GregorianCalendar(2009, 2, 15);
      calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
      Value v = ValueType.DATE.createValue(calendar);
      assertTrue(v.getType() == ValueType.DATE);
      DateValue dv = (DateValue) v;
      assertEquals(dv.compareTo(new DateValue(calendar)), 0);
    } catch (TypeMismatchException e) {
      fail();
    }

    // Verify that an exception is thrown on type mismatch for DateValue.
    try {
      Value v = ValueType.DATE.createValue("abc");
      fail();
    } catch (TypeMismatchException e) {
      // Do nothing, this is the expected behavior.
    }

    // Test creating a null DateValue.
    try {
      Value v = ValueType.DATE.createValue(null);
      assertTrue(v.getType() == ValueType.DATE);
      DateValue dv = (DateValue) v;
      assertEquals(dv, DateValue.getNullValue());
    } catch (TypeMismatchException e) {
      // Do nothing, this is the expected behavior.
    }

    // Test creating a DateTimeValue.
    try {
      GregorianCalendar calendar = new GregorianCalendar(2009, 2, 15, 12, 30, 14);
      calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
      Value v = ValueType.DATETIME.createValue(calendar);
      assertTrue(v.getType() == ValueType.DATETIME);
      DateTimeValue dtv = (DateTimeValue) v;
      assertEquals(dtv.compareTo(new DateTimeValue(calendar)), 0);
    } catch (TypeMismatchException e) {
      fail();
    }

    // Verify that an exception is thrown on type mismatch for DateTimeValue.
    try {
      Value v = ValueType.DATETIME.createValue("abc");
      fail();
    } catch (TypeMismatchException e) {
      // Do nothing, this is the expected behavior.
    }

    // Test creating a null DateTimeValue.
    try {
      Value v = ValueType.DATETIME.createValue(null);
      assertTrue(v.getType() == ValueType.DATETIME);
      DateTimeValue dtv = (DateTimeValue) v;
      assertEquals(dtv, DateTimeValue.getNullValue());
    } catch (TypeMismatchException e) {
      // Do nothing, this is the expected behavior.
    }

    // Test creating a TimeOfDayValue.
    try {
      GregorianCalendar calendar = new GregorianCalendar(2009, 2, 15, 12, 30, 14);
      calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
      Value v = ValueType.TIMEOFDAY.createValue(calendar);
      assertTrue(v.getType() == ValueType.TIMEOFDAY);
      TimeOfDayValue todv = (TimeOfDayValue) v;
      assertEquals(todv.compareTo(new TimeOfDayValue(calendar)), 0);
    } catch (TypeMismatchException e) {
View Full Code Here

  /**
   * Tests addRowFromValues.
   */
  public void testAddRowFromValues() {
    assertEquals(4, testData.getNumberOfRows());
    GregorianCalendar c1 = new GregorianCalendar(2009, 2, 15);
    c1.setTimeZone(TimeZone.getTimeZone("GMT"));
    GregorianCalendar c2 = new GregorianCalendar(2009, 2, 15, 12, 30, 45);
    c2.setTimeZone(TimeZone.getTimeZone("GMT"));
    try {
      testData.addRowFromValues("blah", 5, true, c1, c2, c2);
    } catch (TypeMismatchException e) {
      fail();
    }
View Full Code Here

TOP

Related Classes of com.ibm.icu.util.GregorianCalendar

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.