dolphinscheduler icon indicating copy to clipboard operation
dolphinscheduler copied to clipboard

[Bug] Regarding the system parameter $[yyyyMMdd-1], when the system timezone is set to US West (America/Los_Angeles), there is a Daylight Saving Time (DST) transition issue where a day only has 23 hours.

Open Jack-Qin-King opened this issue 8 months ago • 8 comments

Search before asking

  • [x] I had searched in the issues and found no similar issues.

What happened

Regarding the system parameter $[yyyyMMdd+N], when the system timezone is set to US West (America/Los_Angeles), there is a Daylight Saving Time (DST) transition issue where a day only has 23 hours.

In the code, day-based addition and subtraction is implemented using minutes, specifically through the calcMinutes method. The code hardcodes the calculation as 6024(%s). However, for the US West (Los Angeles) timezone, Daylight Saving Time (DST) transitions occur, causing the second Sunday of March to jump from 01:59:59 to 03:00:00—effectively losing one hour and making that day only 23 hours long. As a result, $[yyyyMMdd-1] subtracts one extra hour, leading to a two-day offset issue.

代码里针对天的加减是按照分钟去实现的,具体方法为calcMinutes,代码里硬编码为60×24×(%s),固定为24小时(不合理),对于美西洛杉矶时区存在冬夏转换导致三月的第二个星期日 01:59:59 会调到03:00:00 因此少了一个小时 只有23小时问题,因此$[yyyyMMdd-1] 会被多减一个小时导致少俩天问题

here is my Test Case `// 启动前设置时区 TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // 方法1: 使用 java.time 包 (推荐,Java 8+) ZonedDateTime laDateTime = ZonedDateTime.of( 2026, 3, 9, // 年, 月, 日 0, 10, 0, // 时, 分, 秒 0, // 纳秒 ZoneId.of("America/Los_Angeles") // 洛杉矶时区 );

    // 转换为 Date 对象
    Date date = Date.from(laDateTime.toInstant());
    //System.out.println(TimePlaceholderUtils.getPlaceHolderTime("$[week_last_day(yyyy-MM-dd,0) - 1]", date));
    System.out.println(TimePlaceholderUtils.getPlaceHolderTime("yyyy-MM-dd-1", date));
    System.out.println(TimePlaceholderUtils.getPlaceHolderTime("yyyy-MM-dd", date));`

What you expected to happen

fix the bug ,期望 $[yyyyMMdd-1] 只会少一天

How to reproduce

` TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // 方法1: 使用 java.time 包 (推荐,Java 8+) ZonedDateTime laDateTime = ZonedDateTime.of( 2026, 3, 9, // 年, 月, 日 0, 10, 0, // 时, 分, 秒 0, // 纳秒 ZoneId.of("America/Los_Angeles") // 洛杉矶时区 );

    // 转换为 Date 对象
    Date date = Date.from(laDateTime.toInstant());
    //System.out.println(TimePlaceholderUtils.getPlaceHolderTime("$[week_last_day(yyyy-MM-dd,0) - 1]", date));
    System.out.println(TimePlaceholderUtils.getPlaceHolderTime("yyyy-MM-dd-1", date));
    System.out.println(TimePlaceholderUtils.getPlaceHolderTime("yyyy-MM-dd", date));`

Anything else

No response

Version

dev

Are you willing to submit PR?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

Jack-Qin-King avatar Mar 04 '26 07:03 Jack-Qin-King

Search before asking

  • [x] I had searched in the issues and found no similar issues.

What happened

Regarding the system parameter $[yyyyMMdd+N], when the system timezone is set to US West (America/Los_Angeles), there is a Daylight Saving Time (DST) transition issue where a day only has 23 hours.

In the code, day-based addition and subtraction is implemented using minutes, specifically through the calcMinutes method. The code hardcodes the calculation as 6024(%s). However, for the US West (Los Angeles) timezone, Daylight Saving Time (DST) transitions occur, causing the second Sunday of March to jump from 01:59:59 to 03:00:00—effectively losing one hour and making that day only 23 hours long. As a result, $[yyyyMMdd-1] subtracts one extra hour, leading to a two-day offset issue.

代码里针对天的加减是按照分钟去实现的,具体方法为calcMinutes,代码里硬编码为6024(%s),对于美西洛杉矶时区存在冬夏转换导致三月的第二个星期日 01:59:59 会调到03:00:00 因此少了一个小时 只有23小时问题,因此$[yyyyMMdd-1] 会被多减一个小时导致少俩天问题

