| 1 | import Foundation |
| 2 | |
| 3 | /// The web's chat.HeldWords, for holds that need the person's choice. |
| 4 | enum HeldLead { |
| 5 | static func words(_ hold: ThinHold, name: String, due: Date?, words: TimeWords) -> String { |
| 6 | func when(_ date: Date) -> String { String(format: EquipoStrings.text("time.when_in"), words.when(date), words.inWords(date.timeIntervalSince(words.now))) } |
| 7 | func day(_ date: Date) -> String { |
| 8 | let formatter = DateFormatter() |
| 9 | formatter.locale = words.locale; formatter.timeZone = words.zone |
| 10 | formatter.dateFormat = "EEEE d MMM" |
| 11 | return formatter.string(from: date) |
| 12 | } |
| 13 | // The autonomy limit's hold: Design ran wire.DesignRunLimit (3) |
| 14 | // attempts since the person last acted on the task. |
| 15 | if hold.reason == "design_limit" { return String(format: EquipoStrings.text("chat.held.design_limit"), Int32(3)) } |
| 16 | if let reset = hold.resetsAt, let due, reset < due { |
| 17 | return String(format: EquipoStrings.text("chat.held.wait.before"), name, when(reset), day(due)) |
| 18 | } |
| 19 | if let reset = hold.resetsAt, reset.timeIntervalSince(words.now) <= 72 * 3600, hold.needsPerson != "deadline" { |
| 20 | return String(format: EquipoStrings.text("chat.held.wait.reset"), name, when(reset)) |
| 21 | } |
| 22 | if let reset = hold.resetsAt, let due { |
| 23 | return String(format: EquipoStrings.text("chat.held.run.after_by"), name, when(reset), day(due)) |
| 24 | } |
| 25 | if hold.reason == "budget" { return String(format: EquipoStrings.text("chat.held.budget"), name) } |
| 26 | return String(format: EquipoStrings.text("chat.held.run.no_reset"), name) |
| 27 | } |
| 28 | } |
| 29 | |