diff --git a/src/auto-imports.d.ts b/src/auto-imports.d.ts index 22d4010e..3dd1613c 100644 --- a/src/auto-imports.d.ts +++ b/src/auto-imports.d.ts @@ -10,6 +10,9 @@ declare global { const EffectScope: typeof import('vue')['EffectScope'] const KeyCode: typeof import('./composables/inputListener')['KeyCode'] const OpenTradeVizOptions: typeof import('./stores/settings')['OpenTradeVizOptions'] + const ROUND_CLOSER: typeof import('./utils/roundTimeframe')['ROUND_CLOSER'] + const ROUND_DOWN: typeof import('./utils/roundTimeframe')['ROUND_DOWN'] + const ROUND_UP: typeof import('./utils/roundTimeframe')['ROUND_UP'] const TradeLayout: typeof import('./stores/layout')['TradeLayout'] const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate'] const asyncComputed: typeof import('@vueuse/core')['asyncComputed'] @@ -102,6 +105,7 @@ declare global { const resolveComponent: typeof import('vue')['resolveComponent'] const resolveRef: typeof import('@vueuse/core')['resolveRef'] const resolveUnref: typeof import('@vueuse/core')['resolveUnref'] + const roundTimeframe: typeof import('./utils/roundTimeframe')['default'] const setActivePinia: typeof import('pinia')['setActivePinia'] const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix'] const shallowReactive: typeof import('vue')['shallowReactive'] @@ -331,6 +335,9 @@ declare module 'vue' { readonly DashboardLayout: UnwrapRef readonly EffectScope: UnwrapRef readonly OpenTradeVizOptions: UnwrapRef + readonly ROUND_CLOSER: UnwrapRef + readonly ROUND_DOWN: UnwrapRef + readonly ROUND_UP: UnwrapRef readonly TradeLayout: UnwrapRef readonly acceptHMRUpdate: UnwrapRef readonly asyncComputed: UnwrapRef @@ -423,6 +430,7 @@ declare module 'vue' { readonly resolveComponent: UnwrapRef readonly resolveRef: UnwrapRef readonly resolveUnref: UnwrapRef + readonly roundTimeframe: UnwrapRef readonly setActivePinia: UnwrapRef readonly setMapStoreSuffix: UnwrapRef readonly shallowReactive: UnwrapRef @@ -644,6 +652,9 @@ declare module '@vue/runtime-core' { readonly DashboardLayout: UnwrapRef readonly EffectScope: UnwrapRef readonly OpenTradeVizOptions: UnwrapRef + readonly ROUND_CLOSER: UnwrapRef + readonly ROUND_DOWN: UnwrapRef + readonly ROUND_UP: UnwrapRef readonly TradeLayout: UnwrapRef readonly acceptHMRUpdate: UnwrapRef readonly asyncComputed: UnwrapRef @@ -736,6 +747,7 @@ declare module '@vue/runtime-core' { readonly resolveComponent: UnwrapRef readonly resolveRef: UnwrapRef readonly resolveUnref: UnwrapRef + readonly roundTimeframe: UnwrapRef readonly setActivePinia: UnwrapRef readonly setMapStoreSuffix: UnwrapRef readonly shallowReactive: UnwrapRef diff --git a/src/composables/percentageTool.ts b/src/composables/percentageTool.ts index e30179f4..4eb79c6d 100644 --- a/src/composables/percentageTool.ts +++ b/src/composables/percentageTool.ts @@ -1,5 +1,4 @@ import { ElementEvent } from 'echarts'; -import { ROUND_CLOSER, roundTimeframe } from '@/shared/timemath'; import humanizeDuration from 'humanize-duration'; import ECharts from 'vue-echarts'; diff --git a/src/shared/charts/tradeChartData.ts b/src/shared/charts/tradeChartData.ts index 78cac6d0..9312061c 100644 --- a/src/shared/charts/tradeChartData.ts +++ b/src/shared/charts/tradeChartData.ts @@ -1,5 +1,4 @@ import { formatPercent, formatPriceCurrency, splitTradePair } from '@/shared/formatters'; -import { roundTimeframe } from '@/shared/timemath'; import { Order, PairHistory, Trade, BTOrder } from '@/types'; import { ScatterSeriesOption } from 'echarts'; diff --git a/src/shared/timemath.ts b/src/utils/roundTimeframe.ts similarity index 75% rename from src/shared/timemath.ts rename to src/utils/roundTimeframe.ts index e0c9ad80..797c6d07 100644 --- a/src/shared/timemath.ts +++ b/src/utils/roundTimeframe.ts @@ -10,11 +10,7 @@ export const ROUND_CLOSER = 4; * @param direction Direction (see ROUND_* constants) * @returns timestamp in ms rounded to the timeframe */ -export function roundTimeframe( - timeframems: number, - timestamp: number, - direction: number = ROUND_DOWN, -) { +export default function (timeframems: number, timestamp: number, direction: number = ROUND_DOWN) { const offset = timestamp % timeframems; let up = direction === ROUND_UP; if (direction === ROUND_CLOSER) { @@ -22,9 +18,3 @@ export function roundTimeframe( } return timestamp - offset + (up ? timeframems : 0); } - -export default { - ROUND_UP, - ROUND_DOWN, - roundTimeframe, -}; diff --git a/tests/unit/timemath.spec.ts b/tests/unit/roundTimeframe.spec.ts similarity index 97% rename from tests/unit/timemath.spec.ts rename to tests/unit/roundTimeframe.spec.ts index bd322931..9a656e9c 100644 --- a/tests/unit/timemath.spec.ts +++ b/tests/unit/roundTimeframe.spec.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { roundTimeframe, ROUND_DOWN, ROUND_UP, ROUND_CLOSER } from '@/shared/timemath'; +import roundTimeframe, { ROUND_DOWN, ROUND_UP, ROUND_CLOSER } from '@/utils/roundTimeframe'; // 1651021200000 = 2022-04-27T11:05:00+00:00