98b7600797
对标安卓正式版、对接 app-server(8770)的 SwiftUI 客户端。iOS 无障碍受限、无比价核心,做自成一体:美团 CPS 导购 + 福利(签到/任务/金币)+ 查看(比价记录/省钱战绩)。 功能完整 M0-M5:脚手架、短信登录(JWT+Keychain+401 自动刷新)、首页券 feed 导购、比价记录+省钱战绩、福利、我的(资料/反馈/设置/注销)。 单 target、0 三方依赖、XcodeGen 生成工程;Debug/Release 双 plist 分流 ATS。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
30 lines
1.1 KiB
Swift
30 lines
1.1 KiB
Swift
import Foundation
|
|
|
|
/// 后端 ISO 8601 时间字符串 → 友好展示。后端 datetime 可能带/不带时区与微秒,逐档尝试解析。
|
|
enum AppDate {
|
|
static func friendly(_ iso: String) -> String {
|
|
guard let date = parse(iso) else { return String(iso.prefix(10)) }
|
|
let f = DateFormatter()
|
|
f.locale = Locale(identifier: "zh_CN")
|
|
f.dateFormat = "M月d日"
|
|
return f.string(from: date)
|
|
}
|
|
|
|
private static func parse(_ iso: String) -> Date? {
|
|
let isoFmt = ISO8601DateFormatter()
|
|
isoFmt.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
|
if let d = isoFmt.date(from: iso) { return d }
|
|
isoFmt.formatOptions = [.withInternetDateTime]
|
|
if let d = isoFmt.date(from: iso) { return d }
|
|
|
|
let df = DateFormatter()
|
|
df.locale = Locale(identifier: "en_US_POSIX")
|
|
df.timeZone = TimeZone(identifier: "Asia/Shanghai")
|
|
for fmt in ["yyyy-MM-dd'T'HH:mm:ss.SSSSSS", "yyyy-MM-dd'T'HH:mm:ss.SSS", "yyyy-MM-dd'T'HH:mm:ss"] {
|
|
df.dateFormat = fmt
|
|
if let d = df.date(from: iso) { return d }
|
|
}
|
|
return nil
|
|
}
|
|
}
|