11
11
//===----------------------------------------------------------------------===//
12
12
13
13
14
-
15
14
internal func __NSTimeZoneIsAutoupdating( _ timezone: NSTimeZone ) -> Bool {
16
15
return false
17
16
}
18
17
18
+ internal func __NSTimeZoneAutoupdating( ) -> NSTimeZone {
19
+ return NSTimeZone . local. _nsObject
20
+ }
21
+
22
+ internal func __NSTimeZoneCurrent( ) -> NSTimeZone {
23
+ return NSTimeZone . system. _nsObject
24
+ }
25
+
19
26
/**
20
27
`TimeZone` defines the behavior of a time zone. Time zone values represent geopolitical regions. Consequently, these values have names for these regions. Time zone values also represent a temporal offset, either plus or minus, from Greenwich Mean Time (GMT) and an abbreviation (such as PST for Pacific Standard Time).
21
28
@@ -25,20 +32,24 @@ internal func __NSTimeZoneIsAutoupdating(_ timezone: NSTimeZone) -> Bool {
25
32
26
33
Cocoa does not provide any API to change the time zone of the computer, or of other applications.
27
34
*/
28
- public struct TimeZone : CustomStringConvertible , CustomDebugStringConvertible , Hashable , Equatable , ReferenceConvertible {
35
+ public struct TimeZone : Hashable , Equatable , ReferenceConvertible {
29
36
public typealias ReferenceType = NSTimeZone
30
37
31
38
internal var _wrapped : NSTimeZone
32
39
internal var _autoupdating : Bool
33
40
34
41
/// The time zone currently used by the system.
35
42
public static var current : TimeZone {
36
- return NSTimeZone . system
43
+ return TimeZone ( adoptingReference : __NSTimeZoneCurrent ( ) , autoupdating : false )
37
44
}
38
45
39
- /// The time zone currently used by the system, automatically updating to the user’s current preference.
46
+ /// The time zone currently used by the system, automatically updating to the user's current preference.
47
+ ///
48
+ /// If this time zone is mutated, then it no longer tracks the application time zone.
49
+ ///
50
+ /// The autoupdating time zone only compares equal to itself.
40
51
public static var autoupdatingCurrent : TimeZone {
41
- return NSTimeZone . local
52
+ return TimeZone ( adoptingReference : __NSTimeZoneAutoupdating ( ) , autoupdating : true )
42
53
}
43
54
44
55
// MARK: -
@@ -195,28 +206,50 @@ public struct TimeZone : CustomStringConvertible, CustomDebugStringConvertible,
195
206
196
207
// MARK: -
197
208
198
- public var description : String {
199
- return _wrapped. description
200
- }
201
-
202
- public var debugDescription : String {
203
- return _wrapped. debugDescription
204
- }
205
-
206
209
public var hashValue : Int {
207
210
if _autoupdating {
208
211
return 1
209
212
} else {
210
213
return _wrapped. hash
211
214
}
212
215
}
216
+
217
+ public static func == ( lhs: TimeZone , rhs: TimeZone ) -> Bool {
218
+ if lhs. _autoupdating || rhs. _autoupdating {
219
+ return lhs. _autoupdating == rhs. _autoupdating
220
+ } else {
221
+ return lhs. _wrapped. isEqual ( rhs. _wrapped)
222
+ }
223
+ }
213
224
}
214
225
215
- public func == ( _ lhs: TimeZone , _ rhs: TimeZone ) -> Bool {
216
- if lhs. _autoupdating || rhs. _autoupdating {
217
- return lhs. _autoupdating == rhs. _autoupdating
218
- } else {
219
- return lhs. _wrapped. isEqual ( rhs. _wrapped)
226
+ extension TimeZone : CustomStringConvertible , CustomDebugStringConvertible , CustomReflectable {
227
+ private var _kindDescription : String {
228
+ if ( self == TimeZone . autoupdatingCurrent) {
229
+ return " autoupdatingCurrent "
230
+ } else if ( self == TimeZone . current) {
231
+ return " current "
232
+ } else {
233
+ return " fixed "
234
+ }
235
+ }
236
+
237
+ public var customMirror : Mirror {
238
+ var c : [ ( label: String ? , value: Any ) ] = [ ]
239
+ c. append ( ( label: " identifier " , value: identifier) )
240
+ c. append ( ( label: " kind " , value: _kindDescription) )
241
+ c. append ( ( label: " abbreviation " , value: abbreviation ( ) ) )
242
+ c. append ( ( label: " secondsFromGMT " , value: secondsFromGMT ( ) ) )
243
+ c. append ( ( label: " isDaylightSavingTime " , value: isDaylightSavingTime ( ) ) )
244
+ return Mirror ( self , children: c, displayStyle: Mirror . DisplayStyle. struct)
245
+ }
246
+
247
+ public var description : String {
248
+ return " \( identifier) ( \( _kindDescription) ) "
249
+ }
250
+
251
+ public var debugDescription : String {
252
+ return " \( identifier) ( \( _kindDescription) ) "
220
253
}
221
254
}
222
255
@@ -248,4 +281,3 @@ extension TimeZone {
248
281
return result!
249
282
}
250
283
}
251
-
0 commit comments