import Foundation /// The web's chat.HeldWords, for holds that need the person's choice. enum HeldLead { static func words(_ hold: ThinHold, name: String, due: Date?, words: TimeWords) -> String { func when(_ date: Date) -> String { String(format: EquipoStrings.text("time.when_in"), words.when(date), words.inWords(date.timeIntervalSince(words.now))) } func day(_ date: Date) -> String { let formatter = DateFormatter() formatter.locale = words.locale; formatter.timeZone = words.zone formatter.dateFormat = "EEEE d MMM" return formatter.string(from: date) } // The autonomy limit's hold: Design ran wire.DesignRunLimit (3) // attempts since the person last acted on the task. if hold.reason == "design_limit" { return String(format: EquipoStrings.text("chat.held.design_limit"), Int32(3)) } if let reset = hold.resetsAt, let due, reset < due { return String(format: EquipoStrings.text("chat.held.wait.before"), name, when(reset), day(due)) } if let reset = hold.resetsAt, reset.timeIntervalSince(words.now) <= 72 * 3600, hold.needsPerson != "deadline" { return String(format: EquipoStrings.text("chat.held.wait.reset"), name, when(reset)) } if let reset = hold.resetsAt, let due { return String(format: EquipoStrings.text("chat.held.run.after_by"), name, when(reset), day(due)) } if hold.reason == "budget" { return String(format: EquipoStrings.text("chat.held.budget"), name) } return String(format: EquipoStrings.text("chat.held.run.no_reset"), name) } }