mirror of
https://github.com/aculix/negotium.git
synced 2026-09-11 07:28:17 +00:00
1198158abf
Two pieces of copy that were making the app harder to read than it needs to be. Carry-over happened in total silence. Open the app after a weekend and unfamiliar tasks were sitting in Today with nothing explaining where they came from, which reads as a bug rather than the feature it is. A line now says how many were brought forward, on the day it happened, and it can be dismissed. The day control was a single button labelled with the day you were already on, which then took you somewhere else. Clicking it was the only way to find out what it did, and the date underneath already said where you were. It is two options now with the current one marked, so the control states both where you are and what the alternative is without being touched. Also drops labelFor from dates.js along with its tests. It existed to label that one button and nothing uses it now.
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
const KEY_PATTERN = /^\d{4}-\d{2}-\d{2}$/
|
|
|
|
/** A `Date` as a local-time `YYYY-MM-DD` key. Sortable, which is what the
|
|
* rollover logic relies on to find every day earlier than today. */
|
|
export function toKey(date) {
|
|
const year = date.getFullYear()
|
|
const month = String(date.getMonth() + 1).padStart(2, '0')
|
|
const day = String(date.getDate()).padStart(2, '0')
|
|
return `${year}-${month}-${day}`
|
|
}
|
|
|
|
/** Local midnight for a key. Built from parts rather than `new Date(key)`,
|
|
* which parses bare ISO dates as UTC and shifts the day west of Greenwich. */
|
|
export function fromKey(key) {
|
|
const [year, month, day] = key.split('-').map(Number)
|
|
return new Date(year, month - 1, day)
|
|
}
|
|
|
|
/** Goes through `setDate`, so it stays on the same calendar day across a DST
|
|
* boundary rather than adding a fixed 24 hours. */
|
|
export function addDays(date, amount) {
|
|
const next = new Date(date.getTime())
|
|
next.setDate(next.getDate() + amount)
|
|
return next
|
|
}
|
|
|
|
export function isKey(value) {
|
|
return KEY_PATTERN.test(value)
|
|
}
|
|
|
|
export function formatLong(dateKey) {
|
|
return fromKey(dateKey).toLocaleDateString('en-US', {
|
|
weekday: 'long',
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
})
|
|
}
|