void calDateTime::FromIcalTime(icaltimetype const* icalt, calITimezone * tz) { icaltimetype t = *icalt; mIsValid = (icaltime_is_null_time(t) || icaltime_is_valid_time(t) ? true : false); mIsDate = t.is_date ? true : false; if (mIsDate) { t.hour = 0; t.minute = 0; t.second = 0; } if (mIsValid) { t = icaltime_normalize(t); } mYear = static_cast<int16_t>(t.year); mMonth = static_cast<int16_t>(t.month - 1); mDay = static_cast<int16_t>(t.day); mHour = static_cast<int16_t>(t.hour); mMinute = static_cast<int16_t>(t.minute); mSecond = static_cast<int16_t>(t.second); if (tz) { mTimezone = tz; } else { mTimezone = cal::detectTimezone(t, nullptr); } #if defined(DEBUG) if (mTimezone) { if (t.is_utc) { nsCOMPtr<calITimezone> ctz = cal::UTC(); NS_ASSERTION(SameCOMIdentity(mTimezone, ctz), "UTC mismatch!"); } else if (!t.zone) { nsAutoCString tzid; mTimezone->GetTzid(tzid); if (tzid.EqualsLiteral("floating")) { nsCOMPtr<calITimezone> ctz = cal::floating(); NS_ASSERTION(SameCOMIdentity(mTimezone, ctz), "floating mismatch!"); } } else { nsAutoCString tzid; mTimezone->GetTzid(tzid); NS_ASSERTION(tzid.Equals(icaltimezone_get_tzid(const_cast<icaltimezone *>(t.zone))), "tzid mismatch!"); } } #endif mWeekday = static_cast<int16_t>(icaltime_day_of_week(t) - 1); mYearday = static_cast<int16_t>(icaltime_day_of_year(t)); // mNativeTime: not moving the existing date to UTC, // but merely representing it a UTC-based way. t.is_date = 0; mNativeTime = IcaltimeToPRTime(&t, icaltimezone_get_utc_timezone()); }
void calDateTime::FromIcalTime(icaltimetype const* icalt, calITimezone * tz) { icaltimetype t = *icalt; mIsValid = (icaltime_is_null_time(t) || icaltime_is_valid_time(t) ? PR_TRUE : PR_FALSE); mIsDate = t.is_date ? PR_TRUE : PR_FALSE; if (mIsDate) { t.hour = 0; t.minute = 0; t.second = 0; } if (mIsValid) { t = icaltime_normalize(t); } mYear = static_cast<PRInt16>(t.year); mMonth = static_cast<PRInt16>(t.month - 1); mDay = static_cast<PRInt16>(t.day); mHour = static_cast<PRInt16>(t.hour); mMinute = static_cast<PRInt16>(t.minute); mSecond = static_cast<PRInt16>(t.second); if (tz) { mTimezone = tz; } else { mTimezone = cal::detectTimezone(t, nsnull); } #if defined(DEBUG) if (mTimezone) { if (t.is_utc) { #if 1 nsCOMPtr<calITimezone> utc_tz; nsCOMPtr<calITimezoneService> tzSvc = do_GetService(CAL_TIMEZONESERVICE_CONTRACTID); tzSvc->GetUTC(getter_AddRefs(utc_tz)); NS_ASSERTION(SameCOMIdentity(mTimezone, utc_tz), "UTC mismatch!"); #else NS_ASSERTION(SameCOMIdentity(mTimezone, cal::UTC()), "UTC mismatch!"); #endif } else if (!t.zone) { #if 1 nsCOMPtr<calITimezone> float_tz; nsCOMPtr<calITimezoneService> tzSvc = do_GetService(CAL_TIMEZONESERVICE_CONTRACTID); tzSvc->GetFloating(getter_AddRefs(float_tz)); NS_ASSERTION(SameCOMIdentity(mTimezone, float_tz), "floating mismatch!"); #else NS_ASSERTION(SameCOMIdentity(mTimezone, cal::floating()), "floating mismatch!"); #endif } else { nsCAutoString tzid; mTimezone->GetTzid(tzid); NS_ASSERTION(tzid.Equals(icaltimezone_get_tzid(const_cast<icaltimezone *>(t.zone))), "tzid mismatch!"); } } #endif mWeekday = static_cast<PRInt16>(icaltime_day_of_week(t) - 1); mYearday = static_cast<PRInt16>(icaltime_day_of_year(t)); // mNativeTime: not moving the existing date to UTC, // but merely representing it a UTC-based way. t.is_date = 0; mNativeTime = IcaltimeToPRTime(&t, icaltimezone_get_utc_timezone()); }