Skip to content

Commit 36fdd36

Browse files
committed
store: make license date selection only allow for selecting the *day*, not the time
- actual time is all still EXACTLY AS BEFORE, it's just that the UI component normalizes the time to be from 12am on the start date to 11:59pm on the end date, in the browser's local timezone
1 parent 426e0e8 commit 36fdd36

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/packages/next/components/misc/date-range.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function DateRange(props: Props) {
2626
maxDaysInFuture,
2727
disabled = false,
2828
initialValues = [undefined, undefined],
29-
suffix
29+
suffix,
3030
} = props;
3131

3232
const [dateRange, setDateRange] = useState<DateRangeType>(initialValues);
@@ -66,7 +66,6 @@ export default function DateRange(props: Props) {
6666
<div style={style}>
6767
<DatePicker.RangePicker
6868
changeOnBlur
69-
showTime
7069
disabled={disabled}
7170
allowEmpty={[true, true]}
7271
renderExtraFooter={() => (
@@ -93,10 +92,18 @@ export default function DateRange(props: Props) {
9392
] as any
9493
}
9594
onChange={(value) => {
96-
const x: [Date0, Date0] = [
97-
value?.[0]?.toDate(),
98-
value?.[1]?.toDate(),
99-
];
95+
const now = dayjs();
96+
// Ensure start is the later of now or the start of the selected day
97+
const start = value?.[0]
98+
? dayjs(value[0]).isBefore(now)
99+
? now.toDate()
100+
: dayjs(value[0]).startOf("day").toDate()
101+
: undefined;
102+
// Set end of day, but only modify if there's a value
103+
const end = value?.[1]
104+
? dayjs(value[1]).endOf("day").subtract(1, "minute").toDate()
105+
: undefined;
106+
const x: [Date0, Date0] = [start, end];
100107
setDateRange(x);
101108
onChange?.(x);
102109
}}
@@ -116,9 +123,7 @@ export default function DateRange(props: Props) {
116123
: undefined
117124
}
118125
/>
119-
{suffix && (
120-
<span style={{marginLeft: '5px'}}>{suffix}</span>
121-
)}
126+
{suffix && <span style={{ marginLeft: "5px" }}>{suffix}</span>}
122127
</div>
123128
);
124129
}

src/packages/next/components/store/usage-and-duration.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function UsageAndDuration(props: Props) {
9595
range[1] = new Date(range[1]);
9696
}
9797
suffix =
98-
range && range[0] && `(${getTimezoneFromDate(range[0], "long")})`;
98+
range && range[0] && `(midnight to 11:59pm, ${getTimezoneFromDate(range[0], "long")})`;
9999
} catch (err) {
100100
invalidRange = true;
101101
console.warn(`WARNING: issue parsing date ${range[0]}`);

0 commit comments

Comments
 (0)