ObjFW  Check-in [2cc53cf92d]

Overview
Comment:Add a few more methods to OFDate.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2cc53cf92d74e2889f049544e2da0164ac98bf25e0367134d0d272784270df6d
User & Date: js on 2011-01-03 21:33:03
Other Links: manifest | tags
Context
2011-01-03
21:48
Fix a typo in Makefile. check-in: 71df4f6b30 user: js tags: trunk
21:33
Add a few more methods to OFDate. check-in: 2cc53cf92d user: js tags: trunk
2011-01-01
20:19
Change license. check-in: da6b3d26cb user: js tags: trunk
Changes

Modified src/OFDate.h from [dcf8e442d6] to [49341feeb2].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

/**
 * \return A new, autoreleased OFDate with the current date and time
 */
+ date;

/**
 * \param sec The seconds since 1970-01-01 00:00:00
 * \return A new, autoreleased OFDate with the specified date and time
 */
+ dateWithTimeIntervalSince1970: (int64_t)sec;

/**
 * \param sec The seconds since 1970-01-01 00:00:00
 * \param usec The microsecond part of the time
 * \return A new, autoreleased OFDate with the specified date and time
 */
+ dateWithTimeIntervalSince1970: (int64_t)sec
		   microseconds: (uint32_t)usec;

/**







|





|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

/**
 * \return A new, autoreleased OFDate with the current date and time
 */
+ date;

/**
 * \param sec The seconds since 1970-01-01T00:00:00Z
 * \return A new, autoreleased OFDate with the specified date and time
 */
+ dateWithTimeIntervalSince1970: (int64_t)sec;

/**
 * \param sec The seconds since 1970-01-01T00:00:00Z
 * \param usec The microsecond part of the time
 * \return A new, autoreleased OFDate with the specified date and time
 */
+ dateWithTimeIntervalSince1970: (int64_t)sec
		   microseconds: (uint32_t)usec;

/**
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 * \return A date in the distant past
 */
+ distantPast;

/**
 * Initializes an already allocated OFDate with the specified date and time.
 *
 * \param sec The seconds since 1970-01-01 00:00:00
 * \return An initialized OFDate with the specified date and time
 */
- initWithTimeIntervalSince1970: (int64_t)sec;

/**
 * Initializes an already allocated OFDate with the specified date and time.
 *
 * \param sec The seconds since 1970-01-01 00:00:00
 * \param usec The microsecond part of the time
 * \return An initialized OFDate with the specified date and time
 */
- initWithTimeIntervalSince1970: (int64_t)sec
		   microseconds: (uint32_t)usec;

/**







|







|







73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
 * \return A date in the distant past
 */
+ distantPast;

/**
 * Initializes an already allocated OFDate with the specified date and time.
 *
 * \param sec The seconds since 1970-01-01T00:00:00Z
 * \return An initialized OFDate with the specified date and time
 */
- initWithTimeIntervalSince1970: (int64_t)sec;

/**
 * Initializes an already allocated OFDate with the specified date and time.
 *
 * \param sec The seconds since 1970-01-01T00:00:00Z
 * \param usec The microsecond part of the time
 * \return An initialized OFDate with the specified date and time
 */
- initWithTimeIntervalSince1970: (int64_t)sec
		   microseconds: (uint32_t)usec;

/**
209
210
211
212
213
214
215




















216
217
218
219
220
221
222

/**
 * \param date Another date
 * \return The later date of the two dates
 */
- (OFDate*)laterDate: (OFDate*)date;





















/**
 * Returns a new date with the specified time interval added.
 *
 * \param sec The seconds after the date
 * \return A new, autoreleased OFDate
 */
- (OFDate*)dateByAddingTimeInterval: (int64_t)sec;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242

/**
 * \param date Another date
 * \return The later date of the two dates
 */
- (OFDate*)laterDate: (OFDate*)date;

/**
 * \return The seconds since 1970-01-01T00:00:00Z
 */
- (int64_t)timeIntervalSince1970;

/**
 * \return The microseconds part of the seconds since 1970-01-01T00:00:00Z
 */
- (uint32_t)microsecondsOfTimeIntervalSince1970;

/**
 * \return The seconds the date is after the receiver
 */
- (int64_t)timeIntervalSinceDate: (OFDate*)date;

/**
 * \return The microseconds part of the seconds the date is after the receiver
 */
