mirror of
https://github.com/VGEAREN/Stockbar.git
synced 2026-10-06 14:33:11 +08:00
v1.2.6: Hide daily PnL on non-trading days (holidays/weekends)
- Add Quote.isToday: compare updateTime date with today in Beijing timezone - effectiveDailyPnl returns nil when quote data is stale (not from today) - Prevents showing yesterday's change as today's daily PnL on closed markets Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
592ad90f61
commit
f8bb287194
@@ -32,6 +32,19 @@ struct Quote {
|
||||
var isUp: Bool { change > 0 }
|
||||
var isDown: Bool { change < 0 }
|
||||
|
||||
/// 数据是否为今天(通过 updateTime 中的日期判断)
|
||||
var isToday: Bool {
|
||||
// 匹配 yyyy-MM-dd 或 yyyy/MM/dd 格式
|
||||
let digits = updateTime.replacingOccurrences(of: "/", with: "-")
|
||||
guard digits.count >= 10 else { return false }
|
||||
let dateStr = String(digits.prefix(10))
|
||||
let fmt = DateFormatter()
|
||||
fmt.dateFormat = "yyyy-MM-dd"
|
||||
fmt.timeZone = TimeZone(identifier: "Asia/Shanghai")
|
||||
let today = fmt.string(from: Date())
|
||||
return dateStr == today
|
||||
}
|
||||
|
||||
var formattedPercent: String {
|
||||
let sign = changePercent >= 0 ? "+" : ""
|
||||
return String(format: "\(sign)%.2f%%", changePercent)
|
||||
|
||||
@@ -260,6 +260,8 @@ final class AppState: ObservableObject {
|
||||
|
||||
func effectiveDailyPnl(stock: Stock, quote: Quote) -> Double? {
|
||||
guard let shares = effectiveShares(for: stock) else { return nil }
|
||||
// 休市日数据是昨天的,不显示日盈亏
|
||||
guard quote.isToday else { return nil }
|
||||
return quote.change * shares
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user