1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00

refactor: Smart time range (#10881)

This commit is contained in:
Mateusz Kwasniewski 2025-10-28 17:26:12 +01:00 committed by GitHub
parent dc87c125e0
commit 0ddf35656c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,23 +1,25 @@
import { styled } from '@mui/material'; import { styled } from '@mui/material';
import HourglassEmptyOutlinedIcon from '@mui/icons-material/HourglassEmptyOutlined'; import HourglassEmptyOutlinedIcon from '@mui/icons-material/HourglassEmptyOutlined';
import type { IReleasePlanMilestone } from 'interfaces/releasePlans'; import type { IReleasePlanMilestone } from 'interfaces/releasePlans';
import { formatDateYMDHM } from 'utils/formatDate'; import { isToday, isTomorrow, format, addMinutes } from 'date-fns';
import { isToday, isTomorrow, format } from 'date-fns';
import { calculateMilestoneStartTime } from '../utils/calculateMilestoneStartTime.ts'; import { calculateMilestoneStartTime } from '../utils/calculateMilestoneStartTime.ts';
import { useUiFlag } from 'hooks/useUiFlag'; import { useUiFlag } from 'hooks/useUiFlag';
export const formatSmartDate = (date: Date): string => { export const formatSmartDate = (date: Date): string => {
const timeString = format(date, 'HH:mm'); const startTime = format(date, 'HH:mm');
const endTime = format(addMinutes(date, 2), 'HH:mm');
const timeRange = `between ${startTime} - ${endTime}`;
if (isToday(date)) { if (isToday(date)) {
return `today after ${timeString}`; return `today ${timeRange}`;
} }
if (isTomorrow(date)) { if (isTomorrow(date)) {
return `tomorrow after ${timeString}`; return `tomorrow ${timeRange}`;
} }
// For other dates, show full date with time // For other dates, show full date with time range
return formatDateYMDHM(date); const dateString = format(date, 'yyyy-MM-dd');
return `${dateString} ${timeRange}`;
}; };
const StyledTimeContainer = styled('span')(({ theme }) => ({ const StyledTimeContainer = styled('span')(({ theme }) => ({