use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class Invite method getReferencedTZIDs.
public Set<String> getReferencedTZIDs() {
Set<String> tzids = new HashSet<String>();
// DTSTART
if (mStart != null && mStart.hasTime()) {
ICalTimeZone tz = mStart.getTimeZone();
if (tz != null)
tzids.add(tz.getID());
}
// DTEND/DUE
if (mEnd != null && mEnd.hasTime()) {
ICalTimeZone tz = mEnd.getTimeZone();
if (tz != null)
tzids.add(tz.getID());
}
// RECURRENCE-ID
if (mRecurrenceId != null) {
ParsedDateTime dt = mRecurrenceId.getDt();
if (dt.hasTime()) {
ICalTimeZone tz = dt.getTimeZone();
if (tz != null)
tzids.add(tz.getID());
}
}
// RDATE/EXDATE
IRecurrence recur = getRecurrence();
if (recur != null)
tzids.addAll(Recurrence.getReferencedTZIDs(recur));
return tzids;
}
use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class Util method encodeAsMetadata.
public static Metadata encodeAsMetadata(TimeZoneMap tzmap) {
Metadata meta = new Metadata();
Map<String, Integer> /* index */
tzIndex = new HashMap<String, Integer>();
int nextIndex = 0;
for (Iterator<Entry<String, ICalTimeZone>> iter = tzmap.getMap().entrySet().iterator(); iter.hasNext(); ) {
Entry<String, ICalTimeZone> entry = iter.next();
String tzid = entry.getKey();
if (// ignore null/empty TZIDs (bug 25183)
tzid == null || tzid.length() < 1)
continue;
ICalTimeZone zone = entry.getValue();
String realTzid = zone.getID();
if (!tzIndex.containsKey(realTzid)) {
meta.put("#" + nextIndex, encodeAsMetadata(zone));
tzIndex.put(realTzid, nextIndex);
++nextIndex;
}
}
for (Iterator<Entry<String, String>> iter = tzmap.getAliasMap().entrySet().iterator(); iter.hasNext(); ) {
Entry<String, String> entry = iter.next();
String alias = entry.getKey();
String realTzid = entry.getValue();
if (tzIndex.containsKey(realTzid)) {
int index = tzIndex.get(realTzid);
meta.put(alias, index);
}
}
return meta;
}
use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class Util method decodeFromMetadata.
/**
*
* @param meta
* @param localTZ local time zone of user account
* @return
* @throws ServiceException
*/
public static TimeZoneMap decodeFromMetadata(Metadata meta, ICalTimeZone localTZ) throws ServiceException {
Map<String, ?> map = meta.asMap();
Map<String, String> aliasMap = new HashMap<String, String>();
ICalTimeZone[] tzlist = new ICalTimeZone[map.size()];
// first time, find the tz's
for (Map.Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
if (key != null && key.length() > 0) {
// ignore null/empty TZIDs (bug 25183)
if (key.charAt(0) == '#') {
int idx = Integer.parseInt(key.substring(1));
Metadata tzMeta = (Metadata) entry.getValue();
String tzidMeta = tzMeta.get(FN_TZID, null);
if (tzidMeta != null) {
ICalTimeZone tz = decodeTimeZoneFromMetadata(tzMeta);
if (tz != null) {
String tzid = tz.getID();
if (!DebugConfig.disableCalendarTZMatchByID)
tzid = TZIDMapper.canonicalize(tzid);
if (!tzidMeta.equals(tzid)) {
aliasMap.put(tzidMeta, tzid);
tz = WellKnownTimeZones.getTimeZoneById(tzid);
}
tzlist[idx] = tz;
}
}
}
}
}
Map<String, ICalTimeZone> tzmap = new HashMap<String, ICalTimeZone>();
for (ICalTimeZone tz : tzlist) {
if (tz != null)
tzmap.put(tz.getID(), tz);
}
// second time, build the real map
for (Map.Entry<String, ?> entry : map.entrySet()) {
String tzid = entry.getKey();
if (tzid != null && tzid.length() > 0) {
// ignore null/empty TZIDs (bug 25183)
if (tzid.charAt(0) != '#') {
int idx = -1;
try {
idx = Integer.parseInt(entry.getValue().toString());
} catch (NumberFormatException e) {
}
if (idx >= 0 && idx < tzlist.length) {
ICalTimeZone tz = tzlist[idx];
if (tz != null) {
String realId = tz.getID();
if (!realId.equals(tzid))
aliasMap.put(tzid, realId);
}
}
}
}
}
return new TimeZoneMap(tzmap, aliasMap, localTZ);
}
use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class Recurrence method main.
public static void main(String[] args) throws Exception {
ICalTimeZone pacific = new ICalTimeZone("America/Los_Angeles", -28800000, "16010101T020000", "FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU", "PST", -25200000, "16010101T020000", "FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU", "PDT");
TimeZoneMap tzmap = new TimeZoneMap(pacific);
String str = "TZID=\"" + pacific.getID() + "\":20090105T120000";
ParsedDateTime dtStart = ParsedDateTime.parse(str, tzmap);
ParsedDuration duration = ParsedDuration.parse("PT1H");
List<IRecurrence> addRules = new ArrayList<IRecurrence>();
List<IRecurrence> subRules = new ArrayList<IRecurrence>();
// weekly from 2009/01/05, for 52 weeks
ZRecur rule = new ZRecur("FREQ=WEEKLY;INTERVAL=1", tzmap);
addRules.add(new SimpleRepeatingRule(dtStart, duration, rule, null));
// add a couple of RDATES: 2009/01/06, 2009/01/07
RdateExdate rdate = new RdateExdate(ICalTok.RDATE, pacific);
str = "TZID=\"" + pacific.getID() + "\":20090106T120000";
ParsedDateTime rd1 = ParsedDateTime.parse(str, tzmap);
rdate.addValue(rd1);
str = "TZID=\"" + pacific.getID() + "\":20090107T120000";
ParsedDateTime rd2 = ParsedDateTime.parse(str, tzmap);
rdate.addValue(rd2);
addRules.add(new SingleDates(rdate, duration));
// modify instance on 2009/02/16 to start at 1pm instead of noon, for 2 hours
str = "TZID=\"" + pacific.getID() + "\":20090216T120000";
ParsedDateTime ridDtModify1 = ParsedDateTime.parse(str, tzmap);
RecurId ridModify1 = new RecurId(ridDtModify1, RecurId.RANGE_NONE);
str = "TZID=\"" + pacific.getID() + "\":20090216T130000";
ParsedDateTime dtStartModify1 = ParsedDateTime.parse(str, tzmap);
ParsedDuration durModify1 = ParsedDuration.parse("PT2H");
ExceptionRule modify1 = new ExceptionRule(ridModify1, dtStartModify1, durModify1, null);
// cancel instance on 2009/01/19
str = "TZID=\"" + pacific.getID() + "\":20090119T120000";
ParsedDateTime dtCancel1 = ParsedDateTime.parse(str, tzmap);
RecurId ridCancel1 = new RecurId(dtCancel1, RecurId.RANGE_NONE);
CancellationRule cancel1 = new CancellationRule(ridCancel1);
// EXDATE on 2009/02/09
RdateExdate exdate = new RdateExdate(ICalTok.EXDATE, pacific);
str = "TZID=\"" + pacific.getID() + "\":20090209T120000";
ParsedDateTime ex1 = ParsedDateTime.parse(str, tzmap);
exdate.addValue(ex1);
SingleDates exdateRule = new SingleDates(exdate, duration);
subRules.add(exdateRule);
RecurrenceRule recurrence = new RecurrenceRule(dtStart, duration, null, addRules, subRules);
recurrence.addException(modify1);
recurrence.addException(cancel1);
// Get all instances between 2009/01/01 and 2010/01/01.
Calendar startCal = new GregorianCalendar(pacific);
startCal.clear();
startCal.set(2009, Calendar.JANUARY, 1, 0, 0, 0);
Calendar endCal = (Calendar) startCal.clone();
endCal.add(Calendar.YEAR, 1);
// List<Instance> instances = recurrence.expandInstances(-1, startCal.getTimeInMillis(), endCal.getTimeInMillis());
List<Instance> instances = recurrence.expandInstances(-1, startCal.getTimeInMillis(), Long.MAX_VALUE);
for (Instance inst : instances) {
System.out.println(inst);
}
System.out.println("Got " + instances.size() + " instances");
}
use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class Util method decodeTimeZoneFromMetadata.
public static ICalTimeZone decodeTimeZoneFromMetadata(Metadata m) throws ServiceException {
String tzid;
if (m.containsKey(FN_TZID)) {
tzid = m.get(FN_TZID);
boolean hasDef = m.containsKey(FN_STANDARD_OFFSET);
if (!DebugConfig.disableCalendarTZMatchByID || !hasDef) {
ICalTimeZone tz = WellKnownTimeZones.getTimeZoneById(tzid);
if (tz != null) {
return tz;
} else if (!hasDef) {
ZimbraLog.calendar.debug("Unknown time zone \"" + tzid + "\" in metadata; using UTC instead");
return ICalTimeZone.getUTC().cloneWithNewTZID(tzid);
}
}
} else
tzid = "unknown time zone";
ICalTimeZone newTz = newICalTimeZone(tzid, m);
ICalTimeZone tz = ICalTimeZone.lookupByRule(newTz, false);
return tz;
}
Aggregations