Differences From Artifact [7fa6b61e6d]:
- File src/OFDate.m — part of check-in [cca678886f] at 2017-05-06 19:43:55 on branch trunk — Clean up a few includes (user: js, size: 14416) [annotate] [blame] [check-ins using]
To Artifact [7b7d9e6713]:
- File
src/OFDate.m
— part of check-in
[4af49a13c3]
at
2017-05-07 20:10:13
on branch trunk
— Small code style change
Casts are now written like types in variable declarations. (user: js, size: 14438) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
201 202 203 204 205 206 207 | + (instancetype)dateWithTimeIntervalSinceNow: (of_time_interval_t)seconds { return [[[self alloc] initWithTimeIntervalSinceNow: seconds] autorelease]; } | | | | | | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | + (instancetype)dateWithTimeIntervalSinceNow: (of_time_interval_t)seconds { return [[[self alloc] initWithTimeIntervalSinceNow: seconds] autorelease]; } + (instancetype)dateWithDateString: (OFString *)string format: (OFString *)format { return [[[self alloc] initWithDateString: string format: format] autorelease]; } + (instancetype)dateWithLocalDateString: (OFString *)string format: (OFString *)format { return [[[self alloc] initWithLocalDateString: string format: format] autorelease]; } + (instancetype)distantFuture { |
︙ | ︙ | |||
259 260 261 262 263 264 265 | self = [self init]; _seconds += seconds; return self; } | | | | 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | self = [self init]; _seconds += seconds; return self; } - initWithDateString: (OFString *)string format: (OFString *)format { self = [super init]; @try { const char *UTF8String = [string UTF8String]; struct tm tm = { 0 }; int16_t tz = 0; |
︙ | ︙ | |||
284 285 286 287 288 289 290 | [self release]; @throw e; } return self; } | | | | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | [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 }; /* |
︙ | ︙ | |||
323 324 325 326 327 328 329 | [self release]; @throw e; } return self; } | | | 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | [self release]; @throw e; } return self; } - initWithSerialization: (OFXMLElement *)element { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; union { |
︙ | ︙ | |||
406 407 408 409 410 411 412 | - (of_comparison_result_t)compare: (id <OFComparing>)object { OFDate *otherDate; if (![object isKindOfClass: [OFDate class]]) @throw [OFInvalidArgumentException exception]; | | | | | 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | - (of_comparison_result_t)compare: (id <OFComparing>)object { OFDate *otherDate; if (![object isKindOfClass: [OFDate class]]) @throw [OFInvalidArgumentException exception]; otherDate = (OFDate *)object; if (_seconds < otherDate->_seconds) return OF_ORDERED_ASCENDING; if (_seconds > otherDate->_seconds) return OF_ORDERED_DESCENDING; return OF_ORDERED_SAME; } - (OFString *)description { if (isinf(_seconds)) return (_seconds > 0 ? @"Distant Future" : @"Distant Past"); else return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"]; } - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; union { double d; uint64_t u; } d; |
︙ | ︙ | |||
527 528 529 530 531 532 533 | } - (uint16_t)localDayOfYear { LOCALTIME_RET(tm_yday + 1) } | | | 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | } - (uint16_t)localDayOfYear { LOCALTIME_RET(tm_yday + 1) } - (OFString *)dateStringWithFormat: (OFConstantString *)format { OFString *ret; time_t seconds = (time_t)_seconds; struct tm tm; size_t pageSize; #ifndef OF_WINDOWS char *buffer; |
︙ | ︙ | |||
587 588 589 590 591 592 593 | } @finally { [self freeMemory: buffer]; } return ret; } | | | 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 | } @finally { [self freeMemory: buffer]; } return ret; } - (OFString *)localDateStringWithFormat: (OFConstantString *)format { OFString *ret; time_t seconds = (time_t)_seconds; struct tm tm; size_t pageSize; #ifndef OF_WINDOWS char *buffer; |
︙ | ︙ | |||
647 648 649 650 651 652 653 | } @finally { [self freeMemory: buffer]; } return ret; } | | | | | | 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | } @finally { [self freeMemory: buffer]; } return ret; } - (OFDate *)earlierDate: (OFDate *)otherDate { if (otherDate == nil) return [[self retain] autorelease]; if ([self compare: otherDate] == OF_ORDERED_DESCENDING) return [[otherDate retain] autorelease]; return [[self retain] autorelease]; } - (OFDate *)laterDate: (OFDate *)otherDate { if (otherDate == nil) return [[self retain] autorelease]; if ([self compare: otherDate] == OF_ORDERED_ASCENDING) return [[otherDate retain] autorelease]; return [[self retain] autorelease]; } - (of_time_interval_t)timeIntervalSince1970 { return _seconds; } - (of_time_interval_t)timeIntervalSinceDate: (OFDate *)otherDate { return _seconds - otherDate->_seconds; } - (of_time_interval_t)timeIntervalSinceNow { struct timeval t; of_time_interval_t seconds; OF_ENSURE(gettimeofday(&t, NULL) == 0); seconds = t.tv_sec; seconds += (of_time_interval_t)t.tv_usec / 1000000; return _seconds - seconds; } - (OFDate *)dateByAddingTimeInterval: (of_time_interval_t)seconds { return [OFDate dateWithTimeIntervalSince1970: _seconds + seconds]; } @end |