here is my Test Case `// 启动前设置时区 TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // 方法1: 使用 java.time 包 (推荐,Java 8+) ZonedDateTime laDateTime = ZonedDateTime.of( 2026, 3, 9, // 年, 月, 日 0, 10, 0, // 时, 分, 秒 0, // 纳秒 ZoneId.of("America/Los_Angeles") // 洛杉矶时区 );

    // 转换为 Date 对象
    Date date = Date.from(laDateTime.toInstant());
    //System.out.println(TimePlaceholderUtils.getPlaceHolderTime("$[week_last_day(yyyy-MM-dd,0) - 1]", date));
    System.out.println(TimePlaceholderUtils.getPlaceHolderTime("yyyy-MM-dd-1", date));
    System.out.println(TimePlaceholderUtils.getPlaceHolderTime("yyyy-MM-dd", date));`

What you expected to happen

fix the bug ,期望 $[yyyyMMdd-1] 只会少一天

How to reproduce

` TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // 方法1: 使用 java.time 包 (推荐,Java 8+) ZonedDateTime laDateTime = ZonedDateTime.of( 2026, 3, 9, // 年, 月, 日 0, 10, 0, // 时, 分, 秒 0, // 纳秒 ZoneId.of("America/Los_Angeles") // 洛杉矶时区 );

    // 转换为 Date 对象
    Date date = Date.from(laDateTime.toInstant());
    //System.out.println(TimePlaceholderUtils.getPlaceHolderTime("$[week_last_day(yyyy-MM-dd,0) - 1]", date));
    System.out.println(TimePlaceholderUtils.getPlaceHolderTime("yyyy-MM-dd-1", date));
    System.out.println(TimePlaceholderUtils.getPlaceHolderTime("yyyy-MM-dd", date));`

Anything else

No response

Version

dev

Are you willing to submit PR?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

github-actions[bot] avatar Mar 04 '26 07:03 github-actions[bot]

Hey, I'd like to work on this issue. My approach will be to change the calculation so that the day offset is handled directly in days rather than converting it to minutes. I will also add a unit test case to verify that the fix works correctly.

Please let me know if this approach looks good. Thanks, Divyansh.

iampratap7997-dot avatar Mar 05 '26 07:03 iampratap7997-dot

handled directly in days is right

Jack-Qin-King avatar Mar 09 '26 02:03 Jack-Qin-King

i find other question use addDays also have problem,when schedul time is 2026-03-09 02:40:58 use addDay() will more 1 day become 2026-03-09 03:40:58

Image here is my test case ` TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // 方法1: 使用 java.time 包 (推荐,Java 8+) ZonedDateTime laDateTime = ZonedDateTime.of( 2026, 3, 9, // 年, 月, 日 2, 40, 58, // 时, 分, 秒 0, // 纳秒 ZoneId.of("America/Los_Angeles") // 洛杉矶时区 );
    // 转换为 Date 对象
    Date businessDate = Date.from(laDateTime.toInstant());

    businessDate = addDays(businessDate, -1);`

Jack-Qin-King avatar Mar 09 '26 10:03 Jack-Qin-King

i find other question use addDays also have problem,when schedul time is 2026-03-09 02:40:58 use addDay() will more 1 day become 2026-03-09 03:40:58

Image here is my test case ` TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); // 方法1: 使用 java.time 包 (推荐,Java 8+) ZonedDateTime laDateTime = ZonedDateTime.of( 2026, 3, 9, // 年, 月, 日 2, 40, 58, // 时, 分, 秒 0, // 纳秒 ZoneId.of("America/Los_Angeles") // 洛杉矶时区 );

    // 转换为 Date 对象
    Date businessDate = Date.from(laDateTime.toInstant());

    businessDate = addDays(businessDate, -1);`

Thanks for testing and pointing this out.

You are right that addDays() can still be affected by DST bcz internally it also works with time, which may cause the hour to shift during DST transitions.

Since the placeholders only require date-level calculation, I will update the implementation to use LocalDate based arithmetic instead of Date to avoid DST-related time shifts.

I will push an updated fix shortly.

iampratap7997-dot avatar Mar 09 '26 16:03 iampratap7997-dot

