Пример #1
0
RSExport void RSCalendarSetTimeZone(RSCalendarRef calendar, RSTimeZoneRef tz)
{
    if (__RSCalendarAvailable(calendar) && (RSGetTypeID(tz) == RSTimeZoneGetTypeID()))
    {
        __RSCalendarSetTimeZone(calendar, tz);
    }
}
RSExport RSDictionaryRef RSDictionaryCreateWithData(RSAllocatorRef allocator, RSDataRef data)
{
    RSDictionaryRef dictionary = nil;
    RSPropertyListRef plist = RSPropertyListCreateWithXMLData(allocator, data);
    if (plist)  RSGetTypeID(RSPropertyListGetContent(plist)) == RSDictionaryGetTypeID() ? dictionary = RSRetain(RSPropertyListGetContent(plist)) : nil;
    RSRelease(plist);
    return dictionary;
}
RSExport RSDictionaryRef RSDictionaryCreateWithContentOfPath(RSAllocatorRef allocator, RSStringRef path)
{
    RSDictionaryRef dictionary = nil;
    RSPropertyListRef plist = RSPropertyListCreateWithPath(allocator, path);
    if (plist)  RSGetTypeID(RSPropertyListGetContent(plist)) == RSDictionaryGetTypeID() ? dictionary = RSRetain(RSPropertyListGetContent(plist)) : nil;
    RSRelease(plist);
    return dictionary;
}
Пример #4
0
RSExport RSBitU32 RSAbsoluteTimeGetDayOfWeek(RSAbsoluteTime at, RSTimeZoneRef tz)
{
    int64_t absolute;
    RSAbsoluteTime fixedat;
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
    if (tz) {
        if (RSTimeZoneGetTypeID() != RSGetTypeID(tz)) HALTWithError(RSInvalidArgumentException, "timezone is not kind of RSTimeZone");
    }
    fixedat = at + (nil != tz ? RSTimeZoneGetSecondsFromGMT(tz, at) : 0.0);
#else
    fixedat = at;
#endif
    absolute = (int64_t)floor(fixedat / 86400.0);
    return (absolute < 0) ? ((absolute + 1) % 7 + 7) : (absolute % 7 + 1); /* Monday = 1, etc. */
}
Пример #5
0
RSExport RSBitU32 RSAbsoluteTimeGetDayOfYear(RSAbsoluteTime at, RSTimeZoneRef tz)
{
    RSAbsoluteTime fixedat;
    int64_t absolute, year;
    int8_t month, day;
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
    if (tz) {
        if (RSTimeZoneGetTypeID() != RSGetTypeID(tz)) HALTWithError(RSInvalidArgumentException, "timezone is not kind of RSTimeZone");
    }
    fixedat = at + (nil != tz ? RSTimeZoneGetSecondsFromGMT(tz, at) : 0.0);
#else
    fixedat = at;
#endif
    absolute = (int64_t)floor(fixedat / 86400.0);
    __RSYMDFromAbsolute(absolute, &year, &month, &day);
    return __RSDaysBeforeMonth(month, year, isleap(year)) + day;
}
Пример #6
0
RSExport RSBitU32 RSAbsoluteTimeGetWeekOfYear(RSAbsoluteTime at, RSTimeZoneRef tz)
{
    int64_t absolute, year;
    int8_t month, day;
    RSAbsoluteTime fixedat;
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX
    if (tz) {
        if (RSTimeZoneGetTypeID() != RSGetTypeID(tz)) HALTWithError(RSInvalidArgumentException, "timezone is not kind of RSTimeZone");
    }
    fixedat = at + (nil != tz ? RSTimeZoneGetSecondsFromGMT(tz, at) : 0.0);
#else
    fixedat = at;
#endif
    absolute = (int64_t)floor(fixedat / 86400.0);
    __RSYMDFromAbsolute(absolute, &year, &month, &day);
    double absolute0101 = __RSAbsoluteFromYMD(year, 1, 1);
    int64_t dow0101 = __RSDoubleModToInt(absolute0101, 7) + 1;
    /* First three and last three days of a year can end up in a week of a different year */
    if (1 == month && day < 4)
    {
        if ((day < 4 && 5 == dow0101) || (day < 3 && 6 == dow0101) || (day < 2 && 7 == dow0101)) {
            return 53;
        }
    }
    if (12 == month && 28 < day)
    {
        double absolute20101 = __RSAbsoluteFromYMD(year + 1, 1, 1);
        int64_t dow20101 = __RSDoubleModToInt(absolute20101, 7) + 1;
        if ((28 < day && 4 == dow20101) || (29 < day && 3 == dow20101) || (30 < day && 2 == dow20101))
        {
            return 1;
        }
    }
    /* Days into year, plus a week-shifting correction, divided by 7. First week is 1. */
    return (__RSDaysBeforeMonth(month, year, isleap(year)) + day + (dow0101 - 11) % 7 + 2) / 7 + 1;
}
Пример #7
0
static  void __RSDateAvailable(RSDateRef date)
{
    if (date == nil) HALTWithError(RSInvalidArgumentException, "date is nil");
    if (RSGetTypeID(date) != RSDateGetTypeID()) HALTWithError(RSInvalidArgumentException, "date is not kind of RSDate");
    return;
}
Пример #8
0
static BOOL __RSCalendarAvailable(RSCalendarRef calendar)
{
    if (calendar == nil) return NO;
    if (RSGetTypeID(calendar) != RSCalendarGetTypeID()) HALTWithError(RSInvalidArgumentException, "calendar not available");
    return YES;
}