kafka-ui/kafka-ui-react-app/src/lib/dateTimeHelpers.ts
Hrant Abrahamyan eb03a12233
Format dates in a single place, Display build date instead of full commit hash in version info (#2590)
* message

* if tag contains -SNAPSHOT - display formatted timestamp

* create Time format context

* fix pull request commits

* change pull request commits

* add fetchTimeFormat function

* add fetchTimeFormat function

* chnage test run

* fix testing error

* covered global context with tests

* removed unused import statement

* fixed smell

* pull master

* fixed code smeils

* covered Version component, hooks with tests, fixed code review comments

* converted outdated to boolean

* remove tag condition from return
2022-09-28 14:23:16 +03:00

34 lines
686 B
TypeScript

import dayjs from 'dayjs';
export const formatTimestamp = (
timestamp: number | string | Date | undefined,
format?: string
): string => {
if (!timestamp) {
return '';
}
return dayjs(timestamp).format(format);
};
export const formatMilliseconds = (input = 0) => {
const milliseconds = Math.max(input || 0, 0);
const seconds = Math.floor(milliseconds / 1000);
const minutes = Math.floor(seconds / 60);
const hours = Math.floor(minutes / 60);
if (hours > 0) {
return `${hours}h ${minutes % 60}m`;
}
if (minutes > 0) {
return `${minutes}m ${seconds % 60}s`;
}
if (seconds > 0) {
return `${seconds}s`;
}
return `${milliseconds}ms`;
};