diff --git a/package.json b/package.json index 5b257ef5..c7ba481c 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ "bootstrap": "^5.3.3", "bootstrap-vue-next": "^0.16.6", "core-js": "^3.36.1", - "date-fns": "^2.30.0", - "date-fns-tz": "^2.0.1", + "date-fns": "^3.6.0", + "date-fns-tz": "^3.0.0", "echarts": "^5.5.0", "favico.js": "^0.3.10", "humanize-duration": "^3.32.0", diff --git a/src/components/charts/CandleChart.vue b/src/components/charts/CandleChart.vue index 3b4b7f50..4fe5ef60 100644 --- a/src/components/charts/CandleChart.vue +++ b/src/components/charts/CandleChart.vue @@ -16,7 +16,6 @@ import { PlotConfig, Trade, } from '@/types'; -import { format } from 'date-fns-tz'; import ECharts from 'vue-echarts'; @@ -44,6 +43,7 @@ import { } from 'echarts/components'; import { use } from 'echarts/core'; import { CanvasRenderer } from 'echarts/renderers'; +import { timestampms } from '@/shared/formatters'; use([ AxisPointerComponent, @@ -645,15 +645,11 @@ function initializeChartOptions() { function updateSliderPosition() { if (!props.sliderPosition) return; - const start = format( - props.sliderPosition.startValue - props.dataset.timeframe_ms * 40, - 'yyyy-MM-dd HH:mm:ss', - ); - const end = format( + const start = timestampms(props.sliderPosition.startValue - props.dataset.timeframe_ms * 40); + const end = timestampms( props.sliderPosition.endValue ? props.sliderPosition.endValue + props.dataset.timeframe_ms * 40 : props.sliderPosition.startValue + props.dataset.timeframe_ms * 80, - 'yyyy-MM-dd HH:mm:ss', ); if (candleChart.value) { candleChart.value.dispatchAction({ diff --git a/src/shared/formatters/timeformat.ts b/src/shared/formatters/timeformat.ts index 5daf7ee2..ac3afbe7 100644 --- a/src/shared/formatters/timeformat.ts +++ b/src/shared/formatters/timeformat.ts @@ -1,12 +1,12 @@ import { parse, toDate } from 'date-fns'; -import { format, utcToZonedTime, zonedTimeToUtc } from 'date-fns-tz'; +import { format, toZonedTime, fromZonedTime } from 'date-fns-tz'; import humanizeDuration from 'humanize-duration'; import { isNotUndefined } from './numberformat'; /** Parse date from string, returns date in UTC! */ export function dateFromString(datestring: string, format: string): Date { const localTime = parse(datestring, format, 0); - return zonedTimeToUtc(localTime, 'UTC'); + return fromZonedTime(localTime, 'UTC'); } let locTimeZone = 'UTC'; @@ -25,7 +25,7 @@ function getTimeZone(tz?: string): string { function formatDate(date: Date, formatPattern: string, timezone?: string): string { const timezoneRes = getTimeZone(timezone); - return format(utcToZonedTime(date, timezoneRes), formatPattern, { + return format(toZonedTime(date, timezoneRes), formatPattern, { timeZone: timezoneRes, }); } diff --git a/yarn.lock b/yarn.lock index 89dabae7..8889f619 100644 --- a/yarn.lock +++ b/yarn.lock @@ -61,15 +61,6 @@ __metadata: languageName: node linkType: hard -"@babel/runtime@npm:^7.21.0": - version: 7.24.4 - resolution: "@babel/runtime@npm:7.24.4" - dependencies: - regenerator-runtime: "npm:^0.14.0" - checksum: 10/8ec8ce2c145bc7e31dd39ab66df124f357f65c11489aefacb30f431bae913b9aaa66aa5efe5321ea2bf8878af3fcee338c87e7599519a952e3a6f83aa1b03308 - languageName: node - linkType: hard - "@babel/types@npm:^7.8.3": version: 7.24.0 resolution: "@babel/types@npm:7.24.0" @@ -2332,21 +2323,14 @@ __metadata: languageName: node linkType: hard -"date-fns-tz@npm:^2.0.1": - version: 2.0.1 - resolution: "date-fns-tz@npm:2.0.1" - peerDependencies: - date-fns: 2.x - checksum: 10/f12e684bc13c9fe7ef7910c5b25437e15290a655d45102b7420f046cecdf9fa5715bf333d6dfb6bab6c382c7abc6b58241a50c216e9ab0b60d6fdb388f473d6b - languageName: node - linkType: hard - -"date-fns@npm:^2.30.0": - version: 2.30.0 - resolution: "date-fns@npm:2.30.0" +"date-fns-tz@npm:^3.0.0": + version: 3.0.0 + resolution: "date-fns-tz@npm:3.0.0" dependencies: - "@babel/runtime": "npm:^7.21.0" - checksum: 10/70b3e8ea7aaaaeaa2cd80bd889622a4bcb5d8028b4de9162cbcda359db06e16ff6e9309e54eead5341e71031818497f19aaf9839c87d1aba1e27bb4796e758a9 + lodash.clonedeep: "npm:^4.5.0" + peerDependencies: + date-fns: ^3.0.0 + checksum: 10/0a20196abd2519eb56bed0ba8fa838d60374db7bffa37d0d9284b29b6eed1b84369560d59688236479ed0bda923057fec2faef71caf09bc246d5f567c23308a8 languageName: node linkType: hard @@ -3219,8 +3203,8 @@ __metadata: bootstrap-vue-next: "npm:^0.16.6" core-js: "npm:^3.36.1" cypress: "npm:^13.7.2" - date-fns: "npm:^2.30.0" - date-fns-tz: "npm:^2.0.1" + date-fns: "npm:^3.6.0" + date-fns-tz: "npm:^3.0.0" echarts: "npm:^5.5.0" eslint: "npm:^8.57.0" eslint-plugin-prettier: "npm:^5.1.3" @@ -4061,6 +4045,13 @@ __metadata: languageName: node linkType: hard +"lodash.clonedeep@npm:^4.5.0": + version: 4.5.0 + resolution: "lodash.clonedeep@npm:4.5.0" + checksum: 10/957ed243f84ba6791d4992d5c222ffffca339a3b79dbe81d2eaf0c90504160b500641c5a0f56e27630030b18b8e971ea10b44f928a977d5ced3c8948841b555f + languageName: node + linkType: hard + "lodash.merge@npm:^4.6.2": version: 4.6.2 resolution: "lodash.merge@npm:4.6.2" @@ -4981,13 +4972,6 @@ __metadata: languageName: node linkType: hard -"regenerator-runtime@npm:^0.14.0": - version: 0.14.1 - resolution: "regenerator-runtime@npm:0.14.1" - checksum: 10/5db3161abb311eef8c45bcf6565f4f378f785900ed3945acf740a9888c792f75b98ecb77f0775f3bf95502ff423529d23e94f41d80c8256e8fa05ed4b07cf471 - languageName: node - linkType: hard - "request-progress@npm:^3.0.0": version: 3.0.0 resolution: "request-progress@npm:3.0.0"