Skip to content

fix: Validate date after duration offset - #4124

Merged
FrederikBolding merged 1 commit into
mainfrom
fb/validate-date-after-duration-add
Sep 18, 2026
Merged

FrederikBolding merged 1 commit into
mainfrom
fb/validate-date-after-duration-add

Conversation

@FrederikBolding

@FrederikBolding FrederikBolding commented Sep 17, 2026

Copy link
Copy Markdown
Member

Cronjob execution dates configured using durations can technically overflow and cause unexpected behaviour. We can catch this by asserting isValid.


Note

Low Risk
Small change to cron schedule parsing with clearer errors on edge-case durations; no auth or data-path changes.

Overview
Cronjob scheduling now rejects ISO 8601 durations that produce an invalid execution time after adding them to “now”, instead of returning a bad date.

Duration handling in getExecutionDate is folded into the same try/catch as cron parsing. After DateTime.now().plus(validatedDuration), an assert(offsetDate.isValid) runs so overflow cases (e.g. P1000000Y) fail with the existing “Unable to parse …” error. A test covers that extreme duration.

Reviewed by Cursor Bugbot for commit 13cd74c. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.59%. Comparing base (2c8a299) to head (13cd74c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4124   +/-   ##
=======================================
  Coverage   98.59%   98.59%           
=======================================
  Files         429      429           
  Lines       12495    12497    +2     
  Branches     1976     1976           
=======================================
+ Hits        12320    12322    +2     
  Misses        175      175           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

if (duration.isValid) {
// This ensures the duration is at least 1 second.
const validatedDuration = getDuration(duration);
const offsetDate = DateTime.now().toUTC().plus(validatedDuration);

@MajorLift MajorLift Sep 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think about triggering a type error as well with something like:

 import { DateTime, Duration } from 'luxon';
+import type { DateTimeMaybeValid } from 'luxon';

+/**
+ * Add a duration to the current time. The sum may fall outside the
+ * representable date range, so the result may be invalid.
+ *
+ * @param duration - The duration to add.
+ * @returns The resulting date, which may be invalid.
+ */
+function getOffsetDate(duration: Duration<true>): DateTimeMaybeValid {
+  return DateTime.now().toUTC().plus(duration);
+}
+
 /**
  * Get the next execution date from a schedule, which should be either:

-      const offsetDate = DateTime.now().toUTC().plus(validatedDuration);
+      const offsetDate = getOffsetDate(validatedDuration);

@FrederikBolding
FrederikBolding marked this pull request as ready for review September 18, 2026 07:41
@FrederikBolding
FrederikBolding requested a review from a team as a code owner September 18, 2026 07:41
@FrederikBolding FrederikBolding changed the title fix: Validate date after duration math fix: Validate date after duration offset Sep 18, 2026
@FrederikBolding
FrederikBolding added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit 7e3d201 Sep 18, 2026
134 checks passed
@FrederikBolding
FrederikBolding deleted the fb/validate-date-after-duration-add branch September 18, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants