RSExport RSTimeZoneRef RSTimeZoneCopyDefault() { return RSTimeZoneCopySystem(); }
RSExport RSCalendarRef RSCalendarCreateWithIndentifier(RSAllocatorRef allocator, RSStringRef identifier) { RSCalendarRef calendar = __RSCalendarCreateInstance(allocator, identifier); RSCalendarSetTimeZone(calendar, RSTimeZoneCopySystem()); return calendar; }
RSExport RSDateRef RSDateCreateWithString(RSAllocatorRef allocator, RSStringRef value) { const int dateLength = 20; RSDateRef _v = nil; //%04d-%02d-%02dT%02d:%02d:%02dZ //4 +1 +2 +1 +2 +1 +2 +1 +2 +1 +2 +1 //%04d - %02d - %02d T %02d : %02d : %02d Z //5,3,3,3,3,3 = 20 if (dateLength == RSStringGetLength(value)) { UniChar ptr[6] = {0}; ptr[0] = RSStringGetCharacterAtIndex(value, 5 - 1); //- ptr[1] = RSStringGetCharacterAtIndex(value, 8 - 1); //- ptr[2] = RSStringGetCharacterAtIndex(value, 11 - 1);//T ptr[3] = RSStringGetCharacterAtIndex(value, 14 - 1);//: ptr[4] = RSStringGetCharacterAtIndex(value, 17 - 1);//: ptr[5] = RSStringGetCharacterAtIndex(value, 20 - 1);//Z if ((ptr[0] == ptr[1]) && (ptr[1] == '-') && (ptr[2] == 'T') && (ptr[3] == ptr[4]) && (ptr[4] == ':') && (ptr[5] == 'Z')) { #if 0 UTF8Char year[5] = {0}; UTF8Char month[3] = {0}; UTF8Char day[3] = {0}; UTF8Char hour[3] = {0}; UTF8Char minute[3] = {0}; UTF8Char second[3] = {0}; RSStringGetUTF8Characters(value, RSMakeRange(0, 4), year); RSStringGetUTF8Characters(value, RSMakeRange(5, 2), month); RSStringGetUTF8Characters(value, RSMakeRange(8, 2), day); RSStringGetUTF8Characters(value, RSMakeRange(11, 2), hour); RSStringGetUTF8Characters(value, RSMakeRange(14, 2), minute); RSStringGetUTF8Characters(value, RSMakeRange(17, 2), second); RSGregorianDate gd = {0}; gd.year = atoi((const char*)year); gd.month= atoi((const char*)month); gd.day = atoi((const char*)day); gd.hour = atoi((const char*)hour); gd.minute = atoi((const char*)minute); gd.second = atoi((const char*)second); #else RSGregorianDate gd = {0}; UniChar payload[4] = {0}; RSIndex tmp = 0; RSStringGetCharacters(value, RSMakeRange(0, 4), payload); if (!__unichar2i(payload, 4, &tmp)) return nil; gd.year = (RSBitU32)tmp; memset(payload, 0, sizeof(payload)); RSStringGetCharacters(value, RSMakeRange(5, 2), payload); if (!__unichar2i(payload, 2, &tmp)) return nil; gd.month = (RSBitU8)tmp; if (__dateCheckRange(gd.month, 1, 12) == NO) return nil; RSStringGetCharacters(value, RSMakeRange(8, 2), payload); if (!__unichar2i(payload, 2, &tmp)) return nil; gd.day = (RSBitU8)tmp; int maxm = 0; switch (gd.month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: maxm = 31; break; case 2: maxm = 28; break; default: maxm = 30; break; } if ((gd.year % 400 == 0) || ((gd.year % 100 != 0) && (gd.year % 4 == 0))) { maxm++; } if (maxm > 32) HALTWithError(RSInvalidArgumentException, "maxm > 32"); if (__dateCheckRange(gd.day, 1, maxm) == NO) return nil; RSStringGetCharacters(value, RSMakeRange(11, 2), payload); if (!__unichar2i(payload, 2, &tmp)) return nil; gd.hour = (RSBitU8)tmp; if (__dateCheckRange(gd.day, 0, 59) == NO) return nil; RSStringGetCharacters(value, RSMakeRange(14, 2), payload); if (!__unichar2i(payload, 2, &tmp)) return nil; gd.minute = (RSBitU8)tmp; if (__dateCheckRange(gd.day, 0, 59) == NO) return nil; RSStringGetCharacters(value, RSMakeRange(17, 2), payload); if (!__unichar2i(payload, 2, &tmp)) return nil; gd.second = (RSBitU8)tmp; if (__dateCheckRange(gd.day, 0, 59) == NO) return nil; #endif _v = RSDateCreate(allocator, RSGregorianDateGetAbsoluteTime(gd, RSTimeZoneCopySystem())); } } return _v; }
static void __RSCalendarSetTimeZone(RSCalendarRef calendar, RSTimeZoneRef tz) { if (calendar->_tz) RSRelease(calendar->_tz); if (tz) calendar->_tz = RSRetain(tz); else calendar->_tz = RSTimeZoneCopySystem(); }