ObjFW  Check-in [f1765412c7]

Overview
Comment:OFDate: Do not use lrint() for microseconds

It's better to make sure we never round up, as it's better to be a
little bit behind in time than ahead.

This has the nice side effect of fixing the test on the 3DS, as lrint()
is behaving differently there.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f1765412c7c70b147e526dda7156b5b5480d23ad1237a80370b51dd47071c72f
User & Date: js on 2016-02-22 15:25:43
Other Links: manifest | tags
Context
2016-02-28
15:31
OFStdIOStream: Set codepage to UTF-8 on Windows check-in: 0a001bfd7b user: js tags: trunk
2016-02-22
15:25
OFDate: Do not use lrint() for microseconds check-in: f1765412c7 user: js tags: trunk
00:17
tests: Add output for Nintendo 3DS check-in: e1762ab0af user: js tags: trunk
Changes

Modified src/OFDate.m from [fa697c55af] to [d7cb394675].

426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

- (uint32_t)microsecond
{
	return (uint32_t)rint((_seconds - floor(_seconds)) * 1000000);
}

- (uint8_t)second
{
	GMTIME_RET(tm_sec)
}








|







426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
	objc_autoreleasePoolPop(pool);

	return [element autorelease];
}

- (uint32_t)microsecond
{
	return (uint32_t)((_seconds - floor(_seconds)) * 1000000);
}

- (uint8_t)second
{
	GMTIME_RET(tm_sec)
}

Modified tests/OFDateTests.m from [b44b2f039d] to [2f507797b6].

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFDate *d1, *d2;

	TEST(@"+[dateWithTimeIntervalSince1970:]",
	    (d1 = [OFDate dateWithTimeIntervalSince1970: 0]))

	TEST(@"-[dateByAddingTimeInterval:]",
	    (d2 = [d1 dateByAddingTimeInterval: 3600 * 25 + 5.000001]))

	TEST(@"-[description]",
	    [[d1 description] isEqual: @"1970-01-01T00:00:00Z"] &&
	    [[d2 description] isEqual: @"1970-01-02T01:00:05Z"])

	TEST(@"+[dateWithDateString:format:]",
	    [[[OFDate dateWithDateString: @"2000-06-20T12:34:56Z"
				  format: @"%Y-%m-%dT%H:%M:%SZ"] description]
	    isEqual: @"2000-06-20T12:34:56Z"]);

	TEST(@"-[isEqual:]",
	    [d1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0]] &&
	    ![d1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0.0000001]])

	TEST(@"-[compare:]", [d1 compare: d2] == OF_ORDERED_ASCENDING)

	TEST(@"-[second]", [d1 second] == 0 && [d2 second] == 5)

	TEST(@"-[microsecond]",
	    [d1 microsecond] == 0 && [d2 microsecond] == 1)

	TEST(@"-[minute]", [d1 minute] == 0 && [d2 minute] == 0)

	TEST(@"-[hour]", [d1 hour] == 0 && [d2 hour] == 1)

	TEST(@"-[dayOfMonth]", [d1 dayOfMonth] == 1 && [d2 dayOfMonth] == 2)








|



















|







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFDate *d1, *d2;

	TEST(@"+[dateWithTimeIntervalSince1970:]",
	    (d1 = [OFDate dateWithTimeIntervalSince1970: 0]))

	TEST(@"-[dateByAddingTimeInterval:]",
	    (d2 = [d1 dateByAddingTimeInterval: 3600 * 25 + 5.000002]))

	TEST(@"-[description]",
	    [[d1 description] isEqual: @"1970-01-01T00:00:00Z"] &&
	    [[d2 description] isEqual: @"1970-01-02T01:00:05Z"])

	TEST(@"+[dateWithDateString:format:]",
	    [[[OFDate dateWithDateString: @"2000-06-20T12:34:56Z"
				  format: @"%Y-%m-%dT%H:%M:%SZ"] description]
	    isEqual: @"2000-06-20T12:34:56Z"]);

	TEST(@"-[isEqual:]",
	    [d1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0]] &&
	    ![d1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0.0000001]])

	TEST(@"-[compare:]", [d1 compare: d2] == OF_ORDERED_ASCENDING)

	TEST(@"-[second]", [d1 second] == 0 && [d2 second] == 5)

	TEST(@"-[microsecond]",
	    [d1 microsecond] == 0 && [d2 microsecond] == 2)

	TEST(@"-[minute]", [d1 minute] == 0 && [d2 minute] == 0)

	TEST(@"-[hour]", [d1 hour] == 0 && [d2 hour] == 1)

	TEST(@"-[dayOfMonth]", [d1 dayOfMonth] == 1 && [d2 dayOfMonth] == 2)