mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-29 10:18:29 -04:00
The garden dialog now adds a garden as well as edits one (new.json and create.json on GardensController), and a GardenPicker button opens it from the home page. A plant_picker helper replaces the home page's separate plant links and the plant_button partial. The plant dialog asks when it was planted (Today, Yesterday, Enter date), using a WhenPicker shared with the harvest dialog. Members with no garden still get the full-page plant link. Part of #4933 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
24 lines
1.0 KiB
JavaScript
24 lines
1.0 KiB
JavaScript
// "12 Sep", or "12 Sep 2025" when it isn't this year. `iso` is a date as the
|
|
// server sends it: "2026-09-12". Parsed by hand so it isn't shifted by the
|
|
// browser's time zone.
|
|
export function formatDate(iso) {
|
|
const [year, month, day] = iso.split('-').map(Number);
|
|
const options = {day: 'numeric', month: 'short'};
|
|
if (year !== new Date().getFullYear()) options.year = 'numeric';
|
|
return new Date(year, month - 1, day).toLocaleDateString(undefined, options);
|
|
}
|
|
|
|
// "2026-09-21" a number of days earlier (or later, if negative), as
|
|
// "2026-09-20". Worked out in UTC so the browser's time zone can't shift it.
|
|
export function daysBefore(iso, days) {
|
|
const [year, month, day] = iso.split('-').map(Number);
|
|
return new Date(Date.UTC(year, month - 1, day - days)).toISOString().slice(0, 10);
|
|
}
|
|
|
|
// Today in the browser's own time zone, as "2026-09-21".
|
|
export function localToday() {
|
|
const now = new Date();
|
|
const pad = (number) => String(number).padStart(2, '0');
|
|
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`;
|
|
}
|