ManaView (Guthaben + EUR + Topf-Split 80/5/5/5/5 + Bewegungen) + ManaBalanceRow + ManaFormat + ManaCreditsModel. Pendant zur Web-<ManaPage>. Konsumiert ManaCreditsClient (ManaCore), System-Styling, app-agnostisch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
42 lines
1.6 KiB
Swift
42 lines
1.6 KiB
Swift
import Foundation
|
||
|
||
/// Formatierungs-Helfer für Mana-Werte (1 Mana = 1 Cent).
|
||
public enum ManaFormat {
|
||
/// Mana als Ganzzahl mit Tausender-Trennung: 1234 → „1.234".
|
||
public static func mana(_ value: Int) -> String {
|
||
let f = NumberFormatter()
|
||
f.locale = Locale(identifier: "de_DE")
|
||
f.numberStyle = .decimal
|
||
f.maximumFractionDigits = 0
|
||
return f.string(from: NSNumber(value: value)) ?? String(value)
|
||
}
|
||
|
||
/// Mana → EUR-Gegenwert: 1234 → „12,34 €".
|
||
public static func euro(_ mana: Int) -> String {
|
||
let f = NumberFormatter()
|
||
f.locale = Locale(identifier: "de_DE")
|
||
f.numberStyle = .currency
|
||
f.currencyCode = "EUR"
|
||
return f.string(from: NSNumber(value: Double(mana) / 100.0)) ?? "\(mana) ct"
|
||
}
|
||
|
||
/// Vorzeichenbehaftete Mana-Menge für eine Bewegung: 12 → „+12", -5 → „−5".
|
||
public static func signedMana(_ value: Int) -> String {
|
||
let sign = value < 0 ? "−" : "+"
|
||
return sign + mana(abs(value))
|
||
}
|
||
|
||
/// ISO-8601-Zeitstempel → kurzes deutsches Datum („7. Juni 2026").
|
||
/// Fällt bei Parse-Fehler auf den Rohwert zurück.
|
||
public static func shortDate(_ iso: String) -> String {
|
||
let parser = ISO8601DateFormatter()
|
||
parser.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
||
let date = parser.date(from: iso) ?? ISO8601DateFormatter().date(from: iso)
|
||
guard let date else { return iso }
|
||
let out = DateFormatter()
|
||
out.locale = Locale(identifier: "de_DE")
|
||
out.dateStyle = .medium
|
||
out.timeStyle = .none
|
||
return out.string(from: date)
|
||
}
|
||
}
|