chore: roundTimeframe util

This commit is contained in:
Matthias 2024-07-05 14:16:49 +02:00
parent 8f73ae1071
commit df2dfd5f70
5 changed files with 14 additions and 14 deletions

12
src/auto-imports.d.ts vendored
View File

@ -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<typeof import('./stores/layout')['DashboardLayout']>
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly OpenTradeVizOptions: UnwrapRef<typeof import('./stores/settings')['OpenTradeVizOptions']>
readonly ROUND_CLOSER: UnwrapRef<typeof import('./utils/roundTimeframe')['ROUND_CLOSER']>
readonly ROUND_DOWN: UnwrapRef<typeof import('./utils/roundTimeframe')['ROUND_DOWN']>
readonly ROUND_UP: UnwrapRef<typeof import('./utils/roundTimeframe')['ROUND_UP']>
readonly TradeLayout: UnwrapRef<typeof import('./stores/layout')['TradeLayout']>
readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
@ -423,6 +430,7 @@ declare module 'vue' {
readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
readonly resolveRef: UnwrapRef<typeof import('@vueuse/core')['resolveRef']>
readonly resolveUnref: UnwrapRef<typeof import('@vueuse/core')['resolveUnref']>
readonly roundTimeframe: UnwrapRef<typeof import('./utils/roundTimeframe')['default']>
readonly setActivePinia: UnwrapRef<typeof import('pinia')['setActivePinia']>
readonly setMapStoreSuffix: UnwrapRef<typeof import('pinia')['setMapStoreSuffix']>
readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
@ -644,6 +652,9 @@ declare module '@vue/runtime-core' {
readonly DashboardLayout: UnwrapRef<typeof import('./stores/layout')['DashboardLayout']>
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly OpenTradeVizOptions: UnwrapRef<typeof import('./stores/settings')['OpenTradeVizOptions']>
readonly ROUND_CLOSER: UnwrapRef<typeof import('./utils/roundTimeframe')['ROUND_CLOSER']>
readonly ROUND_DOWN: UnwrapRef<typeof import('./utils/roundTimeframe')['ROUND_DOWN']>
readonly ROUND_UP: UnwrapRef<typeof import('./utils/roundTimeframe')['ROUND_UP']>
readonly TradeLayout: UnwrapRef<typeof import('./stores/layout')['TradeLayout']>
readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
@ -736,6 +747,7 @@ declare module '@vue/runtime-core' {
readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
readonly resolveRef: UnwrapRef<typeof import('@vueuse/core')['resolveRef']>
readonly resolveUnref: UnwrapRef<typeof import('@vueuse/core')['resolveUnref']>
readonly roundTimeframe: UnwrapRef<typeof import('./utils/roundTimeframe')['default']>
readonly setActivePinia: UnwrapRef<typeof import('pinia')['setActivePinia']>
readonly setMapStoreSuffix: UnwrapRef<typeof import('pinia')['setMapStoreSuffix']>
readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>

View File

@ -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';

View File

@ -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';

View File

@ -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,
};

View File

@ -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