// The app's date spellings, stated once.//// These spellings are NOT negotiable per surface, and they are the APP's, never// the device locale's — which is why every formatter here pins `en_US_POSIX`// and writes an explicit pattern. A phone set to US English must still read// "17 Aug", not "Aug 17".//// EVERY function takes its `now` and its `Calendar`; nothing reads the wall// clock or `Calendar.current` from inside. A fixed-`now` test over a function// that defaulted to the clock is a time bomb with a computable detonation date.// The default argument is at the CALL SITE's convenience only.importCottonKitimportCottonValuesimportFoundationpublicenumDateFormats {/// `7:30 pm` — lowercase am/pm, ALWAYS, and no leading zero on the hour.publicstaticfunc houseTime(_ at: Date, calendar: Calendar = .current) -> String {CottonDate.string(at, pattern: "h:mm a", calendar: calendar).lowercased() }/// `Mon 17 Aug` — short weekday, NO comma, short month, no year. The year/// is not this format's job.publicstaticfunc weekdayDate(_ at: Date, calendar: Calendar = .current) -> String {CottonDate.string(at, pattern: "EEE d MMM", calendar: calendar) }/// `8 August 2026` — the spelled-out form, for a record's own screen.publicstaticfunc longDate(_ at: Date, calendar: Calendar = .current) -> String {CottonDate.string(at, pattern: "d MMMM yyyy", calendar: calendar) }}/// The heading a list gives the day it is today, in the `dates` set's words.publicenumDayHeads {publicstaticvar today: String { ShellLines.line("dates", "heading.today") }/// A month's short name off the dates set ("Oct"), `month` 1–12.publicstaticfunc month(_ month: Int) -> String {let keys = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]return keys.indices.contains(month - 1) ? ShellLines.line("dates", "months.\(keys[month - 1])") : "" }}/// What a slip says of its date column, by the heading it stands under (R7/// b, c): the heading already named the day, so a slip under a day heading/// says the time alone, and one under a month heading says the day alone.publicenumDayWords: Hashable, Sendable {/// No heading names the day: the day and the time.case full/// Under a day heading: `3:24 am` or `All day`.case timeUnderDay/// Under a month heading: `Fri 2 Oct`.case dayUnderMonth/// A list with no heading over the slip (a chat list): the clock alone/// today, `Yesterday`, else the weekday date (R7 d).case noHeading/// A date column's value as this context says it, from the core's/// parts; nil for `.full`, which is the face's own words.publicfunc words(_ parts: DayParts?) -> String? {guardlet parts else { returnnil }switchself {case .full: returnnilcase .timeUnderDay: return parts.underDaycase .dayUnderMonth: return parts.weekdayDatecase .noHeading: return parts.recent } }}extensionDateFormats {// ── R7: the day and the time as the lists, pages and receipts say them ──//// The architect's ruling of 5 Oct 2026 (R7): a day is said ONCE and in ONE// way, the year only when it is not this year, the time alone under a day// heading, and never a relative count of days ("In 3 days", "2d ago").// Every spelling below takes its `now` and its calendar: the heading a// record sits under, the day its slip shows and the day its page shows all// come from the same calendar day in the person's own zone (R7 g)./// The caption a record's date line reads: the clock today, `Yesterday`,/// else the weekday date, its year only outside this one (R7 d, h: a/// relative count of days appears nowhere, so "2d ago" is gone).publicstaticfunc recordDateLabel(_ at: Date, now: Date, calendar: Calendar = .current) -> String {if calendar.isDate(at, inSameDayAs: now) { return houseTime(at, calendar: calendar) }iflet yesterday = calendar.date(byAdding: .day, value: -1, to: now), calendar.isDate(at, inSameDayAs: yesterday) {return"Yesterday" }let sameYear = calendar.component(.year, from: at) == calendar.component(.year, from: now)returnCottonDate.string(at, pattern: sameYear ? "EEE d MMM" : "EEE d MMM yyyy", calendar: calendar) }}