NS_IMETHODIMP calDateTime::Compare(calIDateTime * aOther, int32_t * aResult) { NS_ENSURE_ARG_POINTER(aOther); NS_ENSURE_ARG_POINTER(aResult); bool otherIsDate = false; aOther->GetIsDate(&otherIsDate); icaltimetype a, b; ToIcalTime(&a); aOther->ToIcalTime(&b); // If either this or aOther is floating, both objects are treated // as floating for the comparison. if (!a.zone || !b.zone) { a.zone = NULL; a.is_utc = 0; b.zone = NULL; b.is_utc = 0; } if (mIsDate || otherIsDate) { *aResult = icaltime_compare_date_only_tz(a, b, cal::getIcalTimezone(mTimezone)); } else { *aResult = icaltime_compare(a, b); } return NS_OK; }
NS_IMETHODIMP calDateTime::Compare(calIDateTime * aOther, int32_t * aResult) { NS_ENSURE_ARG_POINTER(aOther); NS_ENSURE_ARG_POINTER(aResult); nsresult rv; nsCOMPtr<calIDateTimeLibical> icalother = do_QueryInterface(aOther, &rv); NS_ENSURE_SUCCESS(rv, rv); bool otherIsDate = false; aOther->GetIsDate(&otherIsDate); icaltimetype a, b; ToIcalTime(&a); icalother->ToIcalTime(&b); // If either this or aOther is floating, both objects are treated // as floating for the comparison. if (!a.zone || !b.zone) { a.zone = nullptr; a.is_utc = 0; b.zone = nullptr; b.is_utc = 0; } if (mIsDate || otherIsDate) { *aResult = icaltime_compare_date_only_tz(a, b, cal::getIcalTimezone(mTimezone)); } else { *aResult = icaltime_compare(a, b); } return NS_OK; }
// internal Normalize(): void calDateTime::Normalize() { icaltimetype icalt; ensureTimezone(); ToIcalTime(&icalt); FromIcalTime(&icalt, mTimezone); }
NS_IMETHODIMP calDateTime::GetTimezoneOffset(int32_t *aResult) { NS_ENSURE_ARG_POINTER(aResult); icaltimetype icalt; ToIcalTime(&icalt); int dst; *aResult = icaltimezone_get_utc_offset(const_cast<icaltimezone *>(icalt.zone), &icalt, &dst); return NS_OK; }
NS_IMETHODIMP calDateTime::Clone(calIDateTime **aResult) { NS_ENSURE_ARG_POINTER(aResult); icaltimetype itt; ToIcalTime(&itt); calDateTime * const cdt = new calDateTime(&itt, mTimezone); CAL_ENSURE_MEMORY(cdt); NS_ADDREF(*aResult = cdt); return NS_OK; }
NS_IMETHODIMP calDateTime::GetIcalString(nsACString& aResult) { icaltimetype t; ToIcalTime(&t); // note that ics is owned by libical, so we don't need to free char const * const ics = icaltime_as_ical_string(t); CAL_ENSURE_MEMORY(ics); aResult.Assign(ics); return NS_OK; }
NS_IMETHODIMP calDateTime::GetEndOfMonth(calIDateTime ** aResult) { NS_ENSURE_ARG_POINTER(aResult); icaltimetype icalt; ToIcalTime(&icalt); icalt.day = icaltime_days_in_month(icalt.month, icalt.year); icalt.is_date = 1; calDateTime * const cdt = new calDateTime(&icalt, mTimezone); CAL_ENSURE_MEMORY(cdt); NS_ADDREF(*aResult = cdt); return NS_OK; }
NS_IMETHODIMP calDateTime::GetStartOfMonth(calIDateTime ** aResult) { NS_ENSURE_ARG_POINTER(aResult); ensureTimezone(); icaltimetype icalt; ToIcalTime(&icalt); icalt.day = 1; icalt.is_date = 1; calDateTime * const cdt = new calDateTime(&icalt, mTimezone); CAL_ENSURE_MEMORY(cdt); NS_ADDREF(*aResult = cdt); return NS_OK; }
NS_IMETHODIMP calDateTime::GetEndOfWeek(calIDateTime ** aResult) { NS_ENSURE_ARG_POINTER(aResult); icaltimetype icalt; ToIcalTime(&icalt); int day_of_week = icaltime_day_of_week(icalt); if (day_of_week < 7) icaltime_adjust(&icalt, 7 - day_of_week, 0, 0, 0); icalt.is_date = 1; calDateTime * const cdt = new calDateTime(&icalt, mTimezone); CAL_ENSURE_MEMORY(cdt); NS_ADDREF(*aResult = cdt); return NS_OK; }
NS_IMETHODIMP calDateTime::AddDuration(calIDuration *aDuration) { NS_ENSURE_FALSE(mImmutable, NS_ERROR_OBJECT_IS_IMMUTABLE); NS_ENSURE_ARG_POINTER(aDuration); icaldurationtype idt; aDuration->ToIcalDuration(&idt); icaltimetype itt; ToIcalTime(&itt); icaltimetype const newitt = icaltime_add(itt, idt); FromIcalTime(&newitt, mTimezone); return NS_OK; }
NS_IMETHODIMP calDateTime::AddDuration(calIDuration *aDuration) { NS_ENSURE_FALSE(mImmutable, NS_ERROR_OBJECT_IS_IMMUTABLE); NS_ENSURE_ARG_POINTER(aDuration); ensureTimezone(); nsresult rv; nsCOMPtr<calIDurationLibical> icaldur = do_QueryInterface(aDuration, &rv); NS_ENSURE_SUCCESS(rv, rv); icaldurationtype idt; icaldur->ToIcalDuration(&idt); icaltimetype itt; ToIcalTime(&itt); icaltimetype const newitt = icaltime_add(itt, idt); FromIcalTime(&newitt, mTimezone); return NS_OK; }
NS_IMETHODIMP calDateTime::GetInTimezone(calITimezone * aTimezone, calIDateTime ** aResult) { NS_ENSURE_ARG_POINTER(aTimezone); NS_ENSURE_ARG_POINTER(aResult); if (mIsDate) { // if it's a date, we really just want to make a copy of this // and set the timezone. nsresult rv = Clone(aResult); if (NS_SUCCEEDED(rv)) { rv = (*aResult)->SetTimezone(aTimezone); } return rv; } else { icaltimetype icalt; ToIcalTime(&icalt); icaltimezone * tz = cal::getIcalTimezone(aTimezone); if (icalt.zone == tz) { return Clone(aResult); } /* If there's a zone, we need to convert; otherwise, we just * assign, since this item is floating */ if (icalt.zone && tz) { icaltimezone_convert_time(&icalt, const_cast<icaltimezone *>(icalt.zone), tz); } icalt.zone = tz; icalt.is_utc = (tz && tz == icaltimezone_get_utc_timezone()); calDateTime * cdt = new calDateTime(&icalt, aTimezone); CAL_ENSURE_MEMORY(cdt); NS_ADDREF (*aResult = cdt); return NS_OK; } }