Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Source/CFTimeZone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions Tests/CFTimeZone/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 26 additions & 0 deletions Tests/CFTimeZone/gmt_name.m
Original file line number Diff line number Diff line change
@@ -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;
}
Loading