mirror of
https://github.com/home-assistant/frontend.git
synced 2026-04-02 00:27:49 +01:00
Use whole months for "Last 12 Months" on Energy Date Picker (#30091)
* Make "now-12m" use month boundaries Currently the "Last 12 Months" date function calculates precisely 12 months from the current day. So today is March 10, then it would retrieve April 11 to March 10. However logically the name implies whole months - i.e. "now" would be "March", so the last 12 months ought to be Apr 1 to March 31. * Let energy date picker detect 12 Month range With now-12m changed to mean whole months rather than partial months, we can make the energy date picker nicely detect and render any month range, and also fix the now button so that it can pick a "now-12m" range. * Use Short Month for Displayed Range To avoid making the displayed range too large to fit on small screens. * Move subMonths into calcDate fn not input Perform both startOfMonth and subMonths as a custom function in calcDate rather than performing subMonths on the input to avoid any wierd timezone issues. Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com> --------- Co-authored-by: Petar Petrov <MindFreeze@users.noreply.github.com>
This commit is contained in:
@@ -166,6 +166,21 @@ const formatDateMonthMem = memoizeOne(
|
||||
})
|
||||
);
|
||||
|
||||
// Aug
|
||||
export const formatDateMonthShort = (
|
||||
dateObj: Date,
|
||||
locale: FrontendLocaleData,
|
||||
config: HassConfig
|
||||
) => formatDateMonthShortMem(locale, config.time_zone).format(dateObj);
|
||||
|
||||
const formatDateMonthShortMem = memoizeOne(
|
||||
(locale: FrontendLocaleData, serverTimeZone: string) =>
|
||||
new Intl.DateTimeFormat(locale.language, {
|
||||
month: "short",
|
||||
timeZone: resolveTimeZone(locale.time_zone, serverTimeZone),
|
||||
})
|
||||
);
|
||||
|
||||
// 2021
|
||||
export const formatDateYear = (
|
||||
dateObj: Date,
|
||||
|
||||
Reference in New Issue
Block a user