완료 방송 상대 시간 표시

최근 종료 방송 카드에 UTC 기준 상대 시간 문자열을 표시한다.
This commit is contained in:
Yu Sung
2025-12-19 23:52:43 +09:00
parent 7307e5b255
commit dd51a3fc2e
5 changed files with 111 additions and 56 deletions

View File

@@ -0,0 +1,60 @@
//
// DateParser.swift
// SodaLive
//
// Created by klaus on 12/19/25.
//
import Foundation
// MARK: - :
enum DateParser {
static func parse(_ text: String) -> Date? {
for parser in parsers {
if let d = parser(text) { return d }
}
return nil
}
// : ISO8601( ) ISO8601 RFC3339
private static let parsers: [(String) -> Date?] = [
{ ISO8601.fractional.date(from: $0) },
{ ISO8601.basic.date(from: $0) },
{ DF.rfc3339.date(from: $0) },
{ DF.basic.date(from: $0) }
]
private enum ISO8601 {
static let fractional: ISO8601DateFormatter = {
let f = ISO8601DateFormatter()
f.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
f.timeZone = TimeZone(secondsFromGMT: 0)
return f
}()
static let basic: ISO8601DateFormatter = {
let f = ISO8601DateFormatter()
f.formatOptions = [.withInternetDateTime]
f.timeZone = TimeZone(secondsFromGMT: 0)
return f
}()
}
private enum DF {
static let rfc3339: DateFormatter = {
let f = DateFormatter()
f.locale = Locale(identifier: "en_US_POSIX")
f.timeZone = TimeZone(secondsFromGMT: 0)
f.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
return f
}()
static let basic: DateFormatter = {
let f = DateFormatter()
f.locale = Locale(identifier: "en_US_POSIX")
f.timeZone = TimeZone(secondsFromGMT: 0)
f.dateFormat = "yyyy-MM-dd HH:mm:ss"
return f
}()
}
}