Differences From Artifact [03b1ee2aba]:
- File
src/OFDate.m
— part of check-in
[e1e7ffa903]
at
2011-09-22 23:25:42
on branch trunk
— Exceptions are now autoreleased.
This is safe as an "exception loop" can't happen, since if allocating
an exception fails, it throws an OFAllocFailedException which is
preallocated and can always be thrown.So, the worst case would be that an autorelease of an exception fails,
triggering an OFOutOfMemoryException for which there is no memory,
resulting in an OFAllocFailedException to be thrown. (user: js, size: 11529) [annotate] [blame] [check-ins using]
To Artifact [396325df1e]:
- File
src/OFDate.m
— part of check-in
[4fc7884fb1]
at
2011-10-28 21:30:36
on branch trunk
— Parse struct tm ourselves.
This way, we don't need tm_gmtoff, which we would otherwise need to
adjust the value parsed by mktime, and don't need timegm either. (user: js, size: 12356) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
129 130 131 132 133 134 135 136 137 138 139 140 141 142 | \ if ((tm = localtime(&seconds_)) == NULL) \ @throw [OFOutOfRangeException exceptionWithClass: isa]; \ \ return tm->field; # endif #endif @implementation OFDate #if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \ defined(OF_THREADS) + (void)initialize { if (self == [OFDate class]) | > > > > > > > > > > > > > > > | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | \ if ((tm = localtime(&seconds_)) == NULL) \ @throw [OFOutOfRangeException exceptionWithClass: isa]; \ \ return tm->field; # endif #endif static int month_to_day_of_year[12] = { 31, 31 + 28, 31 + 28 + 31, 31 + 28 + 31 + 30, 31 + 28 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30, 31 + 28 + 31 + 30 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30, 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 }; @implementation OFDate #if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \ defined(OF_THREADS) + (void)initialize { if (self == [OFDate class]) |
︙ | ︙ | |||
230 231 232 233 234 235 236 | tm.tm_isdst = -1; if (strptime([string UTF8String], [format UTF8String], &tm) == NULL) @throw [OFInvalidFormatException exceptionWithClass: isa]; | > | > > | > > > > | > > > | > > > > | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | tm.tm_isdst = -1; if (strptime([string UTF8String], [format UTF8String], &tm) == NULL) @throw [OFInvalidFormatException exceptionWithClass: isa]; #ifdef STRUCT_TM_HAS_TM_GMTOFF if (tm.tm_gmtoff != 0) @throw [OFInvalidFormatException exceptionWithClass: isa]; #endif /* Years */ seconds = (tm.tm_year - 70) * 31536000; /* Leap years */ seconds += ((tm.tm_year / 4) - 17) * 86400; /* Months */ if (tm.tm_mon < 0 || tm.tm_mon > 12) @throw [OFInvalidFormatException exceptionWithClass: isa]; seconds += month_to_day_of_year[tm.tm_mon - 1] * 86400; /* Days */ seconds += (tm.tm_mday - 1) * 86400; /* Hours */ seconds += tm.tm_hour * 3600; /* Minutes */ seconds += tm.tm_min * 60; /* Seconds */ seconds += tm.tm_sec; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ |