Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dd99815

Browse files
Fix timezone conversion in datetime trigger parameters (#54593)
* onChange utc conversio bug * isValid * lint * revert & workaround * fix cmt lint * add back support for sec/ms --------- Co-authored-by: AhnSteve
1 parent 316ded5 commit dd99815

File tree

2 files changed

+10
-14
lines changed
  • airflow-core/src/airflow/ui/src/components
    • DateTimeInput.tsx
    • FlexibleForm
      • FieldDateTime.tsx

2 files changed

+10
-14
lines changed

airflow-core/src/airflow/ui/src/components/DateTimeInput.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ type Props = {
3232
export const DateTimeInput = forwardRef<HTMLInputElement, Props>(({ onChange, value, ...rest }, ref) => {
3333
const { selectedTimezone } = useTimezone();
3434

35-
// Make the value timezone-aware
36-
const date = dayjs(value).tz(selectedTimezone).format("YYYY-MM-DDTHH:mm:ss.SSS");
35+
// Convert UTC value to local time for display
36+
const displayValue =
37+
Boolean(value) && dayjs(value).isValid()
38+
? dayjs(value).tz(selectedTimezone).format("YYYY-MM-DDTHH:mm:ss.SSS")
39+
: "";
3740

3841
return (
3942
<Input
@@ -42,7 +45,6 @@ export const DateTimeInput = forwardRef(({ onChange, va
4245
...event,
4346
target: {
4447
...event.target,
45-
// Return a timezone-aware ISO string
4648
value: dayjs(event.target.value).isValid()
4749
? dayjs(event.target.value).tz(selectedTimezone, true).toISOString()
4850
: "",
@@ -51,7 +53,7 @@ export const DateTimeInput = forwardRef(({ onChange, va
5153
}
5254
ref={ref}
5355
type="datetime-local"
54-
value={date}
56+
value={displayValue}
5557
{...rest}
5658
/>
5759
);

airflow-core/src/airflow/ui/src/components/FlexibleForm/FieldDateTime.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@ export const FieldDateTime = ({
3232
const { disabled, paramsDict, setParamsDict } = useParamStore(namespace);
3333
const param = paramsDict[name] ?? paramPlaceholder;
3434
const handleChange = (value: string) => {
35+
// "undefined" values are removed from params, so we set it to null to avoid falling back to DAG defaults.
3536
if (paramsDict[name]) {
36-
if (rest.type === "datetime-local") {
37-
// "undefined" values are removed from params, so we set it to null to avoid falling back to DAG defaults.
38-
// eslint-disable-next-line unicorn/no-null
39-
paramsDict[name].value = value === "" ? null : `${value}:00+00:00`; // Need to suffix to make it UTC like
40-
} else {
41-
// "undefined" values are removed from params, so we set it to null to avoid falling back to DAG defaults.
42-
// eslint-disable-next-line unicorn/no-null
43-
paramsDict[name].value = value === "" ? null : value;
44-
}
37+
// eslint-disable-next-line unicorn/no-null
38+
paramsDict[name].value = value === "" ? null : value;
4539
}
4640

4741
setParamsDict(paramsDict);
@@ -56,7 +50,7 @@ export const FieldDateTime = ({
5650
name={`element_${name}`}
5751
onChange={(event) => handleChange(event.target.value)}
5852
size="sm"
59-
value={((param.value ?? "") as string).slice(0, 16)}
53+
value={(param.value as string) || ""}
6054
/>
6155
);
6256
}

0 commit comments

Comments
(0)