Update for handling more future dates, and further testing.

This commit is contained in:
Richard Frith-Macdonald 2021-08-14 11:25:23 +01:00
parent 5162d888dc
commit c43ea6d474
7 changed files with 73 additions and 63 deletions

View file

@ -1,3 +1,15 @@
2021-08-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/nstzfile.h: Fix by Emmanuel Dreyfus - increase number of
transitions allowed, so that we can handle dates further into the
future (since v2+ files support that).
* Tests/base/NSTimeZone/ParisV1-noMagic.tzdb:
* Tests/base/NSTimeZone/ParisV1.tzdb:
* Tests/base/NSTimeZone/ParisV2-missingHeader.tzdb:
* Tests/base/NSTimeZone/ParisV2.tzdb:
* Tests/base/NSTimeZone/localtime.m:
Increase the range of testcases
2021-08-11 Richard Frith-Macdonald <rfm@gnu.org>
* Source/tzdb.h: Public domain time zone file parsing etc

View file

@ -77,12 +77,14 @@ struct tzhead {
#ifndef TZ_MAX_TIMES
/*
** The TZ_MAX_TIMES value below is enough to handle a bit more than a
** year's worth of solar time (corrected daily to the nearest second) or
** 138 years of Pacific Presidential Election time
** A value of 370 is enough to handle a bit more than a year's worth of
** solar time (corrected daily to the nearest second) or 138 years of
** Pacific Presidential Election time
** (where there are three time zone transitions every fourth year).
** This needs to be at least 2000 to cope with TZDB v2+ as likely
** dates go far further into the future than TZDB v1
*/
#define TZ_MAX_TIMES 370
#define TZ_MAX_TIMES 2000
#endif /* !defined TZ_MAX_TIMES */
#ifndef TZ_MAX_TYPES

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -3,12 +3,60 @@
#define PREFIX "./"
static void
testTZDB(NSString *fileName, const char *message, bool beyond2038)
{
NSTimeZone *timeZone;
NSDate *date;
NSData *tzdata;
/* Test using TZDB file known as being v1 */
tzdata = [NSData dataWithContentsOfFile: fileName];
PASS(tzdata != nil && [tzdata isKindOfClass: [NSData class]] &&
[tzdata length] > 0, "Loading user-supplied %s works", message);
timeZone = [NSTimeZone timeZoneWithName: fileName data: tzdata];
PASS(timeZone != nil && [timeZone isKindOfClass: [NSTimeZone class]],
"+timeZoneWithName data works");
/* Before last transition in TZDB v2+ file */
date = [NSDate dateWithString: @"1981-01-16 23:59:59 -0100"];
PASS([timeZone secondsFromGMTForDate: date] == 3600,
"pre-1996 standard time offset vs UTC found for user-supplied %s",
message);
date = [NSDate dateWithString: @"1981-08-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 7200,
"pre-1996 DST time offset vs UTC found for user-supplied %s",
message);
/* After last transition in TZDB v2+ file */
date = [NSDate dateWithString: @"2021-01-16 23:59:59 -0100"];
PASS([timeZone secondsFromGMTForDate: date] == 3600,
"post-1996 standard time offset vs UTC found for user-supplied %s",
message);
date = [NSDate dateWithString: @"2021-08-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 7200,
"post-1996 DST time offset vs UTC found for user-supplied %s",
message);
/* After 32bit value seconds-since-1970 using TZDB v2+ file */
if (beyond2038) {
date = [NSDate dateWithString: @"2039-01-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 3600,
"post-2038 standard time offset vs UTC found for user-supplied %s",
message);
}
return;
}
int main(void)
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSTimeZone *timeZone;
NSDate *date;
NSData *tzdata;
timeZone = [NSTimeZone timeZoneWithName: @"Europe/Paris"];
PASS(timeZone != nil && [timeZone isKindOfClass: [NSTimeZone class]],
@ -32,64 +80,12 @@ int main(void)
PASS([timeZone secondsFromGMTForDate: date] == 7200,
"post-1996 DST time offset vs UTC found for System Europe/Paris");
/* Test using TZDB file known as being v1 */
tzdata = [NSData dataWithContentsOfFile: @ PREFIX "Paris.tzdbv1"];
PASS(tzdata != nil && [tzdata isKindOfClass: [NSData class]] &&
[tzdata length] > 0, "Loading user-supplied Paris TZDBv1 works");
timeZone = [NSTimeZone timeZoneWithName: @"Paris.tzdb1" data: tzdata];
PASS(timeZone != nil && [timeZone isKindOfClass: [NSTimeZone class]],
"+timeZoneWithName data works");
/* Before last transition in TZDB v2+ file */
date = [NSDate dateWithString: @"1981-01-16 23:59:59 -0100"];
PASS([timeZone secondsFromGMTForDate: date] == 3600,
"pre-1996 standard time offset vs UTC found for user Paris TZDBv1");
date = [NSDate dateWithString: @"1981-08-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 7200,
"pre-1996 DST time offset vs UTC found for user Paris TZDBv1");
/* After last transition in TZDB v2+ file */
date = [NSDate dateWithString: @"2021-01-16 23:59:59 -0100"];
PASS([timeZone secondsFromGMTForDate: date] == 3600,
"post-1996 standard time offset vs UTC found for user Paris TZDBv1");
date = [NSDate dateWithString: @"2021-08-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 7200,
"post-1996 DST time offset vs UTC found for user Paris TZDBv1");
/* Test using TZDB file known as being v2 */
tzdata = [NSData dataWithContentsOfFile: @ PREFIX "Paris.tzdbv2"];
PASS(tzdata != nil && [tzdata isKindOfClass: [NSData class]] &&
[tzdata length] > 0, "Loading user-supplied Paris TZDBv2 works");
timeZone = [NSTimeZone timeZoneWithName: @"Paris.tzdbv2" data: tzdata];
PASS(timeZone != nil && [timeZone isKindOfClass: [NSTimeZone class]],
"+timeZoneWithName data works");
/* Before last transition in TZDB v2+ file */
date = [NSDate dateWithString: @"1981-01-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 3600,
"pre-1996 standard time offset vs UTC found for user Paris TZDBv2");
date = [NSDate dateWithString: @"1981-08-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 7200,
"pre-1996 DST time offset vs UTC found for user Paris TZDBv2");
/* After last transition in TZDB v2+ file */
date = [NSDate dateWithString: @"2021-01-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 3600,
"post-1996 DST time offset vs UTC found for user Paris TZDBv2");
date = [NSDate dateWithString: @"2021-08-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 7200,
"post-1996 DST time offset vs UTC found for user Paris TZDBv2");
/* After 32bit value seconds-since-1970 using TZDB v2+ file */
date = [NSDate dateWithString: @"2039-01-16 23:59:59 -0200"];
PASS([timeZone secondsFromGMTForDate: date] == 3600,
"post-2038 DST time offset vs UTC found for user Paris TZDBv2");
testTZDB(@ PREFIX "ParisV1.tzdb", "Europe/Paris TZDB v1", false);
testTZDB(@ PREFIX "ParisV2.tzdb", "Europe/Paris TZDB v2", true);
testTZDB(@ PREFIX "ParisV1-noMagic.tzdb",
"buggy Europe/Paris TZDB v1 without magic", false);
testTZDB(@ PREFIX "ParisV2-missingHeader.tzdb",
"buggy Europe/Paris TZDB v2 without v2 header", true);
[arp release]; arp = nil;
return 0;