[SNMP4J] DateAndTime makeCalender improvement

Pim Moerenhout pim.moerenhout at gmail.com
Sat Apr 9 18:40:22 CEST 2016


Hi Frank,

This test case test the GregorianCalendar with all possible timezones which
fails with the 2.4.2 DateAndTime.makeCalendar

public void testDateAndTime() throws Exception {
  // 1st april 2016 UTC 00:00:00
  long testMillis = 1459468800000L;
  for (String timeZoneId : TimeZone.getAvailableIDs()) {
    GregorianCalendar gc = new
GregorianCalendar(TimeZone.getTimeZone(timeZoneId));
    gc.setTimeInMillis(testMillis);
    OctetString dateAndTime = DateAndTime.makeDateAndTime(gc);
    int error = DateAndTime.validateDateAndTime(dateAndTime);
    if (error != 0) {
      System.out.println("SNMP error: " + error);
    }

    // check the makeCalendar from the generated DateAndTime
    GregorianCalendar parsedGc = DateAndTime.makeCalendar(dateAndTime);
    long parsedGcMillis = parsedGc.getTimeInMillis();
    System.out.println(String.format("[%32s] The parsed millis %s: %5.1f
hours (" + gc
            .getTime() + " " + parsedGc.getTime() + ")", timeZoneId,
        (parsedGcMillis != testMillis ? "differs" : "equals "),
        (parsedGcMillis - testMillis) / 3600000.0));
  }
}

Most timezones fail, except when using the default timezone (or equivalent).

Regards, Pim



More information about the SNMP4J mailing list