Skip to content

Commit caf369d

Browse files
committed
[NSTimeZone] Add implementation of abbreviation property and tests
This adds the implementation of NSTimeZone's `abbreviation` property and a test case for it.
1 parent 492c2e6 commit caf369d

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

Foundation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
5BF7AEBF1BCD51F9008F214A /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4A1BCC5DCB00ED97BB /* NSURL.swift */; };
197197
5BF7AEC01BCD51F9008F214A /* NSUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4B1BCC5DCB00ED97BB /* NSUUID.swift */; };
198198
5BF7AEC11BCD51F9008F214A /* NSValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BDC3F4C1BCC5DCB00ED97BB /* NSValue.swift */; };
199+
84BA558E1C16F90900F48C54 /* TestNSTimeZone.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */; };
199200
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */; };
200201
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = E876A73D1C1180E000F279EC /* TestNSRange.swift */; };
201202
EA66F6361BEED03E00136161 /* TargetConditionals.h in Headers */ = {isa = PBXBuildFile; fileRef = EA66F6351BEED03E00136161 /* TargetConditionals.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -519,6 +520,7 @@
519520
5BDC3FCF1BCF17E600ED97BB /* NSCFSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSCFSet.swift; sourceTree = "<group>"; };
520521
5BDC405C1BD6D83B00ED97BB /* TestFoundation.app */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TestFoundation.app; sourceTree = BUILT_PRODUCTS_DIR; };
521522
5BF7AEC21BCD568D008F214A /* ForSwiftFoundationOnly.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ForSwiftFoundationOnly.h; sourceTree = "<group>"; };
523+
84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSTimeZone.swift; sourceTree = "<group>"; };
522524
C93559281C12C49F009FD6A9 /* TestNSAffineTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSAffineTransform.swift; sourceTree = "<group>"; };
523525
E876A73D1C1180E000F279EC /* TestNSRange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSRange.swift; sourceTree = "<group>"; };
524526
EA313DFC1BE7F2E90060A403 /* CFURLComponents_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFURLComponents_Internal.h; sourceTree = "<group>"; };
@@ -1024,6 +1026,7 @@
10241026
525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */,
10251027
5B40F9F11C125187000E72E3 /* TestNSXMLParser.swift */,
10261028
22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */,
1029+
84BA558D1C16F90900F48C54 /* TestNSTimeZone.swift */,
10271030
);
10281031
name = Tests;
10291032
sourceTree = "<group>";
@@ -1711,6 +1714,7 @@
17111714
E876A73E1C1180E000F279EC /* TestNSRange.swift in Sources */,
17121715
EA66F6521BF1619600136161 /* TestNSPropertyList.swift in Sources */,
17131716
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */,
1717+
84BA558E1C16F90900F48C54 /* TestNSTimeZone.swift in Sources */,
17141718
52829AD71C160D64003BC4EF /* TestNSCalendar.swift in Sources */,
17151719
C93559291C12C49F009FD6A9 /* TestNSAffineTransform.swift in Sources */,
17161720
EA66F64E1BF1619600136161 /* TestNSIndexSet.swift in Sources */,

Foundation/NSTimeZone.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,15 @@ extension NSTimeZone {
162162
public class func timeZoneDataVersion() -> String { NSUnimplemented() }
163163

164164
public var secondsFromGMT: Int { NSUnimplemented() }
165-
public var abbreviation: String? { NSUnimplemented() }
165+
166+
/// The abbreviation for the receiver, such as "EDT" (Eastern Daylight Time). (read-only)
167+
///
168+
/// This invokes `abbreviationForDate:` with the current date as the argument.
169+
public var abbreviation: String? {
170+
let currentDate = NSDate()
171+
return abbreviationForDate(currentDate)
172+
}
173+
166174
public var daylightSavingTime: Bool { NSUnimplemented() }
167175
public var daylightSavingTimeOffset: NSTimeInterval { NSUnimplemented() }
168176
/*@NSCopying*/ public var nextDaylightSavingTimeTransition: NSDate? { NSUnimplemented() }

TestFoundation/TestNSTimeZone.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See http://swift.org/LICENSE.txt for license information
7+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
11+
12+
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
13+
import Foundation
14+
import XCTest
15+
#else
16+
import SwiftFoundation
17+
import SwiftXCTest
18+
#endif
19+
20+
21+
22+
class TestNSTimeZone: XCTestCase {
23+
24+
var allTests : [(String, () -> ())] {
25+
return [
26+
("test_abbreviation", test_abbreviation),
27+
]
28+
}
29+
30+
func test_abbreviation() {
31+
let tz = NSTimeZone.systemTimeZone()
32+
XCTAssertEqual(tz.abbreviation, tz.abbreviationForDate(NSDate()))
33+
}
34+
}

TestFoundation/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ XCTMain([
3737
TestNSRange(),
3838
TestNSXMLParser(),
3939
TestNSDate(),
40+
TestNSTimeZone(),
4041
])

0 commit comments

Comments
 (0)