Skip to content

Commit 8dc63e9

Browse files
committed
Comment out notification posting, update TimeZone to match apple/swift
1 parent e332592 commit 8dc63e9

File tree

2 files changed

+53
-21
lines changed

2 files changed

+53
-21
lines changed

Foundation/NSTimeZone.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ extension NSTimeZone {
174174

175175
open class func resetSystemTimeZone() {
176176
CFTimeZoneResetSystem()
177-
NotificationCenter.default.post(name: NSNotification.Name.NSSystemTimeZoneDidChange, object: nil)
177+
// NotificationCenter.default.post(name: NSNotification.Name.NSSystemTimeZoneDidChange, object: nil)
178178
}
179179

180180
open class var `default`: TimeZone {
@@ -183,7 +183,7 @@ extension NSTimeZone {
183183
}
184184
set {
185185
CFTimeZoneSetDefault(newValue._cfObject)
186-
NotificationCenter.default.post(name: NSNotification.Name.NSSystemTimeZoneDidChange, object: nil)
186+
// NotificationCenter.default.post(name: NSNotification.Name.NSSystemTimeZoneDidChange, object: nil)
187187
}
188188
}
189189

Foundation/TimeZone.swift

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@
1111
//===----------------------------------------------------------------------===//
1212

1313

14-
1514
internal func __NSTimeZoneIsAutoupdating(_ timezone: NSTimeZone) -> Bool {
1615
return false
1716
}
1817

18+
internal func __NSTimeZoneAutoupdating() -> NSTimeZone {
19+
return NSTimeZone.local._nsObject
20+
}
21+
22+
internal func __NSTimeZoneCurrent() -> NSTimeZone {
23+
return NSTimeZone.system._nsObject
24+
}
25+
1926
/**
2027
`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).
2128

@@ -25,20 +32,24 @@ internal func __NSTimeZoneIsAutoupdating(_ timezone: NSTimeZone) -> Bool {
2532

2633
Cocoa does not provide any API to change the time zone of the computer, or of other applications.
2734
*/
28-
public struct TimeZone : CustomStringConvertible, CustomDebugStringConvertible, Hashable, Equatable, ReferenceConvertible {
35+
public struct TimeZone : Hashable, Equatable, ReferenceConvertible {
2936
public typealias ReferenceType = NSTimeZone
3037

3138
internal var _wrapped : NSTimeZone
3239
internal var _autoupdating : Bool
3340

3441
/// The time zone currently used by the system.
3542
public static var current : TimeZone {
36-
return NSTimeZone.system
43+
return TimeZone(adoptingReference: __NSTimeZoneCurrent(), autoupdating: false)
3744
}
3845

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.
4051
public static var autoupdatingCurrent : TimeZone {
41-
return NSTimeZone.local
52+
return TimeZone(adoptingReference: __NSTimeZoneAutoupdating(), autoupdating: true)
4253
}
4354

4455
// MARK: -
@@ -195,28 +206,50 @@ public struct TimeZone : CustomStringConvertible, CustomDebugStringConvertible,
195206

196207
// MARK: -
197208

198-
public var description: String {
199-
return _wrapped.description
200-
}
201-
202-
public var debugDescription : String {
203-
return _wrapped.debugDescription
204-
}
205-
206209
public var hashValue : Int {
207210
if _autoupdating {
208211
return 1
209212
} else {
210213
return _wrapped.hash
211214
}
212215
}
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+
}
213224
}
214225

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))"
220253
}
221254
}
222255

@@ -248,4 +281,3 @@ extension TimeZone {
248281
return result!
249282
}
250283
}
251-

0 commit comments

Comments
 (0)