- (uint32_t)microsecondsOfTimeIntervalSinceDate: (OFDate*)date;

/**
 * Returns a new date with the specified time interval added.
 *
 * \param sec The seconds after the date
 * \return A new, autoreleased OFDate
 */
- (OFDate*)dateByAddingTimeInterval: (int64_t)sec;

Modified src/OFDate.m from [5fce8dec4c] to [31a8bddc6c].

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
{
	self = [self init];

	sec += sec_;
	usec += usec_;

	while (usec > 999999) {
		usec -= 999999;
		sec++;
	}

	return self;
}

- (BOOL)isEqual: (id)obj







|







223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
{
	self = [self init];

	sec += sec_;
	usec += usec_;

	while (usec > 999999) {
		usec -= 10000000;
		sec++;
	}

	return self;
}

- (BOOL)isEqual: (id)obj
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# ifdef OF_THREADS
	[mutex lock];

	@try {
# endif
		struct tm *tmp;

		if ((tmp = gmtime(&sec)) == NULL)
			@throw [OFOutOfRangeException newWithClass: isa];

		tm = *tmp;
# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}







|







359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
# ifdef OF_THREADS
	[mutex lock];

	@try {
# endif
		struct tm *tmp;

		if ((tmp = gmtime(&sec_)) == NULL)
			@throw [OFOutOfRangeException newWithClass: isa];

		tm = *tmp;
# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# ifdef OF_THREADS
	[mutex lock];

	@try {
# endif
		struct tm *tmp;

		if ((tmp = localtime(&sec)) == NULL)
			@throw [OFOutOfRangeException newWithClass: isa];

		tm = *tmp;
# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}







|







402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# ifdef OF_THREADS
	[mutex lock];

	@try {
# endif
		struct tm *tmp;

		if ((tmp = localtime(&sec_)) == NULL)
			@throw [OFOutOfRangeException newWithClass: isa];

		tm = *tmp;
# ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
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
467
468
- (OFDate*)laterDate: (OFDate*)date
{
	if ([self compare: date] == OF_ORDERED_ASCENDING)
		return [[date retain] autorelease];

	return [[self retain] autorelease];
}










































- (OFDate*)dateByAddingTimeInterval: (int64_t)sec_
{
	return [self dateByAddingTimeInterval: sec_
			     withMicroseconds: 0];
}

- (OFDate*)dateByAddingTimeInterval: (int64_t)sec_
		   withMicroseconds: (uint32_t)usec_
{
	sec_ += sec;
	usec_ += usec;

	while (usec_ > 999999) {
		usec_ -= 999999;
		sec_++;
	}

	return [OFDate dateWithTimeIntervalSince1970: sec_
					microseconds: usec_];
}
@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>














|







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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
- (OFDate*)laterDate: (OFDate*)date
{
	if ([self compare: date] == OF_ORDERED_ASCENDING)
		return [[date retain] autorelease];

	return [[self retain] autorelease];
}

- (int64_t)timeIntervalSince1970
{
	return sec;
}

- (uint32_t)microsecondsOfTimeIntervalSince1970
{
	return usec;
}

- (int64_t)timeIntervalSinceDate: (OFDate*)date
{
	int64_t sec_ = sec - date->sec;
	int32_t usec_ = (int32_t)usec - date->usec;

	while (usec_ > 999999) {
		usec_ -= 1000000;
		sec_++;
	}

	while (usec < 0) {
		usec_ += 1000000;
		sec_--;
	}

	return sec_;
}

- (uint32_t)microsecondsOfTimeIntervalSinceDate: (OFDate*)date
{
	int32_t usec_ = (int32_t)usec - date->usec;

	while (usec_ > 999999)
		usec_ -= 1000000;

	while (usec < 0)
		usec_ += 1000000;

	return usec_;
}

- (OFDate*)dateByAddingTimeInterval: (int64_t)sec_
{
	return [self dateByAddingTimeInterval: sec_
			     withMicroseconds: 0];
}

- (OFDate*)dateByAddingTimeInterval: (int64_t)sec_
		   withMicroseconds: (uint32_t)usec_
{
	sec_ += sec;
	usec_ += usec;

	while (usec_ > 999999) {
		usec_ -= 1000000;
		sec_++;
	}

	return [OFDate dateWithTimeIntervalSince1970: sec_
					microseconds: usec_];
}
@end