Skip to content

Commit de5c39e

Browse files
committed
fixes #22. Safari & firefox can't parse string dates as chrome does.
1 parent 1bd6bec commit de5c39e

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

dist/plotly-graph-card.js

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"dependencies": {
2424
"@types/lodash": "^4.14.175",
2525
"custom-card-helpers": "^1.8.0",
26+
"date-fns": "^2.28.0",
2627
"deepmerge": "^4.2.2",
2728
"lodash": "^4.17.21",
2829
"plotly.js": "^2.8.3"

src/Cache.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { isTruthy } from "./style-hack";
44
import { TimestampRange, History } from "./types";
55
import { sleep } from "./utils";
66

7-
type Histories = Record<string, History>;
8-
97
export function mapValues<T, S>(
108
o: Record<string, T>,
119
fn: (value: T, key: string) => S

src/date-ranges.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { json } from "stream/consumers";
12
import { TimestampRange } from "./types";
23

34
const subtract_single_single = (
@@ -22,11 +23,10 @@ const subtract_single_single = (
2223
if (a_start < b_start && b_start <= a_end && a_end <= b_end)
2324
return [[a_start, b_start - 1]];
2425
else {
25-
console.log("----ERROR TO REPORT-----");
26-
console.log([a_start, a_end]);
27-
console.log([b_start, b_end]);
2826
throw new Error(
29-
"Error computing range subtraction. Please report an issue in the repo of this card."
27+
`Error computing range subtraction. Please report an issue in the repo of this card and share this:`+
28+
JSON.stringify([a_start, a_end]) +
29+
JSON.stringify([b_start, b_end])
3030
);
3131
}
3232
};

src/plotly-graph-card.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import isProduction from "./is-production";
1313
import { sleep } from "./utils";
1414
import { Datum } from "plotly.js";
1515
import colorSchemes from "./color-schemes";
16+
import {parseISO} from 'date-fns'
1617

1718
const componentName = isProduction ? "plotly-graph" : "plotly-graph-dev";
1819

@@ -143,7 +144,7 @@ export class PlotlyGraph extends HTMLElement {
143144
return [+new Date() - ms, +new Date()] as [number, number];
144145
}
145146
getVisibleRange() {
146-
return this.contentEl.layout.xaxis!.range!.map((date) => +new Date(date));
147+
return this.contentEl.layout.xaxis!.range!.map((date) => +parseISO(date));
147148
}
148149
async enterBrowsingMode() {
149150
this.isBrowsing = true;
@@ -449,7 +450,7 @@ export class PlotlyGraph extends HTMLElement {
449450
}
450451
static getStubConfig() {
451452
return {
452-
entities: [{ entity: "sun.sun::elevation" }],
453+
entities: [{ entity: "sun.sun" }],
453454
hours_to_show: 24,
454455
refresh_interval: 10,
455456
};

0 commit comments

Comments
 (0)