Stub out closing soon badge
This commit is contained in:
@@ -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>`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user