435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
{
return [self initWithTimeIntervalSince1970: now() + seconds];
}
- (instancetype)initWithDateString: (OFString *)string
format: (OFString *)format
{
const char *UTF8String = string.UTF8String;
struct tm tm = { .tm_isdst = -1 };
int16_t tz = 0;
if (of_strptime(UTF8String, format.UTF8String, &tm, &tz) !=
UTF8String + string.UTF8StringLength)
@throw [OFInvalidFormatException exception];
return [self initWithTimeIntervalSince1970: tmAndTzToTime(&tm, &tz)];
}
- (instancetype)initWithLocalDateString: (OFString *)string
format: (OFString *)format
{
const char *UTF8String = string.UTF8String;
struct tm tm = { .tm_isdst = -1 };
/*
* 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.
*/
|
>
>
>
>
|
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
{
return [self initWithTimeIntervalSince1970: now() + seconds];
}
- (instancetype)initWithDateString: (OFString *)string
format: (OFString *)format
{
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = string.UTF8String;
struct tm tm = { .tm_isdst = -1 };
int16_t tz = 0;
if (of_strptime(UTF8String, format.UTF8String, &tm, &tz) !=
UTF8String + string.UTF8StringLength)
@throw [OFInvalidFormatException exception];
objc_autoreleasePoolPop(pool);
return [self initWithTimeIntervalSince1970: tmAndTzToTime(&tm, &tz)];
}
- (instancetype)initWithLocalDateString: (OFString *)string
format: (OFString *)format
{
void *pool = objc_autoreleasePoolPush();
const char *UTF8String = string.UTF8String;
struct tm tm = { .tm_isdst = -1 };
/*
* 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.
*/
|
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
if ((seconds = mktime(&tm)) == -1)
@throw [OFInvalidFormatException exception];
#ifdef OF_WINDOWS
}
#endif
} else
seconds = tmAndTzToTime(&tm, &tz);
return [self initWithTimeIntervalSince1970: seconds];
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
of_time_interval_t seconds;
|
>
>
|
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
if ((seconds = mktime(&tm)) == -1)
@throw [OFInvalidFormatException exception];
#ifdef OF_WINDOWS
}
#endif
} else
seconds = tmAndTzToTime(&tm, &tz);
objc_autoreleasePoolPop(pool);
return [self initWithTimeIntervalSince1970: seconds];
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
of_time_interval_t seconds;
|