also i find BusinessTimeUtils has the problem ,because also use addDay method, so i think should repair the whole project where use the addDays method which from org.apache.commons.lang3.time.DateUtils `/*

  • Licensed to the Apache Software Foundation (ASF) under one or more
  • contributor license agreements. See the NOTICE file distributed with
  • this work for additional information regarding copyright ownership.
  • The ASF licenses this file to You under the Apache License, Version 2.0
  • (the "License"); you may not use this file except in compliance with
  • the License. You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. */

package org.apache.dolphinscheduler.common.utils.placeholder;

import static org.apache.commons.lang3.time.DateUtils.addDays; import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_FORMAT_DATE; import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_FORMAT_TIME; import static org.apache.dolphinscheduler.common.utils.DateUtils.format;

import org.apache.dolphinscheduler.common.constants.DateConstants; import org.apache.dolphinscheduler.common.enums.CommandType;

import java.util.Date; import java.util.HashMap; import java.util.Map;

/**

  • business time utils */ public class BusinessTimeUtils {

    private BusinessTimeUtils() { throw new IllegalStateException("BusinessTimeUtils class"); }

    /**

    • get business time in parameters by different command types
    • @param commandType command type
    • @param runTime run time or schedule time
    • @return business time / public static Map<String, String> getBusinessTime(CommandType commandType, Date runTime, String timezone) { Date businessDate = runTime; Map<String, String> result = new HashMap<>(); switch (commandType) { case COMPLEMENT_DATA: if (runTime == null) { return result; } case START_PROCESS: case START_CURRENT_TASK_PROCESS: case RECOVER_TOLERANCE_FAULT_PROCESS: case RECOVER_SUSPENDED_PROCESS: case START_FAILURE_TASK_PROCESS: case REPEAT_RUNNING: case DYNAMIC_GENERATION: case SCHEDULER: default: businessDate = addDays(new Date(), -1); if (runTime != null) { /* * If there is a scheduled time, take the scheduling time. Recovery from failed nodes, suspension of recovery, re-run for scheduling */ businessDate = addDays(runTime, -1); } break; } Date businessCurrentDate = addDays(businessDate, 1); result.put(DateConstants.PARAMETER_CURRENT_DATE, format(businessCurrentDate, PARAMETER_FORMAT_DATE, timezone)); result.put(DateConstants.PARAMETER_BUSINESS_DATE, format(businessDate, PARAMETER_FORMAT_DATE, timezone)); result.put(DateConstants.PARAMETER_DATETIME, format(businessCurrentDate, PARAMETER_FORMAT_TIME, timezone)); return result; } } `

Jack-Qin-King avatar Mar 10 '26 09:03 Jack-Qin-King

Thanks for pointing this out.

Let this PR focus only on fixing the $[yyyyMMdd±N] DST issue in TimePlaceholderUtils to keep the change minimal. What do you think about creating a new issue for this case? We can address it in a separate PR.

also i find BusinessTimeUtils has the problem ,because also use addDay method, so i think should repair the whole project where use the addDays method which from org.apache.commons.lang3.time.DateUtils `/*

  • Licensed to the Apache Software Foundation (ASF) under one or more
  • contributor license agreements. See the NOTICE file distributed with
  • this work for additional information regarding copyright ownership.
  • The ASF licenses this file to You under the Apache License, Version 2.0
  • (the "License"); you may not use this file except in compliance with
  • the License. You may obtain a copy of the License at
  • http://www.apache.org/licenses/LICENSE-2.0
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. */

package org.apache.dolphinscheduler.common.utils.placeholder;

import static org.apache.commons.lang3.time.DateUtils.addDays; import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_FORMAT_DATE; import static org.apache.dolphinscheduler.common.constants.DateConstants.PARAMETER_FORMAT_TIME; import static org.apache.dolphinscheduler.common.utils.DateUtils.format;

import org.apache.dolphinscheduler.common.constants.DateConstants; import org.apache.dolphinscheduler.common.enums.CommandType;

import java.util.Date; import java.util.HashMap; import java.util.Map;

/**

  • business time utils / public class BusinessTimeUtils { private BusinessTimeUtils() { throw new IllegalStateException("BusinessTimeUtils class"); } /*

    • get business time in parameters by different command types

    • @param commandType command type

    • @param runTime run time or schedule time

    • @return business time / public static Map<String, String> getBusinessTime(CommandType commandType, Date runTime, String timezone) { Date businessDate = runTime; Map<String, String> result = new HashMap<>(); switch (commandType) { case COMPLEMENT_DATA: if (runTime == null) { return result; } case START_PROCESS: case START_CURRENT_TASK_PROCESS: case RECOVER_TOLERANCE_FAULT_PROCESS: case RECOVER_SUSPENDED_PROCESS: case START_FAILURE_TASK_PROCESS: case REPEAT_RUNNING: case DYNAMIC_GENERATION: case SCHEDULER: default: businessDate = addDays(new Date(), -1); if (runTime != null) { /*

      • If there is a scheduled time, take the scheduling time. Recovery from failed nodes, suspension of recovery, re-run for scheduling */ businessDate = addDays(runTime, -1); } break; } Date businessCurrentDate = addDays(businessDate, 1); result.put(DateConstants.PARAMETER_CURRENT_DATE, format(businessCurrentDate, PARAMETER_FORMAT_DATE, timezone)); result.put(DateConstants.PARAMETER_BUSINESS_DATE, format(businessDate, PARAMETER_FORMAT_DATE, timezone)); result.put(DateConstants.PARAMETER_DATETIME, format(businessCurrentDate, PARAMETER_FORMAT_TIME, timezone)); return result; } } `

iampratap7997-dot avatar Mar 10 '26 14:03 iampratap7997-dot

ok

Jack-Qin-King avatar Mar 11 '26 09:03 Jack-Qin-King