Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): keep hourly runs on the right date at month end (#43925)

Juhyuk choicc4aaebc9797
diff --git a/web/app/components/workflow/nodes/trigger-schedule/utils/__tests__/hourly-month-end.spec.ts b/web/app/components/workflow/nodes/trigger-schedule/utils/__tests__/hourly-month-end.spec.ts
new file mode 100644
index 00000000000..de32311e2fc
--- /dev/null
+++ b/web/app/components/workflow/nodes/trigger-schedule/utils/__tests__/hourly-month-end.spec.ts
@@ -0,0 +1,37 @@
+import type { ScheduleTriggerNodeType } from '../../types'
+import { BlockEnum } from '../../../../types'
+import { getFormattedExecutionTimes, getNextExecutionTime } from '../execution-time-calculator'
+
+const createHourlyData = (): ScheduleTriggerNodeType =>
+ ({
+ type: BlockEnum.TriggerSchedule,
+ title: 'schedule',
+ mode: 'visual',
+ frequency: 'hourly',
+ timezone: 'Asia/Seoul',
+ visual_config: { on_minute: 0 },
+ }) as ScheduleTriggerNodeType
+
+describe('hourly runs across the end of a month', () => {
+ afterEach(() => {
+ vi.useRealTimers()
+ })
+
+ it('moves to the first day of the next month after midnight', () => {
+ vi.useFakeTimers()
+ vi.setSystemTime(new Date('2026-10-31T13:30:00Z'))
+
+ const times = getFormattedExecutionTimes(createHourlyData(), 3)
+
+ expect(times[0]).toMatch(/October 31, 2026, 11:00\sPM/)
+ expect(times[1]).toMatch(/November 1, 2026, 12:00\sAM/)
+ expect(times[2]).toMatch(/November 1, 2026, 1:00\sAM/)
+ })
+
+ it('moves to January 1 of the next year after New Year midnight', () => {
+ vi.useFakeTimers()
+ vi.setSystemTime(new Date('2026-12-31T14:30:00Z'))
+
+ expect(getNextExecutionTime(createHourlyData())).toMatch(/January 1, 2027, 12:00\sAM/)
+ })
+})
diff --git a/web/app/components/workflow/nodes/trigger-schedule/utils/execution-time-calculator.ts b/web/app/components/workflow/nodes/trigger-schedule/utils/execution-time-calculator.ts
index 29f1d6f0031..96a8e73c40b 100644
--- a/web/app/components/workflow/nodes/trigger-schedule/utils/execution-time-calculator.ts
+++ b/web/app/components/workflow/nodes/trigger-schedule/utils/execution-time-calculator.ts
@@ -121,12 +121,8 @@ export const getNextExecutionTimes = (data: ScheduleTriggerNodeType, count: numb
for (let i = 0; i < count; i++) {
const execution = new Date(userToday)
+ // setHours rolls past midnight into the next day, month and year on its own
execution.setHours(hour + i, onMinute, 0, 0)
- // Handle day overflow
- if (hour + i >= 24) {
- execution.setDate(userToday.getDate() + Math.floor((hour + i) / 24))
- execution.setHours((hour + i) % 24, onMinute, 0, 0)
- }
times.push(execution)
}
} else if (data.frequency === 'daily') {