unixMilleseconds calculation off of existing date. open toJSONString options.

This commit is contained in:
Hedden, Kyle Matthew 2024-02-01 13:50:12 -05:00
parent b0bc8994ee
commit 4552a57ea2
2 changed files with 7 additions and 3 deletions

View File

@ -11,6 +11,10 @@ import Foundation
public extension Date { public extension Date {
static func unixMillisecondsNow() -> Int64 { static func unixMillisecondsNow() -> Int64 {
return Int64(Self().timeIntervalSince1970 * 1000) return Self().unixMilliseconds()
}
func unixMilliseconds() -> Int64 {
return Int64(self.timeIntervalSince1970 * 1000)
} }
} }

View File

@ -43,9 +43,9 @@ extension Encodable {
return jsonArray return jsonArray
} }
public func toJSONString() -> String? { public func toJSONString(options: JSONSerialization.WritingOptions = .prettyPrinted) -> String? {
guard let json = self.toJSON(), guard let json = self.toJSON(),
let data = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), let data = try? JSONSerialization.data(withJSONObject: json, options: options),
let string = String(data: data, encoding: .utf8) else { let string = String(data: data, encoding: .utf8) else {
return nil return nil
} }