Skip to content

Commit

Permalink
Ui: restore semi-legacy browser support (evcc-io#17061)
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis authored and jonilala796 committed Jan 3, 2025
1 parent 411717d commit 83ff88d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 2 additions & 1 deletion assets/js/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ function updateCssColors() {
}

// update colors on theme change
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", updateCssColors);
const darkModeMatcher = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)");
darkModeMatcher?.addEventListener("change", updateCssColors);
updateCssColors();

export const dimColor = (color) => {
Expand Down
25 changes: 17 additions & 8 deletions assets/js/mixins/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,17 @@ export default {
return tomorrow.toDateString() === date.toDateString();
},
weekdayPrefix: function (date) {
const rtf = new Intl.RelativeTimeFormat(this.$i18n?.locale, { numeric: "auto" });

if (this.isToday(date)) {
return ""; //rtf.formatToParts(0, "day")[0].value;
return "";
}
if (this.isTomorrow(date)) {
return rtf.formatToParts(1, "day")[0].value;
try {
const rtf = new Intl.RelativeTimeFormat(this.$i18n?.locale, { numeric: "auto" });
return rtf.formatToParts(1, "day")[0].value;
} catch (e) {
console.warn("weekdayPrefix: Intl.RelativeTimeFormat not supported", e);
return "tomorrow";
}
}
return new Intl.DateTimeFormat(this.$i18n?.locale, {
weekday: "short",
Expand Down Expand Up @@ -288,12 +292,17 @@ export default {
second: 1000,
};

const rtf = new Intl.RelativeTimeFormat(this.$i18n?.locale, { numeric: "auto" });

// "Math.abs" accounts for both "past" & "future" scenarios
for (var u in units)
if (Math.abs(elapsed) > units[u] || u == "second")
return rtf.format(Math.round(elapsed / units[u]), u);
if (Math.abs(elapsed) > units[u] || u == "second") {
try {
const rtf = new Intl.RelativeTimeFormat(this.$i18n?.locale, { numeric: "auto" });
return rtf.format(Math.round(elapsed / units[u]), u);
} catch (e) {
console.warn("fmtTimeAgo: Intl.RelativeTimeFormat not supported", e);
return `${elapsed} ${u}s ago`;
}
}
},
fmtSocOption: function (soc, rangePerSoc, distanceUnit, heating) {
let result = heating ? this.fmtTemperature(soc) : `${this.fmtPercentage(soc)}`;
Expand Down
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default defineConfig({
plugins: [
legacy({
targets: ["defaults", "iOS >= 14"],
modernPolyfills: ["es.promise.all-settled"],
}),
vuePlugin({
template: {
Expand Down

0 comments on commit 83ff88d

Please sign in to comment.