Skip to content

[Fix-18015] [DST ISSUE] Handle DST issue when calculating yyyyMMdd±N time placeholders#18026

Open
iampratap7997-dot wants to merge 7 commits intoapache:devfrom
iampratap7997-dot:fix-dst-time-placeholder
Open

[Fix-18015] [DST ISSUE] Handle DST issue when calculating yyyyMMdd±N time placeholders#18026
iampratap7997-dot wants to merge 7 commits intoapache:devfrom
iampratap7997-dot:fix-dst-time-placeholder

Conversation

@iampratap7997-dot
Copy link
Contributor

@iampratap7997-dot iampratap7997-dot commented Mar 6, 2026

Was this PR generated or assisted by AI?

NO (Only the manual test case for America(Los_Angeles) timezone was created by AI to verify the fix.)

Purpose of the pull request

Fixes #18015 DST issue when calculating $[yyyyMMdd±N] time placeholders.
Day-based calculations were previously implemented in minutes, which caused incorrect dates during Daylight Saving Time transitions.

Brief change log

1- Replaced minute-based day calculations with addDays for expressions like yyyyMMdd+N & yyyyMMdd-N.
2- Ensures correct date calculation in timezones with DST (e.g., America/Los_Angeles).

Verify this pull request

  • The fix was manually verified using America/Los_Angeles timezone around DST transition.
  • Unit tests cover existing placeholders (no new tests added, logic change only).

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

Date targetDate = addMinutes(date, calcMinutes(addMinuteExpr));
if (index + 1 < expression.length() && Character.isDigit(expression.charAt(index + 1))) {
String addDayExpr = expression.substring(index + 1);
int days = Integer.parseInt(addDayExpr);

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException

Potential uncaught 'java.lang.NumberFormatException'.
Date targetDate = addMinutes(date, 0 - calcMinutes(addMinuteExpr));
if (index + 1 < expression.length() && Character.isDigit(expression.charAt(index + 1))) {
String addDayExpr = expression.substring(index + 1);
int days = Integer.parseInt(addDayExpr);

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException

Potential uncaught 'java.lang.NumberFormatException'.
@iampratap7997-dot
Copy link
Contributor Author

iampratap7997-dot commented Mar 7, 2026

HI maintainers,
Please add the milestone label for this PR .

Thanks,
Divyansh.

@iampratap7997-dot
Copy link
Contributor Author

iampratap7997-dot commented Mar 10, 2026

Hi ,

I've fixed the DST issue occurring in the recent test case and also addressed the Copilot issues.
@jieguangzhou Could you please re-run the tests?

Thanks,
Divyansh

@SbloodyS SbloodyS requested a review from Copilot March 16, 2026 02:14
@SbloodyS SbloodyS added the bug Something isn't working label Mar 16, 2026
@SbloodyS SbloodyS added this to the 3.4.2 milestone Mar 16, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix DST-related date drift when evaluating day-based time placeholders like $[yyyyMMdd±N] by switching from minute-based offsets to calendar-day arithmetic.

Changes:

  • Replaces minute-based “day” adjustments in calcMinutes(String, Date) with LocalDate.plusDays/minusDays using the system timezone.
  • Simplifies this_day(...) calculation to return the provided date directly.
  • Updates imports to support the new java.time-based implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@@ -18,8 +18,6 @@
package org.apache.dolphinscheduler.plugin.task.api.parser;

import static org.apache.commons.lang3.time.DateUtils.addWeeks;
Comment on lines 648 to +659
public static Map.Entry<Date, String> calcMinutes(String expression, Date date) {
if (expression.contains("+")) {
int index = expression.lastIndexOf('+');

if (Character.isDigit(expression.charAt(index + 1))) {
String addMinuteExpr = expression.substring(index + 1);
Date targetDate = addMinutes(date, calcMinutes(addMinuteExpr));
if (index + 1 < expression.length() && Character.isDigit(expression.charAt(index + 1))) {
String addDayExpr = expression.substring(index + 1);
int days;
try {
days = Integer.parseInt(addDayExpr);
} catch (NumberFormatException e) {
return null;
}
iampratap7997-dot and others added 2 commits March 16, 2026 20:06
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working

Projects

None yet

3 participants