26 lines
919 B
Swift
26 lines
919 B
Swift
import Foundation
|
|
|
|
enum FeishuDateParser {
|
|
static func parse(_ value: Any?) -> Date? {
|
|
switch value {
|
|
case let milliseconds as Double:
|
|
return Date(timeIntervalSince1970: milliseconds / 1000.0)
|
|
case let milliseconds as Int:
|
|
return Date(timeIntervalSince1970: Double(milliseconds) / 1000.0)
|
|
case let string as String:
|
|
if let milliseconds = Double(string) {
|
|
return Date(timeIntervalSince1970: milliseconds / 1000.0)
|
|
}
|
|
let formatter = ISO8601DateFormatter()
|
|
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
|
if let date = formatter.date(from: string) {
|
|
return date
|
|
}
|
|
formatter.formatOptions = [.withInternetDateTime]
|
|
return formatter.date(from: string)
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
}
|