Skip to content

Commit 78e3a56

Browse files
matt-aitkenericallam
authored andcommitted
The DateField now defaults to local time, but can be overriden to use utc with an option
1 parent f97d55e commit 78e3a56

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

apps/webapp/app/components/primitives/DateField.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,12 @@ type DateFieldProps = {
3535
showNowButton?: boolean;
3636
showClearButton?: boolean;
3737
onValueChange?: (value: Date | undefined) => void;
38+
utc?: boolean;
3839
variant?: Variant;
3940
};
4041

42+
const deviceTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
43+
4144
export function DateField({
4245
label,
4346
defaultValue,
@@ -50,23 +53,23 @@ export function DateField({
5053
showGuide = false,
5154
showNowButton = false,
5255
showClearButton = false,
56+
utc = false,
5357
variant = "small",
5458
}: DateFieldProps) {
5559
const [value, setValue] = useState<undefined | CalendarDateTime>(
56-
dateToCalendarDate(defaultValue)
60+
utc ? utcDateToCalendarDate(defaultValue) : dateToCalendarDate(defaultValue)
5761
);
5862

5963
const state = useDateFieldState({
6064
value: value,
6165
onChange: (value) => {
6266
if (value) {
6367
setValue(value);
64-
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
65-
onValueChange?.(value.toDate(timeZone));
68+
onValueChange?.(value.toDate(utc ? "utc" : deviceTimezone));
6669
}
6770
},
68-
minValue: dateToCalendarDate(minValue),
69-
maxValue: dateToCalendarDate(maxValue),
71+
minValue: utc ? utcDateToCalendarDate(minValue) : dateToCalendarDate(minValue),
72+
maxValue: utc ? utcDateToCalendarDate(maxValue) : dateToCalendarDate(maxValue),
7073
shouldForceLeadingZeros: true,
7174
granularity,
7275
locale: "en-US",
@@ -79,7 +82,9 @@ export function DateField({
7982
useEffect(() => {
8083
if (state.value === undefined && defaultValue === undefined) return;
8184

82-
const calendarDate = dateToCalendarDate(defaultValue);
85+
const calendarDate = utc
86+
? utcDateToCalendarDate(defaultValue)
87+
: dateToCalendarDate(defaultValue);
8388
//unchanged
8489
if (state.value?.toDate("utc").getTime() === defaultValue?.getTime()) {
8590
return;
@@ -137,7 +142,7 @@ export function DateField({
137142
variant={variants[variant].nowButtonVariant}
138143
onClick={() => {
139144
const now = new Date();
140-
setValue(dateToCalendarDate(new Date()));
145+
setValue(utc ? utcDateToCalendarDate(now) : dateToCalendarDate(now));
141146
onValueChange?.(now);
142147
}}
143148
>

apps/webapp/app/components/runs/TimeFrameFilter.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export function AbsoluteTimeFrame({
214214
granularity="second"
215215
showNowButton
216216
showClearButton
217+
utc
217218
/>
218219
</div>
219220
<div className="space-y-1">
@@ -227,6 +228,7 @@ export function AbsoluteTimeFrame({
227228
granularity="second"
228229
showNowButton
229230
showClearButton
231+
utc
230232
/>
231233
</div>
232234
</div>

apps/webapp/app/components/runs/v3/BatchFilters.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,13 @@ function AppliedCustomDateRangeFilter() {
768768
<>
769769
{rangeType === "range" ? (
770770
<span>
771-
<DateTime date={fromDate!} includeTime includeSeconds showTimezone />{" "}
772-
<DateTime date={toDate!} includeTime includeSeconds showTimezone />
771+
<DateTime date={fromDate!} includeTime includeSeconds />{" "}
772+
<DateTime date={toDate!} includeTime includeSeconds />
773773
</span>
774774
) : rangeType === "from" ? (
775-
<DateTime date={fromDate!} includeTime includeSeconds showTimezone />
775+
<DateTime date={fromDate!} includeTime includeSeconds />
776776
) : (
777-
<DateTime date={toDate!} includeTime includeSeconds showTimezone />
777+
<DateTime date={toDate!} includeTime includeSeconds />
778778
)}
779779
</>
780780
}

apps/webapp/app/components/runs/v3/RunFilters.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,13 +1106,13 @@ function AppliedCustomDateRangeFilter() {
11061106
<>
11071107
{rangeType === "range" ? (
11081108
<span>
1109-
<DateTime date={fromDate!} includeTime includeSeconds showTimezone />{" "}
1110-
<DateTime date={toDate!} includeTime includeSeconds showTimezone />
1109+
<DateTime date={fromDate!} includeTime includeSeconds />{" "}
1110+
<DateTime date={toDate!} includeTime includeSeconds />
11111111
</span>
11121112
) : rangeType === "from" ? (
1113-
<DateTime date={fromDate!} includeTime includeSeconds showTimezone />
1113+
<DateTime date={fromDate!} includeTime includeSeconds />
11141114
) : (
1115-
<DateTime date={toDate!} includeTime includeSeconds showTimezone />
1115+
<DateTime date={toDate!} includeTime includeSeconds />
11161116
)}
11171117
</>
11181118
}

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.test.tasks.$taskParam/route.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ function ScheduledTaskForm({
412412
granularity="second"
413413
showNowButton
414414
variant="medium"
415+
utc
415416
/>
416417
<Hint>
417418
This is the timestamp of the CRON, it will come through to your run in the
@@ -436,6 +437,7 @@ function ScheduledTaskForm({
436437
showNowButton
437438
showClearButton
438439
variant="medium"
440+
utc
439441
/>
440442
<Hint>
441443
This is the timestamp of the previous run. You can use this in your code to find

0 commit comments

Comments
 (0)