2023-12-19 08:52:25 +00:00
|
|
|
import { Duration } from 'luxon';
|
2024-03-03 05:41:25 +00:00
|
|
|
import React, { ComponentPropsWithoutRef } from 'react';
|
|
|
|
import { cn } from 'utils/classnames';
|
2023-12-19 08:52:25 +00:00
|
|
|
|
2024-03-03 05:41:25 +00:00
|
|
|
export interface FormatMilliSecondProps
|
|
|
|
extends ComponentPropsWithoutRef<'div'> {
|
|
|
|
time: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const FormatMillisecond = ({ time, ...props }: FormatMilliSecondProps) => {
|
2023-12-19 08:52:25 +00:00
|
|
|
const formatTime = Duration.fromMillis(time)
|
|
|
|
.shiftTo('days', 'hours', 'minutes', 'seconds')
|
|
|
|
.toObject();
|
2023-12-19 10:24:15 +00:00
|
|
|
|
2023-12-19 08:52:25 +00:00
|
|
|
return (
|
2024-03-03 05:41:25 +00:00
|
|
|
<div
|
|
|
|
{...props}
|
|
|
|
className={cn('text-sm text-elements-mid-em', props?.className)}
|
|
|
|
>
|
2023-12-19 08:52:25 +00:00
|
|
|
{formatTime.days !== 0 && <span>{formatTime.days}d </span>}
|
|
|
|
{formatTime.hours !== 0 && <span>{formatTime.hours}h </span>}
|
|
|
|
{formatTime.minutes !== 0 && <span>{formatTime.minutes}m </span>}
|
|
|
|
<span>{formatTime.seconds}s</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FormatMillisecond;
|