mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import Duration from 'sentry/components/duration';
|
|
import {defined} from 'sentry/utils';
|
|
|
|
interface DurationProps {
|
|
abbreviation?: boolean;
|
|
}
|
|
|
|
interface SecondsProps extends DurationProps {
|
|
seconds: number;
|
|
}
|
|
|
|
interface MillisecondsProps extends DurationProps {
|
|
milliseconds: number;
|
|
}
|
|
|
|
interface NanosecondsProps extends DurationProps {
|
|
nanoseconds: number;
|
|
}
|
|
|
|
type PerformanceDurationProps = SecondsProps | MillisecondsProps | NanosecondsProps;
|
|
|
|
function isMilliseconds(props: PerformanceDurationProps): props is MillisecondsProps {
|
|
return defined((props as MillisecondsProps).milliseconds);
|
|
}
|
|
|
|
function isNanoseconds(props: PerformanceDurationProps): props is NanosecondsProps {
|
|
return defined((props as NanosecondsProps).nanoseconds);
|
|
}
|
|
|
|
function PerformanceDuration(props: PerformanceDurationProps) {
|
|
const normalizedSeconds = isNanoseconds(props)
|
|
? props.nanoseconds / 1_000_000_000
|
|
: isMilliseconds(props)
|
|
? props.milliseconds / 1000
|
|
: props.seconds;
|
|
|
|
return (
|
|
<Duration
|
|
abbreviation={props.abbreviation}
|
|
seconds={normalizedSeconds}
|
|
fixedDigits={2}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default PerformanceDuration;
|