Refactor tooltip formatting into common file and switch to native js localization

This commit is contained in:
nymkappa
2021-12-11 17:10:55 +09:00
parent b924725ea2
commit be4c80b489
4 changed files with 34 additions and 58 deletions

View File

@@ -0,0 +1,28 @@
export const formatterXAxis = (
locale: string,
windowPreference: string,
value: string
) => {
if(value.length === 0){
return null;
}
const date = new Date(value);
switch (windowPreference) {
case '2h':
return date.toLocaleTimeString(locale, { hour: 'numeric', minute: 'numeric' });
case '24h':
return date.toLocaleTimeString(locale, { weekday: 'short', hour: 'numeric', minute: 'numeric' });
case '1w':
return date.toLocaleTimeString(locale, { month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' });
case '1m':
case '3m':
case '6m':
return date.toLocaleTimeString(locale, { month: 'short', day: 'numeric', hour: 'numeric' });
case '1y':
case '2y':
case '3y':
return date.toLocaleDateString(locale, { year: 'numeric', month: 'short', day: 'numeric' });
}
};