Stub out closing soon badge

This commit is contained in:
Andy Smith
2025-04-14 17:02:50 -05:00
parent 028a43e652
commit ff6464ffef
4 changed files with 48 additions and 1 deletions
@@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"
import { differenceInDays } from "helpers/date_helpers"
export default class extends Controller {
static targets = [ "time", "date", "datetime", "shortdate", "ago", "indays", "daysago" ]
static targets = [ "time", "date", "datetime", "shortdate", "ago", "indays", "daysago", "daysuntil" ]
#timer
@@ -14,6 +14,7 @@ export default class extends Controller {
this.agoFormatter = new AgoFormatter()
this.daysagoFormatter = new DaysAgoFormatter()
this.indaysFormatter = new InDaysFormatter()
this.daysuntilFormatter = new DaysUntilFormatter()
}
connect() {
@@ -60,6 +61,10 @@ export default class extends Controller {
this.#formatTime(this.daysagoFormatter, target)
}
daysuntilTargetConnected(target) {
this.#formatTime(this.daysuntilFormatter, target)
}
#refreshRelativeTimes() {
this.agoTargets.forEach(target => {
this.#formatTime(this.agoFormatter, target)
@@ -121,6 +126,13 @@ class InDaysFormatter {
}
}
class DaysUntilFormatter {
format(date) {
const days = differenceInDays(new Date(), date)
return styleableValue(days)
}
}
function styleableValue(value) {
return `<span class="local-time-value">${value}</span>`
}