Add 10.9 methods for getEra:..., getHour:... etc

This commit is contained in:
Gregory John Casamento 2022-04-04 19:26:22 -04:00
parent 38b14bb8ec
commit cb87724a21
2 changed files with 106 additions and 0 deletions

View file

@ -329,6 +329,27 @@ GS_EXPORT_CLASS
interval: (NSTimeInterval *)tip
forDate: (NSDate *)date;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
- (void) getEra: (NSInteger *)eraValuePointer
year: (NSInteger *)yearValuePointer
month: (NSInteger *)monthValuePointer
day: (NSInteger *)dayValuePointer
fromDate: (NSDate *)date;
- (void) getHour: (NSInteger *)hourValuePointer
minute: (NSInteger *)minuteValuePointer
second: (NSInteger *)secondValuePointer
nanosecond: (NSInteger *)nanosecondValuePointer
fromDate: (NSDate *)date;
- (void) getEra: (NSInteger *)eraValuePointer
yearForWeekOfYear: (NSInteger *)yearValuePointer
weekOfYear: (NSInteger *)weekValuePointer
weekday: (NSInteger *)weekdayValuePointer
fromDate: (NSDate *)date;
#endif
@end
#if defined(__cplusplus)

View file

@ -848,6 +848,91 @@ do \
#endif
}
- (void) getEra: (NSInteger *)eraValuePointer
year: (NSInteger *)yearValuePointer
month: (NSInteger *)monthValuePointer
day: (NSInteger *)dayValuePointer
fromDate: (NSDate *)date
{
#if GS_USE_ICU == 1
UErrorCode err = U_ZERO_ERROR;
UDate udate;
[self _resetCalendar];
ucal_clear (my->cal);
udate = (UDate)floor([date timeIntervalSince1970] * 1000.0);
ucal_setMillis (my->cal, udate, &err);
if (U_FAILURE(err))
return;
if (eraValuePointer != NULL)
*eraValuePointer = ucal_get(my->cal, UCAL_ERA, &err);
if (yearValuePointer != NULL)
*yearValuePointer = ucal_get(my->cal, UCAL_YEAR, &err);
if (monthValuePointer != NULL)
*monthValuePointer = ucal_get(my->cal, UCAL_MONTH, &err) + 1;
if (dayValuePointer != NULL)
*dayValuePointer = ucal_get(my->cal, UCAL_DAY_OF_MONTH, &err);
#endif
}
- (void) getHour: (NSInteger *)hourValuePointer
minute: (NSInteger *)minuteValuePointer
second: (NSInteger *)secondValuePointer
nanosecond: (NSInteger *)nanosecondValuePointer
fromDate: (NSDate *)date
{
#if GS_USE_ICU == 1
UErrorCode err = U_ZERO_ERROR;
UDate udate;
[self _resetCalendar];
ucal_clear (my->cal);
udate = (UDate)floor([date timeIntervalSince1970] * 1000.0);
ucal_setMillis (my->cal, udate, &err);
if (U_FAILURE(err))
return;
if (hourValuePointer != NULL)
*hourValuePointer = ucal_get(my->cal, UCAL_HOUR_OF_DAY, &err);
if (minuteValuePointer != NULL)
*minuteValuePointer = ucal_get(my->cal, UCAL_MINUTE, &err);
if (secondValuePointer != NULL)
*secondValuePointer = ucal_get(my->cal, UCAL_SECOND, &err);
if (nanosecondValuePointer != NULL)
*nanosecondValuePointer = ucal_get(my->cal, UCAL_MILLISECOND, &err) * 1000;
#endif
}
- (void) getEra: (NSInteger *)eraValuePointer
yearForWeekOfYear: (NSInteger *)yearValuePointer
weekOfYear: (NSInteger *)weekValuePointer
weekday: (NSInteger *)weekdayValuePointer
fromDate: (NSDate *)date
{
#if GS_USE_ICU == 1
UErrorCode err = U_ZERO_ERROR;
UDate udate;
[self _resetCalendar];
ucal_clear (my->cal);
udate = (UDate)floor([date timeIntervalSince1970] * 1000.0);
ucal_setMillis (my->cal, udate, &err);
if (U_FAILURE(err))
return;
if (eraValuePointer != NULL)
*eraValuePointer = ucal_get(my->cal, UCAL_ERA, &err);
if (yearValuePointer != NULL)
*yearValuePointer = ucal_get(my->cal, UCAL_YEAR_WOY, &err);
if (weekValuePointer != NULL)
*weekValuePointer = ucal_get(my->cal, UCAL_WEEK_OF_YEAR, &err);
if (weekdayValuePointer != NULL)
*weekdayValuePointer = ucal_get(my->cal, UCAL_DAY_OF_WEEK, &err);
#endif
}
- (void) encodeWithCoder: (NSCoder*)encoder
{
[encoder encodeObject: my->identifier];