Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions apps/sim/lib/workflows/schedules/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,27 +421,20 @@ describe('Schedule Utilities', () => {
})

describe('parseCronToHumanReadable', () => {
it.concurrent('should parse common cron patterns using cronstrue', () => {
// cronstrue produces "Every minute" for '* * * * *'
it.concurrent('should describe the schedules the builder generates', () => {
expect(parseCronToHumanReadable('* * * * *')).toBe('Every minute')

// cronstrue produces "Every 15 minutes" for '*/15 * * * *'
expect(parseCronToHumanReadable('*/15 * * * *')).toBe('Every 15 minutes')
expect(parseCronToHumanReadable('1 * * * *')).toBe('At 1 minute past the hour')
expect(parseCronToHumanReadable('30 * * * *')).toBe('At 30 minutes past the hour')
expect(parseCronToHumanReadable('0 9 * * *')).toBe('At 9:00 AM')
expect(parseCronToHumanReadable('30 14 * * *')).toBe('At 2:30 PM')
expect(parseCronToHumanReadable('0 9 * * 1')).toBe('At 9:00 AM, only on Monday')
expect(parseCronToHumanReadable('30 14 15 * *')).toBe('At 2:30 PM, on day 15 of the month')
})

// cronstrue produces "At 30 minutes past the hour" for '30 * * * *'
expect(parseCronToHumanReadable('30 * * * *')).toContain('30 minutes past the hour')

// cronstrue produces "At 9:00 AM" for '0 9 * * *' (no leading zero on hour)
expect(parseCronToHumanReadable('0 9 * * *')).toContain('9:00 AM')

// cronstrue produces "At 2:30 PM" for '30 14 * * *' (no leading zero on hour)
expect(parseCronToHumanReadable('30 14 * * *')).toContain('2:30 PM')

// cronstrue produces "At 09:00 AM, only on Monday" for '0 9 * * 1'
expect(parseCronToHumanReadable('0 9 * * 1')).toContain('Monday')

// cronstrue produces "At 02:30 PM, on day 15 of the month" for '30 14 15 * *'
expect(parseCronToHumanReadable('30 14 15 * *')).toContain('15')
it.concurrent('should describe step schedules in custom cron expressions', () => {
expect(parseCronToHumanReadable('0 */2 * * *')).toBe('On the hour, every 2 hours')
expect(parseCronToHumanReadable('0 0 */2 * *')).toBe('At 12:00 AM, every 2 days in a month')
})

it.concurrent('should describe the nth weekday of the month', () => {
Expand Down
11 changes: 5 additions & 6 deletions apps/sim/lib/workflows/schedules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,12 +450,11 @@ export function calculateNextRunTime(
export const parseCronToHumanReadable = (cronExpression: string, timezone?: string): string => {
try {
const forDisplay = cronExpression.replace(/([0-7])#L\b/g, '$1L')
const baseDescription = cronstrue
.toString(forDisplay, {
use24HourTimeFormat: false,
verbose: false,
})
.replace(/\b0(\d:\d{2})/g, '$1')
const baseDescription = cronstrue.toString(forDisplay, {
use24HourTimeFormat: false,
trimHoursLeadingZero: true,
verbose: false,
})

if (timezone && timezone !== 'UTC') {
const tzAbbr = getTimezoneAbbreviation(timezone)
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
"class-variance-authority": "^0.7.1",
"cmdk": "^1.0.0",
"croner": "^9.0.0",
"cronstrue": "3.3.0",
"cronstrue": "3.38.0",
"csv-parse": "7.0.3",
"date-fns": "4.4.0",
"decimal.js": "10.6.0",
Expand Down
4 changes: 2 additions & 2 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading