/** * 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! } }
/** * Creates a new instance of TimeZoneHelper on the basis of a zoneinfo (Olson database) ID. * * @param id the time zone ID according to the zoneinfo (Olson) database * @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) */ public TimeZoneHelper(String id, long from, long to) { setFormattersToUTC(); cacheID(id); processID(id, from, to); }