Skip to content

Commit 60f6f7a

Browse files
committed
Recore Date
1 parent 74b371d commit 60f6f7a

File tree

2 files changed

+54
-64
lines changed

2 files changed

+54
-64
lines changed

Sources/Foundation/Date.swift

-43
This file was deleted.

Sources/Foundation/NSDate.swift

+54-21
Original file line numberDiff line numberDiff line change
@@ -226,30 +226,15 @@ extension NSDate {
226226
}
227227
}
228228

229-
extension NSDate: _SwiftBridgeable {
230-
typealias SwiftType = Date
231-
var _swiftObject: Date {
232-
return Date(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate)
229+
extension Date : CustomPlaygroundDisplayConvertible {
230+
public var playgroundDescription: Any {
231+
let df = DateFormatter()
232+
df.dateStyle = .medium
233+
df.timeStyle = .short
234+
return df.string(from: self)
233235
}
234236
}
235237

236-
extension CFDate : _NSBridgeable, _SwiftBridgeable {
237-
typealias NSType = NSDate
238-
typealias SwiftType = Date
239-
240-
internal var _nsObject: NSType { return unsafeBitCast(self, to: NSType.self) }
241-
internal var _swiftObject: Date { return _nsObject._swiftObject }
242-
}
243-
244-
extension Date : _NSBridgeable {
245-
typealias NSType = NSDate
246-
typealias CFType = CFDate
247-
248-
internal var _nsObject: NSType { return NSDate(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) }
249-
internal var _cfObject: CFType { return _nsObject._cfObject }
250-
}
251-
252-
253238
open class NSDateInterval : NSObject, NSCopying, NSSecureCoding {
254239

255240

@@ -407,6 +392,8 @@ open class NSDateInterval : NSObject, NSCopying, NSSecureCoding {
407392
}
408393
}
409394

395+
// MARK: - Bridging
396+
410397
extension NSDate : _StructTypeBridgeable {
411398
public typealias _StructType = Date
412399

@@ -429,3 +416,49 @@ extension NSDateInterval : _SwiftBridgeable {
429416
}
430417
}
431418

419+
extension NSDate: _SwiftBridgeable {
420+
typealias SwiftType = Date
421+
var _swiftObject: Date {
422+
return Date(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate)
423+
}
424+
}
425+
426+
extension CFDate : _NSBridgeable, _SwiftBridgeable {
427+
typealias NSType = NSDate
428+
typealias SwiftType = Date
429+
430+
internal var _nsObject: NSType { return unsafeBitCast(self, to: NSType.self) }
431+
internal var _swiftObject: Date { return _nsObject._swiftObject }
432+
}
433+
434+
extension Date : _NSBridgeable {
435+
typealias NSType = NSDate
436+
typealias CFType = CFDate
437+
438+
internal var _nsObject: NSType { return NSDate(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate) }
439+
internal var _cfObject: CFType { return _nsObject._cfObject }
440+
}
441+
442+
extension Date : _ObjectiveCBridgeable {
443+
@_semantics("convertToObjectiveC")
444+
public func _bridgeToObjectiveC() -> NSDate {
445+
return NSDate(timeIntervalSinceReferenceDate: timeIntervalSinceReferenceDate)
446+
}
447+
448+
public static func _forceBridgeFromObjectiveC(_ x: NSDate, result: inout Date?) {
449+
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
450+
fatalError("Unable to bridge \(NSDate.self) to \(self)")
451+
}
452+
}
453+
454+
public static func _conditionallyBridgeFromObjectiveC(_ x: NSDate, result: inout Date?) -> Bool {
455+
result = Date(timeIntervalSinceReferenceDate: x.timeIntervalSinceReferenceDate)
456+
return true
457+
}
458+
459+
public static func _unconditionallyBridgeFromObjectiveC(_ source: NSDate?) -> Date {
460+
var result: Date? = nil
461+
_forceBridgeFromObjectiveC(source!, result: &result)
462+
return result!
463+
}
464+
}

0 commit comments

Comments
 (0)