diff --git a/Source/CFTimeZone.c b/Source/CFTimeZone.c index 6925a6e..f769e09 100644 --- a/Source/CFTimeZone.c +++ b/Source/CFTimeZone.c @@ -305,7 +305,10 @@ CFTimeZoneCreateWithTimeIntervalFromGMT (CFAllocatorRef alloc, tzfile.header.tzh_timecnt[3] = 1; tzfile.header.tzh_typecnt[3] = 1; tzfile.ttinfo.offset = CFSwapInt32HostToBig((SInt32)ti); - numChars = snprintf (tzfile.abbrev, 10, "GMT%c%02d:%02d", sign, hour, min); + if ((SInt32) ti == 0) + numChars = snprintf (tzfile.abbrev, 10, "GMT"); + else + numChars = snprintf (tzfile.abbrev, 10, "GMT%c%02d%02d", sign, hour, min); tzfile.header.tzh_charcnt[3] = numChars; name = CFStringCreateWithCString (alloc, tzfile.abbrev, diff --git a/Tests/CFTimeZone/basic.m b/Tests/CFTimeZone/basic.m index 49a092f..9be9547 100644 --- a/Tests/CFTimeZone/basic.m +++ b/Tests/CFTimeZone/basic.m @@ -14,11 +14,11 @@ int main (void) tz = CFTimeZoneCreateWithTimeIntervalFromGMT (NULL, 0.0); PASS_CF(tz != NULL, "CFTimeZone create successfully."); - PASS_CFEQ(CFTimeZoneGetName(tz), CFSTR("GMT+00:00"), + PASS_CFEQ(CFTimeZoneGetName(tz), CFSTR("GMT"), "CFTimeZone has correct name."); - + str = CFTimeZoneCopyAbbreviation (tz, 0.0); - PASS_CFEQ(str, CFSTR("GMT+00:00"), "Time zone abbreviations are equal."); + PASS_CFEQ(str, CFSTR("GMT"), "Time zone abbreviations are equal."); ti = CFTimeZoneGetSecondsFromGMT (tz, 0.0); PASS_CF(ti == 0.0, "GMT+00:00 offset from GMT is %g", ti); diff --git a/Tests/CFTimeZone/gmt_name.m b/Tests/CFTimeZone/gmt_name.m new file mode 100644 index 0000000..5a47ca5 --- /dev/null +++ b/Tests/CFTimeZone/gmt_name.m @@ -0,0 +1,26 @@ +#include "CoreFoundation/CFTimeZone.h" +#include "../CFTesting.h" + +/* A time zone built from a GMT offset is named GMT for a zero offset and + GMT followed by the signed four-digit offset otherwise. */ + +int main (void) +{ + PASS_CFEQ (CFTimeZoneGetName ( + CFTimeZoneCreateWithTimeIntervalFromGMT (NULL, 0.0)), + CFSTR ("GMT"), "A zero offset is named GMT."); + PASS_CFEQ (CFTimeZoneGetName ( + CFTimeZoneCreateWithTimeIntervalFromGMT (NULL, 5 * 3600)), + CFSTR ("GMT+0500"), "A five-hour offset is named GMT+0500."); + PASS_CFEQ (CFTimeZoneGetName ( + CFTimeZoneCreateWithTimeIntervalFromGMT (NULL, -5 * 3600)), + CFSTR ("GMT-0500"), "A negative five-hour offset is named GMT-0500."); + PASS_CFEQ (CFTimeZoneGetName ( + CFTimeZoneCreateWithTimeIntervalFromGMT (NULL, 5 * 3600 + 30 * 60)), + CFSTR ("GMT+0530"), "A five-and-a-half-hour offset is named GMT+0530."); + PASS_CFEQ (CFTimeZoneGetName ( + CFTimeZoneCreateWithTimeIntervalFromGMT (NULL, 30 * 60)), + CFSTR ("GMT+0030"), "A thirty-minute offset is named GMT+0030."); + + return 0; +}