use of com.zimbra.cs.util.tnef.mapi.SYSTEMTIME in project zm-mailbox by Zimbra.
the class TnefTimeZone method getTimeZone.
/**
* Ref: [MS-OXOCAL] - v20100729
* Returns a time zone from the given index;
* The default TimeZone ID is "tnefTimeZone"
* @param index
* @return
* @throws IOException
*/
public static TimeZone getTimeZone(int index, boolean observeDaylightSaving, String tzId) throws IOException {
if (index < 0 || index > 59)
return null;
// UTC offset in minutes
int bias = 0;
// offset in minutes from bias during standard time.; has a value of 0 in most cases
int standardBias = 0;
// offset in minutes from bias during daylight saving time.
int daylightBias = 0;
SYSTEMTIME StandardDate = null;
SYSTEMTIME DaylightDate = null;
// 1 - January, 12 - December
int startMonth = 0;
// 0 - Sunday, 6 - Saturday
int startDayOfWeek = 0;
// day of the week within the month, 5 = last occurrence of that day
int startDay = 0;
int startHour = 0;
int endMonth = 0;
int endDayOfWeek = 0;
int endDay = 0;
int endHour = 0;
// get the UTC+12 standard offset in minutes from MS_OXOCAL_STANDARD_OFFSET table!!
int utcPlus12offset = MS_OXOCAL_STANDARD_OFFSET[index][0];
int indexToDaytimeSavingDatesTable = MS_OXOCAL_STANDARD_OFFSET[index][1];
if (utcPlus12offset > 12 * 60)
bias = (utcPlus12offset - 12 * 60) * -1;
else if (utcPlus12offset < 12 * 60)
bias = (12 * 60 - utcPlus12offset);
if (indexToDaytimeSavingDatesTable == -1 || !observeDaylightSaving) {
int utcOffsetInMilliseconds = bias * 60 * 1000;
return getNoDaylightSavingTimeZoneFromUtcOffset(utcOffsetInMilliseconds);
}
// handle the daylight saving case here...
// HACK!!
// HACK!!
// TZRule.getStandardUtcOffset() always multiply the offset by -1;
// Hence, we are multiplying by -1 in reverse order.
bias = bias * -1;
// If daylight saving time is observed, during the daylight time period,
// an additional -60 offset is added to the standard offset.
daylightBias = -60;
startMonth = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][1][0];
startDayOfWeek = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][1][1];
startDay = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][1][2];
startHour = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][1][3];
endMonth = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][0][0];
endDayOfWeek = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][0][1];
endDay = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][0][2];
endHour = MS_OXOCAL_STAN_DST_DATES[indexToDaytimeSavingDatesTable][0][3];
StandardDate = new SYSTEMTIME(endMonth, endDayOfWeek, endDay, endHour);
DaylightDate = new SYSTEMTIME(startMonth, startDayOfWeek, startDay, startHour);
if (sLog.isDebugEnabled()) {
StringBuilder debugInfo = new StringBuilder();
debugInfo.append(bias * -1 + " " + "{" + endMonth + "," + endDayOfWeek + "," + endDay + "," + endHour + "} " + "{" + startMonth + "," + startDayOfWeek + "," + startDay + "," + startHour + "}");
sLog.debug(debugInfo);
}
String timeZoneId;
if (tzId == null || tzId.length() == 0)
timeZoneId = DEFAULT_TNEF_TIMEZONE_ID;
else
timeZoneId = tzId;
TimeZoneDefinition timeZoneDefinition = new TimeZoneDefinition(timeZoneId, bias, standardBias, daylightBias, StandardDate, DaylightDate);
return timeZoneDefinition.getTimeZone();
}
Aggregations