ObjFW  Check-in [3ba1a97679]

Overview
Comment:OFDate: Don't use inf for -[distant{Future,Past}]

This way, they are no longer special cases.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3ba1a9767997f908b4ebe5c202166a9f4474867999d0f903dcb7dd68b27fa8bb
User & Date: js on 2017-05-14 23:31:21
Other Links: manifest | tags
Context
2017-05-14
23:33
OFNumber: Handle int endianess != float endianess check-in: e29e71523e user: js tags: trunk
23:31
OFDate: Don't use inf for -[distant{Future,Past}] check-in: 3ba1a97679 user: js tags: trunk
21:29
Add OFHTTPCookieManager check-in: 28bacc2aa0 user: js tags: trunk
Changes

Modified src/OFDate.m from [ada236f2a0] to [388aebd154].

218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
	return [[[self alloc] initWithLocalDateString: string
					       format: format] autorelease];
}

+ (instancetype)distantFuture
{
	return [[[self alloc]
	    initWithTimeIntervalSince1970: INFINITY] autorelease];
}

+ (instancetype)distantPast
{
	return [[[self alloc]
	    initWithTimeIntervalSince1970: -INFINITY] autorelease];
}

- init
{
	struct timeval t;

	self = [super init];







|





|







218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
	return [[[self alloc] initWithLocalDateString: string
					       format: format] autorelease];
}

+ (instancetype)distantFuture
{
	return [[[self alloc]
	    initWithTimeIntervalSince1970: 64060588800.0] autorelease];
}

+ (instancetype)distantPast
{
	return [[[self alloc]
	    initWithTimeIntervalSince1970: -62167219200.0] autorelease];
}

- init
{
	struct timeval t;

	self = [super init];
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362

- initWithSerialization: (OFXMLElement *)element
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();
		OFString *stringValue;
		union {
			double d;
			uint64_t u;
		} d;

		if (![[element name] isEqual: [self className]] ||
		    ![[element namespace] isEqual: OF_SERIALIZATION_NS])
			@throw [OFInvalidArgumentException exception];

		stringValue = [element stringValue];

		if ([stringValue isEqual: @"DISTANT_PAST"])
			_seconds = -INFINITY;
		else if ([stringValue isEqual: @"DISTANT_FUTURE"])
			_seconds = INFINITY;
		else {
			d.u = (uint64_t)[element hexadecimalValue];
			_seconds = d.d;
		}

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}








<









<
<
<
<
<
<
<
|
|
<







329
330
331
332
333
334
335

336
337
338
339
340
341
342
343
344







345
346

347
348
349
350
351
352
353

- initWithSerialization: (OFXMLElement *)element
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		union {
			double d;
			uint64_t u;
		} d;

		if (![[element name] isEqual: [self className]] ||
		    ![[element namespace] isEqual: OF_SERIALIZATION_NS])
			@throw [OFInvalidArgumentException exception];








		d.u = OF_BSWAP64_IF_LE((uint64_t)[element hexadecimalValue]);
		_seconds = OF_BSWAP_DOUBLE_IF_LE(d.d);


		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
		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;

	element = [OFXMLElement elementWithName: [self className]
				      namespace: OF_SERIALIZATION_NS];

	if (isinf(_seconds))
		[element setStringValue:
		    (_seconds > 0 ? @"DISTANT_FUTURE" : @"DISTANT_PAST")];
	else {
		d.d = _seconds;
		[element setStringValue:
		    [OFString stringWithFormat: @"%016" PRIx64, d.u]];
	}

	[element retain];

	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}







<
<
<
|














|
|
<
<
<
<
|
<







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
439
440
		return OF_ORDERED_DESCENDING;

	return OF_ORDERED_SAME;
}

- (OFString *)description
{



	return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"];
}

- (OFXMLElement *)XMLElementBySerializing
{
	void *pool = objc_autoreleasePoolPush();
	OFXMLElement *element;
	union {
		double d;
		uint64_t u;
	} d;

	element = [OFXMLElement elementWithName: [self className]
				      namespace: OF_SERIALIZATION_NS];

	d.d = OF_BSWAP_DOUBLE_IF_LE(_seconds);
	[element setStringValue:




	    [OFString stringWithFormat: @"%016" PRIx64, OF_BSWAP64_IF_LE(d.u)]];


	[element retain];

	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}