.../Source/Utilities/ISO8601Helpers.swift
Line  | Count  | Source  | 
1  |  | //  | 
2  |  | //  ISO8601Helpers.swift  | 
3  |  | //  CutBox  | 
4  |  | //  | 
5  |  | //  Created by Jason Milkins on 19/8/23.  | 
6  |  | //  Copyright © 2023 ocodo. All rights reserved.  | 
7  |  | //  | 
8  |  |  | 
9  |  | import Foundation  | 
10  |  |  | 
11  |  | /// Quick conversion of Date to ISO8601 timestamp  | 
12  | 1.48k  | func iso8601Timestamp(fromDate: Date) -> String { | 
13  | 1.48k  |     let dateFormatter = DateFormatter()  | 
14  | 1.48k  |     dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)  | 
15  | 1.48k  |     dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'"  | 
16  | 1.48k  |     return dateFormatter.string(from: fromDate)  | 
17  | 1.48k  | }  | 
18  |  |  | 
19  |  | /// Quick generation of ISO8601 timestamp of seconds (as Double) before time  | 
20  | 4  | func secondsBeforeTimeNowAsISO8601(seconds: Double) -> String { | 
21  | 4  |     let date = Date(timeIntervalSinceNow: -seconds)  | 
22  | 4  |     return iso8601Timestamp(fromDate: date)  | 
23  | 4  | }  |