Ejemplo n.º 1
0
 public void test_allZones() throws Exception {
   int count = 0;
   for (String id : ((Set<String>) DateTimeZone.getAvailableIDs())) {
     if (id.startsWith("Europe/P")) {
       // note: sometimes id != timezone(id).id
       count++;
     }
   }
   Assert.assertTrue(count >= 3);
   Assert.assertTrue(((Set<String>) DateTimeZone.getAvailableIDs()).contains("Europe/Moscow"));
 }
Ejemplo n.º 2
0
public class DateRangeTests extends BaseAggregationTestCase<DateRangeAggregatorBuilder> {

  private static final String[] timeZoneIds =
      DateTimeZone.getAvailableIDs().toArray(new String[DateTimeZone.getAvailableIDs().size()]);

  @Override
  protected DateRangeAggregatorBuilder createTestAggregatorBuilder() {
    int numRanges = randomIntBetween(1, 10);
    DateRangeAggregatorBuilder factory = new DateRangeAggregatorBuilder("foo");
    for (int i = 0; i < numRanges; i++) {
      String key = null;
      if (randomBoolean()) {
        key = randomAsciiOfLengthBetween(1, 20);
      }
      double from =
          randomBoolean()
              ? Double.NEGATIVE_INFINITY
              : randomIntBetween(Integer.MIN_VALUE, Integer.MAX_VALUE - 1000);
      double to =
          randomBoolean()
              ? Double.POSITIVE_INFINITY
              : (Double.isInfinite(from)
                  ? randomIntBetween(Integer.MIN_VALUE, Integer.MAX_VALUE)
                  : randomIntBetween((int) from, Integer.MAX_VALUE));
      if (randomBoolean()) {
        factory.addRange(new Range(key, from, to));
      } else {
        String fromAsStr = Double.isInfinite(from) ? null : String.valueOf(from);
        String toAsStr = Double.isInfinite(to) ? null : String.valueOf(to);
        factory.addRange(new Range(key, fromAsStr, toAsStr));
      }
    }
    factory.field(INT_FIELD_NAME);
    if (randomBoolean()) {
      factory.format("###.##");
    }
    if (randomBoolean()) {
      factory.keyed(randomBoolean());
    }
    if (randomBoolean()) {
      factory.missing(randomIntBetween(0, 10));
    }
    if (randomBoolean()) {
      factory.timeZone(DateTimeZone.forID(randomFrom(timeZoneIds)));
    }
    return factory;
  }
}
 private static List<DateTimeZone> createZones() {
   final List<DateTimeZone> zones = new ArrayList<DateTimeZone>();
   for (final String zone : DateTimeZone.getAvailableIDs()) {
     zones.add(DateTimeZone.forID(zone));
   }
   return zones;
 }
Ejemplo n.º 4
0
  @SuppressWarnings("unchecked")
  public void testTimeZoneHelperCheckAllOlsonIDsWithICalendar() throws Exception {

    int mistakes = 0; // counter for mistakes in time zone handling

    /*
     * Max number of mistakes allowed. This value should be lowered as soon
     * as improvements in the code that handles time zones reduce the
     * number of mistakes. In this way, this test can be used to certify
     * that the number of properly handled time zones is being constantly
     * raised.
     */
    final int MAX_MISTAKES = 125;

    System.out.println("================================= iCalendar (2.0)");
    for (String id : (Set<String>) DateTimeZone.getAvailableIDs()) {

      TimeZoneHelper vctzOut =
          new TimeZoneHelper(
              id,
              // 0L,              // 01 Jan 1970 @ 00:00:00 UTC
              915148800000L, // 01 Jan 1999 @ 00:00:00 UTC
              1324771200000L); // 25 Dec 2011 @ 00:00:00 UTC
      VTimezone vTimezone = vctzOut.getVTimezone();

      // Uncomment this to debug the iCalendar items referring to one
      // continent:
      /*
      String continent = "Australia"; // or whatever you want to watch
      if (id.startsWith(continent)) {
          System.out.println("\n\n" + vTimezone);
      }
      */

      vTimezone.getProperty("TZID").setValue(""); // The name should not be used as a hint for
      // this "test"

      TimeZoneHelper vctzIn =
          new TimeZoneHelper(
              vTimezone,
              915148800000L, // 01 Jan 1999 @ 00:00:00 UTC
              1324771200000L); // 25 Dec 2011 @ 00:00:00 UTC
      System.out.print('\n' + id + " --> " + vctzIn.toID());
      vctzIn.clearCachedID();
      String guess = vctzIn.toID(id);
      if (!id.equals(guess)) {
        System.out.print(" (WRONG!)");
        mistakes++;
      }
    }
    System.out.println("\n\n" + mistakes + " time zones were not properly handled.");
    assertTrue(mistakes <= MAX_MISTAKES);
    System.out.println();
  }
Ejemplo n.º 5
0
    public DateTimeZone deserialize(
        JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
      if (json.isJsonNull()) return null;
      String tz = json.getAsString();
      if (tz.isEmpty()) // defaults to UTC
      return DateTimeZone.UTC;
      DateTimeZone timeZone;

      try {
        // check if time zone is valid
        timeZone = DateTimeZone.forID(tz);
      } catch (IllegalArgumentException e) {
        throw new ContextualJsonSyntaxException(
            tz, "is not a valid time zone, must be one of " + DateTimeZone.getAvailableIDs());
      }
      return timeZone;
    }
Ejemplo n.º 6
0
  @SuppressWarnings("unchecked")
  public void testTimeZoneHelperCheckAllOlsonIDsWithXVCalendar() throws Exception {

    int mistakes = 0; // counter for mistakes in time zone handling

    /*
     * Max number of mistakes allowed. This value should be lowered as soon
     * as improvements in the code that handles time zones reduce the
     * number of mistakes. In this way, this test can be used to certify
     * that the number of properly handled time zones is being constantly
     * raised.
     */
    final int MAX_MISTAKES = 16;

    System.out.println("================================= vCalendar (1.0)");
    for (String id : (Set<String>) DateTimeZone.getAvailableIDs()) {

      TimeZoneHelper vctzOut =
          new TimeZoneHelper(
              id,
              // 0L,              // 01 Jan 1970 @ 00:00:00 UTC
              915148800000L, // 01 Jan 1999 @ 00:00:00 UTC
              1324771200000L); // 25 Dec 2011 @ 00:00:00 UTC
      List<Property> dayLightList = vctzOut.getDaylightList();
      Property tz = vctzOut.getTZ();

      TimeZoneHelper vctzIn = new TimeZoneHelper(tz, dayLightList);
      vctzIn.setName(""); // The name should not be used as a hint for
      // this "test"
      System.out.print('\n' + id + " --> " + vctzIn.toID());
      vctzIn.clearCachedID();
      String guess = vctzIn.toID(id);
      if (!id.equals(guess)) {
        System.out.print(" (WRONG!)");
        mistakes++;
      }
    }
    System.out.println("\n\n" + mistakes + " time zones were not properly handled.");
    assertTrue(mistakes <= MAX_MISTAKES);
    System.out.println();
  }
Ejemplo n.º 7
0
 public static Set<String> getAvailableIDs() {
   return DateTimeZone.getAvailableIDs();
 }