mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
1 parent
e810eab39f
commit
b7974827d2
786 files changed
+14567
-24066
No files matched your search
@@ -0,0 +1,24 @@
|
||||
// Formatting date duration in shorten format, e.g. "2d", or "25m"
|
||||
|
||||
import moment from "moment";
|
||||
|
||||
export function formatDuration(timeValue: number, compact: boolean) {
|
||||
let result = "";
|
||||
const duration = moment.duration(timeValue);
|
||||
const suffixes = ["d", "h", "m"];
|
||||
const durationValues = [
|
||||
Math.round(duration.asDays()),
|
||||
duration.hours(),
|
||||
duration.minutes(),
|
||||
];
|
||||
durationValues.forEach((value, index) => {
|
||||
if (value) result += value + suffixes[index] + " ";
|
||||
});
|
||||
if (compact) {
|
||||
result = result.split(" ")[0];
|
||||
}
|
||||
if (!result) {
|
||||
return "<1m";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user