Skip to content

Commit

Permalink
formatBucketRange: fix second format for when multplier is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
zbigg committed Sep 27, 2023
1 parent 6eb675f commit d987c26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('timeFormat', () => {
stepMultiplier: 1,
date: '2022-09-13T13:00:00',
stepSize: GroupDateTypes.SECONDS,
expected: '9/13/2022 01:00:00 PM'
expected: '9/13/2022 01:00:00 PM - 01:00:00 PM'
},
{
title: 'two seconds',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ export function formatTime({ date, stepSize }) {
return formatter(date);
}

const SHORTENED_RANGES_WHEN_NO_MULTIPLIES = [GroupDateTypes.SECONDS, GroupDateTypes.DAYS];

/**
* Format time range.
*
Expand Down Expand Up @@ -71,12 +69,16 @@ export function formatBucketRange({ date, stepSize, stepMultiplier }) {

const { start, end } = getBucketInterval({ date, stepSize, stepMultiplier });

if (
stepMultiplier === 1 &&
stepSize &&
SHORTENED_RANGES_WHEN_NO_MULTIPLIES.includes(stepSize)
) {
return formatTime({ date: start, stepSize });
// exceptions/shorthands
if (stepMultiplier === 1) {
if (stepSize === GroupDateTypes.DAYS) {
return formatTime({ date: start, stepSize });
}
if (stepSize === GroupDateTypes.SECONDS) {
return `${formatLocalDate(start)} ${formatTimeWithSeconds(
start
)} - ${formatTimeWithSeconds(end)}`;
}
}

return formatTimeRange({ start, end, stepSize });
Expand Down

0 comments on commit d987c26

Please sign in to comment.