Пример #1
0
  public void testTimeZoneHelperToICalendarCanberra() {

    TimeZoneHelper vctz =
        new TimeZoneHelper(
            "Australia/Canberra",
            1167609600000L, // 01 Jan 2007 @ 00:00:00 UTC
            1349049600000L); // 01 Oct 2012 @ 00:00:00 UTC
    VTimezone vtz = vctz.getVTimezone();
    List<VComponent> dayLightComponents = vtz.getComponents("DAYLIGHT");
    List<VComponent> standardComponents = vtz.getComponents("STANDARD");

    assertEquals("Australia/Canberra", vtz.getProperty("TZID").getValue());
    assertEquals(1, dayLightComponents.size());
    TzDaylightComponent dayLight = (TzDaylightComponent) dayLightComponents.get(0);
    assertEquals("+1000", dayLight.getProperty("TZOFFSETFROM").getValue());
    assertEquals("+1100", dayLight.getProperty("TZOFFSETTO").getValue());
    assertEquals("20061029T020000", dayLight.getProperty("DTSTART").getValue());
    assertEquals(
        "FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10", dayLight.getProperty("RRULE").getValue());

    assertEquals(1, standardComponents.size());
    TzStandardComponent standard = (TzStandardComponent) standardComponents.get(0);
    assertEquals("+1100", standard.getProperty("TZOFFSETFROM").getValue());
    assertEquals("+1000", standard.getProperty("TZOFFSETTO").getValue());
    assertEquals("20070325T030000", standard.getProperty("DTSTART").getValue());
    assertEquals(
        "FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3", standard.getProperty("RRULE").getValue());
  }
Пример #2
0
  public void testTimeZoneHelperToICalendarBogota() {

    TimeZoneHelper vctz =
        new TimeZoneHelper(
            "America/Bogota",
            0L, // 01 Jan 1970 @ 00:00:00 UTC
            1324771200000L); // 25 Dec 2011 @ 00:00:00 UTC

    VTimezone vtz = vctz.getVTimezone();
    List<VComponent> dayLightComponents = vtz.getComponents("DAYLIGHT");
    List<VComponent> standardComponents = vtz.getComponents("STANDARD");

    assertEquals("America/Bogota", vtz.getProperty("TZID").getValue());
    assertEquals(0, dayLightComponents.size());
    assertEquals(2, standardComponents.size());
    TzStandardComponent standard = (TzStandardComponent) standardComponents.get(0);
    assertEquals("-0500", standard.getProperty("TZOFFSETFROM").getValue());
    assertEquals("-0400", standard.getProperty("TZOFFSETTO").getValue());
    assertEquals("19920503T000000", standard.getProperty("DTSTART").getValue());
    assertEquals("19920503T000000", standard.getProperty("RDATE").getValue());

    standard = (TzStandardComponent) standardComponents.get(1);
    assertEquals("-0400", standard.getProperty("TZOFFSETFROM").getValue());
    assertEquals("-0500", standard.getProperty("TZOFFSETTO").getValue());
    assertEquals("19930404T000000", standard.getProperty("DTSTART").getValue());
    assertEquals("19930404T000000", standard.getProperty("RDATE").getValue());
  }
Пример #3
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();
  }
Пример #4
0
  /**
   * Creates a new instance of TimeZoneHelper on the basis of the information extracted from an
   * iCalendar (vCalendar 2.0) item.
   *
   * @param vTimeZone
   * @param from the start of the relevant time interval for the generation of transitions (an
   *     istant expressed as a long)
   * @param to the end of the relevant time interval for the generation of transitions (an istant
   *     expressed as a long)
   * @throws java.lang.Exception
   */
  public TimeZoneHelper(VTimezone vTimeZone, long from, long to) throws Exception {
    setFormattersToUTC();
    Property tzID = vTimeZone.getProperty("TZID");
    if (tzID != null) {
      this.name = tzID.getValue();

      // Try and skip the parsing by using just the TZID:
      String extracted = extractID(name);
      if (extracted != null) {
        cacheID(extracted);
        processID(extracted, from, to);
        return;
      }

      List<VComponent> standardTimeRules = vTimeZone.getComponents("STANDARD");
      List<VComponent> summerTimeRules = vTimeZone.getComponents("DAYLIGHT");

      String standardTimeOffset;
      if (standardTimeRules.isEmpty()) {
        if (summerTimeRules.isEmpty()) {
          throw new Exception("Empty VTIMEZONE");
        } else {
          standardTimeOffset = summerTimeRules.get(0).getProperty("TZOFFSETFROM").getValue();
        }
      } else {
        standardTimeOffset = standardTimeRules.get(0).getProperty("TZOFFSETTO").getValue();
      }
      basicOffset = parseOffset(standardTimeOffset);

      for (VComponent standardTimeRule : standardTimeRules) {
        addTransitions(standardTimeRule, from, to);
      }
      for (VComponent summerTimeRule : summerTimeRules) {
        addTransitions(summerTimeRule, from, to);
      }
      Collections.sort(transitions);

    } else {
      this.name = ""; // This should not happen!
    }
  }
Пример #5
0
  public void testTimeZoneHelperToICalendarJohannesburg() {

    TimeZoneHelper vctz =
        new TimeZoneHelper(
            "Africa/Johannesburg",
            0L, // 01 Jan 1970 @ 00:00:00 UTC
            1324771200000L); // 25 Dec 2011 @ 00:00:00 UTC

    VTimezone vtz = vctz.getVTimezone();
    List<VComponent> dayLightComponents = vtz.getComponents("DAYLIGHT");
    List<VComponent> standardComponents = vtz.getComponents("STANDARD");

    assertEquals("Africa/Johannesburg", vtz.getProperty("TZID").getValue());
    assertEquals(0, dayLightComponents.size());
    assertEquals(1, standardComponents.size());
    TzStandardComponent standard = (TzStandardComponent) standardComponents.get(0);
    assertEquals("+0200", standard.getProperty("TZOFFSETFROM").getValue());
    assertEquals("+0200", standard.getProperty("TZOFFSETTO").getValue());
    assertEquals("19700101T000000", standard.getProperty("DTSTART").getValue());
    assertEquals("19700101T000000", standard.getProperty("RDATE").getValue());
  }