Skip to content

Commit 6dd329b

Browse files
authored
Merge pull request #1721 from apple/revert-1704-dateFormatterFix
2 parents 8e86e4d + 8808544 commit 6dd329b

File tree

5 files changed

+13
-90
lines changed

5 files changed

+13
-90
lines changed

CoreFoundation/NumberDate.subproj/CFTimeZone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ static CFTimeZoneRef __CFTimeZoneCreateSystem(void) {
790790
size_t zoneInfoDirLen = CFStringGetLength(__tzZoneInfo);
791791
if (strncmp(linkbuf, tzZoneInfo, zoneInfoDirLen) == 0) {
792792
name = CFStringCreateWithBytes(kCFAllocatorSystemDefault, (uint8_t *)linkbuf + zoneInfoDirLen,
793-
strlen(linkbuf) - zoneInfoDirLen, kCFStringEncodingUTF8, false);
793+
strlen(linkbuf) - zoneInfoDirLen + 1, kCFStringEncodingUTF8, false);
794794
} else {
795795
name = CFStringCreateWithBytes(kCFAllocatorSystemDefault, (uint8_t *)linkbuf, strlen(linkbuf), kCFStringEncodingUTF8, false);
796796
}

Foundation/DateFormatter.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ open class DateFormatter : Formatter {
176176
/*@NSCopying*/ internal var _timeZone: TimeZone? { willSet { _reset() } }
177177
open var timeZone: TimeZone! {
178178
get {
179-
guard let tz = _timeZone else {
179+
guard let timeZone = _timeZone else {
180180
return (CFDateFormatterCopyProperty(_cfObject, kCFDateFormatterTimeZone) as! NSTimeZone)._swiftObject
181181
}
182-
return tz
182+
return timeZone
183183
}
184184
set {
185-
_timeZone = newValue
185+
_timeZone = timeZone
186186
}
187187
}
188188

TestFoundation/TestCalendar.swift

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,7 @@ class TestNSDateComponents: XCTestCase {
345345
// 2286-11-20 17:46:41
346346
let date4 = Date(timeIntervalSince1970: 10_000_000_001)
347347

348-
// The date components below assume UTC/GMT time zone.
349-
guard let timeZone = TimeZone(abbreviation: "UTC") else {
350-
XCTFail("Unable to create UTC TimeZone for Test")
351-
return
352-
}
353-
354-
var calendar = Calendar.current
355-
calendar.timeZone = timeZone
356-
357-
let diff1 = calendar.dateComponents([.month, .year, .day], from: date1, to: date2)
348+
let diff1 = Calendar.current.dateComponents([.month, .year, .day], from: date1, to: date2)
358349
XCTAssertEqual(diff1.year, 1)
359350
XCTAssertEqual(diff1.month, 5)
360351
XCTAssertEqual(diff1.isLeapMonth, false)
@@ -373,35 +364,35 @@ class TestNSDateComponents: XCTestCase {
373364
XCTAssertNil(diff1.calendar)
374365
XCTAssertNil(diff1.timeZone)
375366

376-
let diff2 = calendar.dateComponents([.weekOfMonth], from: date2, to: date1)
367+
let diff2 = Calendar.current.dateComponents([.weekOfMonth], from: date2, to: date1)
377368
XCTAssertEqual(diff2.weekOfMonth, -76)
378369
XCTAssertEqual(diff2.isLeapMonth, false)
379370

380-
let diff3 = calendar.dateComponents([.weekday], from: date2, to: date1)
371+
let diff3 = Calendar.current.dateComponents([.weekday], from: date2, to: date1)
381372
XCTAssertEqual(diff3.weekday, -536)
382373
XCTAssertEqual(diff3.isLeapMonth, false)
383374

384-
let diff4 = calendar.dateComponents([.weekday, .weekOfMonth], from: date1, to: date2)
375+
let diff4 = Calendar.current.dateComponents([.weekday, .weekOfMonth], from: date1, to: date2)
385376
XCTAssertEqual(diff4.weekday, 4)
386377
XCTAssertEqual(diff4.weekOfMonth, 76)
387378
XCTAssertEqual(diff4.isLeapMonth, false)
388379

389-
let diff5 = calendar.dateComponents([.weekday, .weekOfYear], from: date1, to: date2)
380+
let diff5 = Calendar.current.dateComponents([.weekday, .weekOfYear], from: date1, to: date2)
390381
XCTAssertEqual(diff5.weekday, 4)
391382
XCTAssertEqual(diff5.weekOfYear, 76)
392383
XCTAssertEqual(diff5.isLeapMonth, false)
393384

394-
let diff6 = calendar.dateComponents([.month, .weekOfMonth], from: date1, to: date2)
385+
let diff6 = Calendar.current.dateComponents([.month, .weekOfMonth], from: date1, to: date2)
395386
XCTAssertEqual(diff6.month, 17)
396387
XCTAssertEqual(diff6.weekOfMonth, 2)
397388
XCTAssertEqual(diff6.isLeapMonth, false)
398389

399-
let diff7 = calendar.dateComponents([.weekOfYear, .weekOfMonth], from: date2, to: date1)
390+
let diff7 = Calendar.current.dateComponents([.weekOfYear, .weekOfMonth], from: date2, to: date1)
400391
XCTAssertEqual(diff7.weekOfYear, -76)
401392
XCTAssertEqual(diff7.weekOfMonth, 0)
402393
XCTAssertEqual(diff7.isLeapMonth, false)
403394

404-
let diff8 = calendar.dateComponents([.era, .quarter, .year, .month, .day, .hour, .minute, .second, .nanosecond, .calendar, .timeZone], from: date2, to: date3)
395+
let diff8 = Calendar.current.dateComponents([.era, .quarter, .year, .month, .day, .hour, .minute, .second, .nanosecond, .calendar, .timeZone], from: date2, to: date3)
405396
XCTAssertEqual(diff8.era, 0)
406397
XCTAssertEqual(diff8.year, 315)
407398
XCTAssertEqual(diff8.quarter, 0)
@@ -415,7 +406,7 @@ class TestNSDateComponents: XCTestCase {
415406
XCTAssertNil(diff8.calendar)
416407
XCTAssertNil(diff8.timeZone)
417408

418-
let diff9 = calendar.dateComponents([.era, .quarter, .year, .month, .day, .hour, .minute, .second, .nanosecond, .calendar, .timeZone], from: date4, to: date3)
409+
let diff9 = Calendar.current.dateComponents([.era, .quarter, .year, .month, .day, .hour, .minute, .second, .nanosecond, .calendar, .timeZone], from: date4, to: date3)
419410
XCTAssertEqual(diff9.era, 0)
420411
XCTAssertEqual(diff9.year, 0)
421412
XCTAssertEqual(diff9.quarter, 0)

TestFoundation/TestDateFormatter.swift

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class TestDateFormatter: XCTestCase {
2424
("test_dateFormatString", test_dateFormatString),
2525
("test_setLocaleToNil", test_setLocaleToNil),
2626
("test_setTimeZoneToNil", test_setTimeZoneToNil),
27-
("test_setTimeZone", test_setTimeZone),
28-
("test_expectedTimeZone", test_expectedTimeZone),
2927
]
3028
}
3129

@@ -358,54 +356,4 @@ class TestDateFormatter: XCTestCase {
358356
// Time zone should go back to the system one.
359357
XCTAssertEqual(f.timeZone, NSTimeZone.system)
360358
}
361-
362-
func test_setTimeZone() {
363-
// Test two different time zones. Should ensure that if one
364-
// happens to be TimeZone.current, we still get a valid test.
365-
let newYork = TimeZone(identifier: "America/New_York")!
366-
let losAngeles = TimeZone(identifier: "America/Los_Angeles")!
367-
368-
XCTAssertNotEqual(newYork, losAngeles)
369-
370-
// Case 1: New York
371-
let f = DateFormatter()
372-
f.timeZone = newYork
373-
XCTAssertEqual(f.timeZone, newYork)
374-
375-
// Case 2: Los Angeles
376-
f.timeZone = losAngeles
377-
XCTAssertEqual(f.timeZone, losAngeles)
378-
}
379-
380-
func test_expectedTimeZone() {
381-
let gmt = TimeZone(abbreviation: DEFAULT_TIMEZONE)
382-
let newYork = TimeZone(identifier: "America/New_York")!
383-
let losAngeles = TimeZone(identifier: "America/Los_Angeles")!
384-
385-
XCTAssertNotEqual(newYork, losAngeles)
386-
387-
let now = Date()
388-
389-
let f = DateFormatter()
390-
f.dateFormat = "z"
391-
f.locale = Locale(identifier: "en_US_POSIX")
392-
393-
// Case 1: TimeZone.current
394-
// This case can catch some issues that cause TimeZone.current to be
395-
// treated like GMT, but it doesn't work if TimeZone.current is GMT.
396-
// If you do find an issue like this caused by this first case,
397-
// it would benefit from a more specific test that fails when
398-
// TimeZone.current is GMT as well.
399-
// (ex. TestTimeZone.test_systemTimeZoneName)
400-
f.timeZone = TimeZone.current
401-
XCTAssertEqual(f.string(from: now), TimeZone.current.abbreviation())
402-
403-
// Case 2: New York
404-
f.timeZone = newYork
405-
XCTAssertEqual(f.string(from: now), newYork.abbreviation())
406-
407-
// Case 3: Los Angeles
408-
f.timeZone = losAngeles
409-
XCTAssertEqual(f.string(from: now), losAngeles.abbreviation())
410-
}
411359
}

TestFoundation/TestTimeZone.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
88
//
99

10-
import CoreFoundation
11-
1210
class TestTimeZone: XCTestCase {
1311

1412
static var allTests: [(String, (TestTimeZone) -> () throws -> Void)] {
@@ -31,7 +29,6 @@ class TestTimeZone: XCTestCase {
3129

3230
("test_customMirror", test_tz_customMirror),
3331
("test_knownTimeZones", test_knownTimeZones),
34-
("test_systemTimeZoneName", test_systemTimeZoneName),
3532
]
3633
}
3734

@@ -201,17 +198,4 @@ class TestTimeZone: XCTestCase {
201198
XCTAssertNotNil(TimeZone(identifier: tz), "Cant instantiate valid timeZone: \(tz)")
202199
}
203200
}
204-
205-
func test_systemTimeZoneName() {
206-
// Ensure that the system time zone creates names the same way as creating them with an identifier.
207-
// If it isn't the same, bugs in DateFormat can result, but in this specific case, the bad length
208-
// is only visible to CoreFoundation APIs, and the Swift versions hide it, making it hard to detect.
209-
let timeZone = CFTimeZoneCopySystem()
210-
let timeZoneName = CFTimeZoneGetName(timeZone)
211-
212-
let createdTimeZone = TimeZone(identifier: TimeZone.current.identifier)!
213-
214-
XCTAssertEqual(CFStringGetLength(timeZoneName), TimeZone.current.identifier.count)
215-
XCTAssertEqual(CFStringGetLength(timeZoneName), createdTimeZone.identifier.count)
216-
}
217201
}

0 commit comments

Comments
 (0)