Skip to content

Commit d4ae9bf

Browse files
committed
Merge pull request #152 from brownleej/system-time-zone-fix
Fixes a shadowed variable in the system time zone initializer.
2 parents 82dff74 + 651ee69 commit d4ae9bf

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,6 @@ static CFTimeZoneRef __CFTimeZoneCreateSystem(void) {
753753
}
754754
ret = readlink(TZZONELINK, linkbuf, sizeof(linkbuf));
755755
if (0 < ret) {
756-
CFStringRef name;
757756
linkbuf[ret] = '\0';
758757
if (strncmp(linkbuf, TZZONEINFO, sizeof(TZZONEINFO) - 1) == 0) {
759758
name = CFStringCreateWithBytes(kCFAllocatorSystemDefault, (uint8_t *)linkbuf + sizeof(TZZONEINFO) - 1, strlen(linkbuf) - sizeof(TZZONEINFO) + 1, kCFStringEncodingUTF8, false);

TestFoundation/TestNSTimeZone.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
1313
import Foundation
1414
import XCTest
15+
import Glibc
1516
#else
1617
import SwiftFoundation
1718
import SwiftXCTest
19+
import Darwin
1820
#endif
1921

2022

@@ -25,6 +27,7 @@ class TestNSTimeZone: XCTestCase {
2527
return [
2628
("test_abbreviation", test_abbreviation),
2729
("test_initializingTimeZoneWithOffset", test_initializingTimeZoneWithOffset),
30+
("test_systemTimeZoneUsesSystemTime", test_systemTimeZoneUsesSystemTime),
2831
]
2932
}
3033

@@ -39,4 +42,14 @@ class TestNSTimeZone: XCTestCase {
3942
let seconds = tz?.secondsFromGMTForDate(NSDate())
4043
XCTAssertEqual(seconds, -14400)
4144
}
45+
46+
func test_systemTimeZoneUsesSystemTime() {
47+
tzset();
48+
var t = time(nil)
49+
var lt = tm()
50+
localtime_r(&t, &lt)
51+
let zoneName = NSTimeZone.systemTimeZone().abbreviation ?? "Invalid Abbreviation"
52+
let expectedName = NSString(CString: lt.tm_zone, encoding: NSASCIIStringEncoding)?.bridge() ?? "Invalid Zone"
53+
XCTAssertEqual(zoneName, expectedName)
54+
}
4255
}

0 commit comments

Comments
 (0)