[PR #24673] fix(schedule): add time logic to weekly frequency mode for consistent behavior with daily mode #30743

Closed
opened 2026-02-21 20:48:08 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/24673

State: closed
Merged: Yes


Summary

Fixed a logical inconsistency in the weekly schedule trigger where the algorithm would always skip to the next week regardless of whether the configured time has passed today. This PR builds upon PR #24641 and adds time comparison logic to make weekly frequency mode behave consistently with daily mode.

Problem

The weekly frequency mode had a critical flaw where it would force execution to skip to the next week even when the configured time hasn't passed today:

  • Today is Wednesday 10:00 AM, schedule set for every Wednesday 2:00 PM → Would incorrectly schedule for next Wednesday
  • This violated user expectations and was inconsistent with daily mode behavior

Root Cause

In execution-time-calculator.ts, the weekly logic used:

const adjustedDays = daysUntilTarget === 0 ? 7 : daysUntilTarget

This forced a 7-day skip when today matches the target weekday, completely ignoring the configured time.

Solution

Added time comparison logic consistent with daily mode:

// Check if today's configured time has already passed
const todayAtTargetTime = new Date(userToday)
todayAtTargetTime.setHours(displayHour, Number.parseInt(minute), 0, 0)

let adjustedDays = daysUntilTarget
if (daysUntilTarget === 0 && todayAtTargetTime <= userCurrentTime) {
  adjustedDays = 7
}

Impact

  • Weekly mode now respects time like daily mode
  • Improves user experience and meets expectations
  • Maintains backward compatibility
  • Zero performance impact (O(1) time complexity increase)
  • Comprehensive test coverage with 41 new test cases

Related

Related to PR #24641 which fixed weekday calculation but didn't address time logic.

Screenshots

Before After
Wednesday 10:00 AM + Weekly Wednesday 2:00 PM → Next Wednesday Wednesday 10:00 AM + Weekly Wednesday 2:00 PM → Today Wednesday
Wednesday 4:00 PM + Weekly Wednesday 2:00 PM → Next Wednesday Wednesday 4:00 PM + Weekly Wednesday 2:00 PM → Next Wednesday

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/24673 **State:** closed **Merged:** Yes --- ## Summary Fixed a logical inconsistency in the weekly schedule trigger where the algorithm would always skip to the next week regardless of whether the configured time has passed today. This PR builds upon PR #24641 and adds time comparison logic to make weekly frequency mode behave consistently with daily mode. ### Problem The weekly frequency mode had a critical flaw where it would force execution to skip to the next week even when the configured time hasn't passed today: - Today is Wednesday 10:00 AM, schedule set for every Wednesday 2:00 PM → Would incorrectly schedule for next Wednesday - This violated user expectations and was inconsistent with daily mode behavior ### Root Cause In `execution-time-calculator.ts`, the weekly logic used: ```typescript const adjustedDays = daysUntilTarget === 0 ? 7 : daysUntilTarget ``` This forced a 7-day skip when today matches the target weekday, completely ignoring the configured time. ### Solution Added time comparison logic consistent with daily mode: ```typescript // Check if today's configured time has already passed const todayAtTargetTime = new Date(userToday) todayAtTargetTime.setHours(displayHour, Number.parseInt(minute), 0, 0) let adjustedDays = daysUntilTarget if (daysUntilTarget === 0 && todayAtTargetTime <= userCurrentTime) { adjustedDays = 7 } ``` ### Impact - ✅ Weekly mode now respects time like daily mode - ✅ Improves user experience and meets expectations - ✅ Maintains backward compatibility - ✅ Zero performance impact (O(1) time complexity increase) - ✅ Comprehensive test coverage with 41 new test cases ### Related Related to PR #24641 which fixed weekday calculation but didn't address time logic. ## Screenshots | Before | After | |--------|-------| | Wednesday 10:00 AM + Weekly Wednesday 2:00 PM → **Next Wednesday** ❌ | Wednesday 10:00 AM + Weekly Wednesday 2:00 PM → **Today Wednesday** ✅ | | Wednesday 4:00 PM + Weekly Wednesday 2:00 PM → **Next Wednesday** ✅ | Wednesday 4:00 PM + Weekly Wednesday 2:00 PM → **Next Wednesday** ✅ | ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:48:08 -05:00
yindo closed this issue 2026-02-21 20:48:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30743