Differences From Artifact [6c84c9ff36]:
- File
src/OFDate.m
— part of check-in
[e4439b7ef8]
at
2016-09-11 22:03:20
on branch trunk
— OFDate: Add support for parsing time zones
This adds %z for parsing time zones. Additionally, this also adds %a and
%b. (user: js, size: 14281) [annotate] [blame] [check-ins using]
To Artifact [125716a7f2]:
- File src/OFDate.m — part of check-in [804f222e18] at 2016-09-11 22:23:45 on branch trunk — OFDate: Throw on trailing garbage (user: js, size: 14427) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
266 267 268 269 270 271 272 273 274 275 276 277 | - initWithDateString: (OFString*)string format: (OFString*)format { self = [super init]; @try { struct tm tm = { 0 }; int16_t tz = 0; tm.tm_isdst = -1; | > | | > | | | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | - initWithDateString: (OFString*)string format: (OFString*)format { self = [super init]; @try { const char *UTF8String = [string UTF8String]; struct tm tm = { 0 }; int16_t tz = 0; tm.tm_isdst = -1; if (of_strptime(UTF8String, [format UTF8String], &tm, &tz) != UTF8String + [string UTF8StringLength]) @throw [OFInvalidFormatException exception]; _seconds = tmAndTzToTime(&tm, &tz); } @catch (id e) { [self release]; @throw e; } return self; } - initWithLocalDateString: (OFString*)string format: (OFString*)format { self = [super init]; @try { const char *UTF8String = [string UTF8String]; struct tm tm = { 0 }; /* * of_strptime() can never set this to INT16_MAX, no matter * what is passed to it, so this is a safe way to figure out if * the date contains a time zone. */ int16_t tz = INT16_MAX; tm.tm_isdst = -1; if (of_strptime(UTF8String, [format UTF8String], &tm, &tz) != UTF8String + [string UTF8StringLength]) @throw [OFInvalidFormatException exception]; if (tz == INT16_MAX) { #ifndef OF_WINDOWS if ((_seconds = mktime(&tm)) == -1) @throw [OFInvalidFormatException exception]; #else |
︙ | ︙ |