Fix date formatting bug
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
export const formatNumber = (amt: number, precision: number) => {
|
export const formatNumber = (amt: number, precision: number) => {
|
||||||
if (precision < 3) { precision = 3; }
|
if (precision < 3) { precision = 3; }
|
||||||
if (amt >= 1e6) {
|
if (amt >= 1e6) {
|
||||||
return (amt/1e6).toPrecision(precision) + "M";
|
return (amt / 1e6).toPrecision(precision) + "M";
|
||||||
} else if (amt >= 1e3) {
|
} else if (amt >= 1e3) {
|
||||||
return (amt/1e3).toPrecision(precision) + "k";
|
return (amt / 1e3).toPrecision(precision) + "k";
|
||||||
}
|
}
|
||||||
return amt.toPrecision(precision)
|
return amt.toPrecision(precision)
|
||||||
}
|
}
|
||||||
@@ -14,55 +14,55 @@ export const formatThousands = (amt: number) => {
|
|||||||
|
|
||||||
export const formatDataVolume = (amt: number, precision: number) => {
|
export const formatDataVolume = (amt: number, precision: number) => {
|
||||||
if (precision < 3) { precision = 3; }
|
if (precision < 3) { precision = 3; }
|
||||||
if (amt >= 1e18-1e15) {
|
if (amt >= 1e18 - 1e15) {
|
||||||
return (amt/1e18).toPrecision(precision) + " EB";
|
return (amt / 1e18).toPrecision(precision) + " EB";
|
||||||
}else if (amt >= 1e15-1e12) {
|
} else if (amt >= 1e15 - 1e12) {
|
||||||
return (amt/1e15).toPrecision(precision) + " PB";
|
return (amt / 1e15).toPrecision(precision) + " PB";
|
||||||
}else if (amt >= 1e12-1e9) {
|
} else if (amt >= 1e12 - 1e9) {
|
||||||
return (amt/1e12).toPrecision(precision) + " TB";
|
return (amt / 1e12).toPrecision(precision) + " TB";
|
||||||
} else if (amt >= 1e9-1e6) {
|
} else if (amt >= 1e9 - 1e6) {
|
||||||
return (amt/1e9).toPrecision(precision) + " GB";
|
return (amt / 1e9).toPrecision(precision) + " GB";
|
||||||
} else if (amt >= 1e6-1e3) {
|
} else if (amt >= 1e6 - 1e3) {
|
||||||
return (amt/1e6).toPrecision(precision) + " MB";
|
return (amt / 1e6).toPrecision(precision) + " MB";
|
||||||
} else if (amt >= 1e3-1) {
|
} else if (amt >= 1e3 - 1) {
|
||||||
return (amt/1e3).toPrecision(precision) + " kB";
|
return (amt / 1e3).toPrecision(precision) + " kB";
|
||||||
}
|
}
|
||||||
return amt.toPrecision(precision) + " B"
|
return amt.toPrecision(precision) + " B"
|
||||||
}
|
}
|
||||||
export const formatDataVolumeBits = (amt: number, precision: number) => {
|
export const formatDataVolumeBits = (amt: number, precision: number) => {
|
||||||
amt = amt*8
|
amt = amt * 8
|
||||||
if (precision < 3) { precision = 3; }
|
if (precision < 3) { precision = 3; }
|
||||||
if (amt >= 1e18-1e15) {
|
if (amt >= 1e18 - 1e15) {
|
||||||
return (amt/1e18).toPrecision(precision) + " Eb";
|
return (amt / 1e18).toPrecision(precision) + " Eb";
|
||||||
}else if (amt >= 1e15-1e12) {
|
} else if (amt >= 1e15 - 1e12) {
|
||||||
return (amt/1e15).toPrecision(precision) + " Pb";
|
return (amt / 1e15).toPrecision(precision) + " Pb";
|
||||||
}else if (amt >= 1e12-1e9) {
|
} else if (amt >= 1e12 - 1e9) {
|
||||||
return (amt/1e12).toPrecision(precision) + " Tb";
|
return (amt / 1e12).toPrecision(precision) + " Tb";
|
||||||
} else if (amt >= 1e9-1e6) {
|
} else if (amt >= 1e9 - 1e6) {
|
||||||
return (amt/1e9).toPrecision(precision) + " Gb";
|
return (amt / 1e9).toPrecision(precision) + " Gb";
|
||||||
} else if (amt >= 1e6-1e3) {
|
} else if (amt >= 1e6 - 1e3) {
|
||||||
return (amt/1e6).toPrecision(precision) + " Mb";
|
return (amt / 1e6).toPrecision(precision) + " Mb";
|
||||||
} else if (amt >= 1e3-1) {
|
} else if (amt >= 1e3 - 1) {
|
||||||
return (amt/1e3).toPrecision(precision) + " kb";
|
return (amt / 1e3).toPrecision(precision) + " kb";
|
||||||
}
|
}
|
||||||
return amt + " b"
|
return amt + " b"
|
||||||
}
|
}
|
||||||
|
|
||||||
const second = 1000
|
const second = 1000
|
||||||
const minute = second*60
|
const minute = second * 60
|
||||||
const hour = minute*60
|
const hour = minute * 60
|
||||||
const day = hour*24
|
const day = hour * 24
|
||||||
|
|
||||||
export const formatDuration = (ms: number, decimals: number) => {
|
export const formatDuration = (ms: number, decimals: number) => {
|
||||||
let res = ""
|
let res = ""
|
||||||
if (ms >= day) { res += Math.floor(ms/day) + "d " }
|
if (ms >= day) { res += Math.floor(ms / day) + "d " }
|
||||||
if (ms >= hour) { res += Math.floor((ms%day)/hour) + "h " }
|
if (ms >= hour) { res += Math.floor((ms % day) / hour) + "h " }
|
||||||
if (ms >= minute) { res += Math.floor((ms%hour)/minute) + "m " }
|
if (ms >= minute) { res += Math.floor((ms % hour) / minute) + "m " }
|
||||||
return res + ((ms%minute)/second).toFixed(decimals) + "s"
|
return res + ((ms % minute) / second).toFixed(decimals) + "s"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const formatDate = (
|
export const formatDate = (
|
||||||
date: Date|string,
|
date: Date | string,
|
||||||
hours: boolean = true,
|
hours: boolean = true,
|
||||||
minutes: boolean = true,
|
minutes: boolean = true,
|
||||||
seconds: boolean = true,
|
seconds: boolean = true,
|
||||||
@@ -72,15 +72,15 @@ export const formatDate = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
let dateStr = date.getFullYear()
|
let dateStr = date.getFullYear()
|
||||||
+"-"+("00"+(date.getMonth()+1)).slice(-2)
|
+ "-" + ("00" + (date.getMonth() + 1)).slice(-2)
|
||||||
+"-"+("00"+date.getDate()).slice(-2)
|
+ "-" + ("00" + date.getDate()).slice(-2)
|
||||||
|
|
||||||
if (hours) { dateStr += " "+("00"+date.getHours()).slice(-2) }
|
if (hours) { dateStr += " " + ("00" + date.getHours()).slice(-2) }
|
||||||
if (minutes) { dateStr += ":"+("00"+date.getMinutes()).slice(-2) }
|
if (minutes) { dateStr += ":" + ("00" + date.getMinutes()).slice(-2) }
|
||||||
if (seconds) { dateStr += ":"+("00"+date.getMinutes()).slice(-2) }
|
if (seconds) { dateStr += ":" + ("00" + date.getSeconds()).slice(-2) }
|
||||||
return dateStr
|
return dateStr
|
||||||
}
|
}
|
||||||
|
|
||||||
export const formatEuros = (amt: number, precision: number) => {
|
export const formatEuros = (amt: number, precision: number) => {
|
||||||
return "€ "+ (amt / 1000000).toFixed(precision)
|
return "€ " + (amt / 1000000).toFixed(precision)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user