ObjFW  Check-in [168b748eb8]

Overview
Comment:OFDate: Improve handling of distant past / future
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 168b748eb88b91dbf16e2b0e53656624784efb966cd621839adafdda97d3893a
User & Date: js on 2015-06-14 13:10:01
Other Links: manifest | tags
Context
2015-06-17
22:11
Add OF_NULLABLE_PROPERTY check-in: 80e1a9655b user: js tags: trunk
2015-06-14
13:10
OFDate: Improve handling of distant past / future check-in: 168b748eb8 user: js tags: trunk
12:47
utils/ofhttp: Allow specifying - to -b for stdin check-in: 51cfed24d2 user: js tags: trunk
Changes

Modified src/OFDate.m from [e749446c20] to [d311cf12a2].

185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
	return [[[self alloc] initWithLocalDateString: string
					       format: format] autorelease];
}

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

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

- init
{
	struct timeval t;

	self = [super init];







|





|







185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
	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];
301
302
303
304
305
306
307

308
309
310
311
312
313
314
315
316







317
318

319
320
321
322
323
324
325

- 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 = (uint64_t)[element hexadecimalValue];
		_seconds = d.d;


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








>









>
>
>
>
>
>
>
|
|
>







301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334

- 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;
	}

382
383
384
385
386
387
388



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403




404
405
406

407
408
409
410
411
412
413
		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 = _seconds;
	[element setStringValue:
	    [OFString stringWithFormat: @"%016" PRIx64, d.u]];


	[element retain];

	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}







>
>
>
|














>
>
>
>
|
|
|
>







391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
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
		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];
}