CFDateRef CFCalendarCopyGregorianStartDate(CFCalendarRef calendar) { CF_OBJC_FUNCDISPATCHV(CFCalendarGetTypeID(), CFDateRef, calendar, _gregorianStartDate); __CFGenericValidateType(calendar, CFCalendarGetTypeID()); if (!calendar->_cal) __CFCalendarSetupCal(calendar); UErrorCode status = U_ZERO_ERROR; UDate udate = calendar->_cal ? ucal_getGregorianChange(calendar->_cal, &status) : 0; if (calendar->_cal && U_SUCCESS(status)) { CFAbsoluteTime at = (double)udate / 1000.0 - kCFAbsoluteTimeIntervalSince1970; return CFDateCreate(CFGetAllocator(calendar), at); } return NULL; }
RSExport RSDateRef RSCalendarCopyGregorianStartDate(RSCalendarRef calendar) { RS_OBJC_FUNCDISPATCHV(RSCalendarGetTypeID(), RSDateRef, calendar, _gregorianStartDate); __RSGenericValidInstance(calendar, RSCalendarGetTypeID()); if (!calendar->_cal) __RSCalendarSetupCal(calendar); UErrorCode status = U_ZERO_ERROR; UDate udate = calendar->_cal ? ucal_getGregorianChange(calendar->_cal, &status) : 0; if (calendar->_cal && U_SUCCESS(status)) { RSAbsoluteTime at = (double)udate / 1000.0 - RSAbsoluteTimeIntervalSince1970; return RSDateCreate(RSGetAllocator(calendar), at); } return nil; }
void CFCalendarSetGregorianStartDate(CFCalendarRef calendar, CFDateRef date) { CF_OBJC_FUNCDISPATCHV(CFCalendarGetTypeID(), void, calendar, _setGregorianStartDate:date); __CFGenericValidateType(calendar, CFCalendarGetTypeID()); if (date) __CFGenericValidateType(date, CFDateGetTypeID()); if (!calendar->_cal) __CFCalendarSetupCal(calendar); if (!calendar->_cal) return; if (!date) { UErrorCode status = U_ZERO_ERROR; UCalendar *cal = __CFCalendarCreateUCalendar(calendar->_identifier, calendar->_localeID, calendar->_tz); UDate udate = cal ? ucal_getGregorianChange(cal, &status) : 0; if (cal && U_SUCCESS(status)) { status = U_ZERO_ERROR; if (calendar->_cal) ucal_setGregorianChange(calendar->_cal, udate, &status); } if (cal) ucal_close(cal); } else { CFAbsoluteTime at = CFDateGetAbsoluteTime(date); UDate udate = (at + kCFAbsoluteTimeIntervalSince1970) * 1000.0; UErrorCode status = U_ZERO_ERROR; if (calendar->_cal) ucal_setGregorianChange(calendar->_cal, udate, &status); } }