-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathNSTimeZone.swift
182 lines (146 loc) · 5.98 KB
/
NSTimeZone.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
import CoreFoundation
public class NSTimeZone : NSObject, NSCopying, NSSecureCoding, NSCoding {
typealias CFType = CFTimeZoneRef
private var _base = _CFInfo(typeID: CFTimeZoneGetTypeID())
private var _name = UnsafeMutablePointer<Void>()
private var _data = UnsafeMutablePointer<Void>()
private var _periods = UnsafeMutablePointer<Void>()
private var _periodCnt = Int32(0)
internal var _cfObject: CFType {
return unsafeBitCast(self, CFType.self)
}
// Primary creation method is +timeZoneWithName:; the
// data-taking variants should rarely be used directly
public convenience init?(name tzName: String) {
self.init(name: tzName, data: nil)
}
public init?(name tzName: String, data aData: NSData?) {
super.init()
if !_CFTimeZoneInit(_cfObject, tzName._cfObject, aData?._cfObject) {
return nil
}
}
public required init?(coder aDecoder: NSCoder) {
NSUnimplemented()
}
deinit {
_CFDeinit(self)
}
// Time zones created with this never have daylight savings and the
// offset is constant no matter the date; the name and abbreviation
// do NOT follow the POSIX convention (of minutes-west).
public convenience init(forSecondsFromGMT seconds: Int) { NSUnimplemented() }
public convenience init?(abbreviation: String) { NSUnimplemented() }
public func encodeWithCoder(aCoder: NSCoder) {
}
public static func supportsSecureCoding() -> Bool {
return true
}
public func copyWithZone(zone: NSZone) -> AnyObject {
return self
}
public var name: String {
get {
if self.dynamicType === NSTimeZone.self {
return CFTimeZoneGetName(_cfObject)._swiftObject
} else {
NSRequiresConcreteImplementation()
}
}
}
public var data: NSData {
get {
if self.dynamicType === NSTimeZone.self {
return CFTimeZoneGetData(_cfObject)._nsObject
} else {
NSRequiresConcreteImplementation()
}
}
}
public func secondsFromGMTForDate(aDate: NSDate) -> Int {
if self.dynamicType === NSTimeZone.self {
return Int(CFTimeZoneGetSecondsFromGMT(_cfObject, aDate.timeIntervalSinceReferenceDate))
} else {
NSRequiresConcreteImplementation()
}
}
public func abbreviationForDate(aDate: NSDate) -> String? {
if self.dynamicType === NSTimeZone.self {
return CFTimeZoneCopyAbbreviation(_cfObject, aDate.timeIntervalSinceReferenceDate)._swiftObject
} else {
NSRequiresConcreteImplementation()
}
}
public func isDaylightSavingTimeForDate(aDate: NSDate) -> Bool {
if self.dynamicType === NSTimeZone.self {
return CFTimeZoneIsDaylightSavingTime(_cfObject, aDate.timeIntervalSinceReferenceDate)
} else {
NSRequiresConcreteImplementation()
}
}
public func daylightSavingTimeOffsetForDate(aDate: NSDate) -> NSTimeInterval {
if self.dynamicType === NSTimeZone.self {
return CFTimeZoneGetDaylightSavingTimeOffset(_cfObject, aDate.timeIntervalSinceReferenceDate)
} else {
NSRequiresConcreteImplementation()
}
}
public func nextDaylightSavingTimeTransitionAfterDate(aDate: NSDate) -> NSDate? {
if self.dynamicType === NSTimeZone.self {
return NSDate(timeIntervalSinceReferenceDate: CFTimeZoneGetNextDaylightSavingTimeTransition(_cfObject, aDate.timeIntervalSinceReferenceDate))
} else {
NSRequiresConcreteImplementation()
}
}
}
extension NSTimeZone {
public class func systemTimeZone() -> NSTimeZone {
return CFTimeZoneCopySystem()._nsObject
}
public class func resetSystemTimeZone() {
CFTimeZoneResetSystem()
}
public class func defaultTimeZone() -> NSTimeZone {
return CFTimeZoneCopyDefault()._nsObject
}
public class func setDefaultTimeZone(aTimeZone: NSTimeZone) {
CFTimeZoneSetDefault(aTimeZone._cfObject)
}
}
extension NSTimeZone : _CFBridgable { }
extension CFTimeZoneRef : _NSBridgable {
typealias NSType = NSTimeZone
internal var _nsObject : NSType {
return unsafeBitCast(self, NSType.self)
}
}
extension NSTimeZone {
public class func localTimeZone() -> NSTimeZone { NSUnimplemented() }
public class func knownTimeZoneNames() -> [String] { NSUnimplemented() }
public class func abbreviationDictionary() -> [String : String] { NSUnimplemented() }
public class func setAbbreviationDictionary(dict: [String : String]) { NSUnimplemented() }
public class func timeZoneDataVersion() -> String { NSUnimplemented() }
public var secondsFromGMT: Int { NSUnimplemented() }
public var abbreviation: String? { NSUnimplemented() }
public var daylightSavingTime: Bool { NSUnimplemented() }
public var daylightSavingTimeOffset: NSTimeInterval { NSUnimplemented() }
/*@NSCopying*/ public var nextDaylightSavingTimeTransition: NSDate? { NSUnimplemented() }
public func isEqualToTimeZone(aTimeZone: NSTimeZone) -> Bool { NSUnimplemented() }
public func localizedName(style: NSTimeZoneNameStyle, locale: NSLocale?) -> String? { NSUnimplemented() }
}
public enum NSTimeZoneNameStyle : Int {
case Standard // Central Standard Time
case ShortStandard // CST
case DaylightSaving // Central Daylight Time
case ShortDaylightSaving // CDT
case Generic // Central Time
case ShortGeneric // CT
}