11import  {  describe ,  test ,  expect ,  beforeEach ,  afterEach ,  vi  }  from  "vitest" ; 
2- import  {  calculateNextScheduledTimestamp  }  from  "../app/v3/utils/calculateNextSchedule.server" ; 
2+ import  {  calculateNextScheduledTimestampFromNow  }  from  "../app/v3/utils/calculateNextSchedule.server" ; 
33
4- describe ( "calculateNextScheduledTimestamp " ,  ( )  =>  { 
4+ describe ( "calculateNextScheduledTimestampFromNow " ,  ( )  =>  { 
55  beforeEach ( ( )  =>  { 
66    // Mock the current time to make tests deterministic 
77    vi . useFakeTimers ( ) ; 
@@ -16,7 +16,7 @@ describe("calculateNextScheduledTimestamp", () => {
1616    const  schedule  =  "0 * * * *" ;  // Every hour 
1717    const  lastRun  =  new  Date ( "2024-01-01T11:00:00.000Z" ) ;  // 1.5 hours ago 
1818
19-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   lastRun ) ; 
19+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
2020
2121    // Should be 13:00 (next hour after current time 12:30) 
2222    expect ( nextRun ) . toEqual ( new  Date ( "2024-01-01T13:00:00.000Z" ) ) ; 
@@ -26,7 +26,7 @@ describe("calculateNextScheduledTimestamp", () => {
2626    const  schedule  =  "0 * * * *" ;  // Every hour 
2727    const  lastRun  =  new  Date ( "2024-01-01T11:00:00.000Z" ) ; 
2828
29-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  "America/New_York" ,   lastRun ) ; 
29+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  "America/New_York" ) ; 
3030
3131    // The exact time will depend on timezone calculation, but should be in the future 
3232    expect ( nextRun ) . toBeInstanceOf ( Date ) ; 
@@ -38,7 +38,7 @@ describe("calculateNextScheduledTimestamp", () => {
3838    const  veryOldTimestamp  =  new  Date ( "2020-01-01T00:00:00.000Z" ) ;  // 4 years ago 
3939
4040    const  startTime  =  performance . now ( ) ; 
41-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   veryOldTimestamp ) ; 
41+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
4242    const  duration  =  performance . now ( )  -  startTime ; 
4343
4444    // Should complete quickly (under 10ms) instead of iterating millions of times 
@@ -55,7 +55,7 @@ describe("calculateNextScheduledTimestamp", () => {
5555    const  schedule  =  "0 */2 * * *" ;  // Every 2 hours 
5656    const  recentTimestamp  =  new  Date ( "2024-01-01T10:00:00.000Z" ) ;  // 2.5 hours ago 
5757
58-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   recentTimestamp ) ; 
58+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
5959
6060    // Should properly iterate: 10:00 -> 12:00 -> 14:00 (since current time is 12:30) 
6161    expect ( nextRun ) . toEqual ( new  Date ( "2024-01-01T14:00:00.000Z" ) ) ; 
@@ -66,7 +66,7 @@ describe("calculateNextScheduledTimestamp", () => {
6666    const  oldTimestamp  =  new  Date ( "2023-12-01T00:00:00.000Z" ) ;  // Over a month ago 
6767
6868    const  startTime  =  performance . now ( ) ; 
69-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   oldTimestamp ) ; 
69+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
7070    const  duration  =  performance . now ( )  -  startTime ; 
7171
7272    // Should be fast due to dynamic skip-ahead optimization 
@@ -80,7 +80,7 @@ describe("calculateNextScheduledTimestamp", () => {
8080    const  schedule  =  "0 9 * * MON" ;  // Every Monday at 9 AM 
8181    const  oldTimestamp  =  new  Date ( "2022-01-01T00:00:00.000Z" ) ;  // Very old (beyond 1hr threshold) 
8282
83-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   oldTimestamp ) ; 
83+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
8484
8585    // Should return a valid future Monday at 9 AM 
8686    expect ( nextRun . getHours ( ) ) . toBe ( 9 ) ; 
@@ -95,7 +95,7 @@ describe("calculateNextScheduledTimestamp", () => {
9595    const  extremelyOldTimestamp  =  new  Date ( "2000-01-01T00:00:00.000Z" ) ;  // 24 years ago 
9696
9797    const  startTime  =  performance . now ( ) ; 
98-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   extremelyOldTimestamp ) ; 
98+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
9999    const  duration  =  performance . now ( )  -  startTime ; 
100100
101101    // Should complete extremely quickly due to dynamic skip-ahead 
@@ -111,7 +111,7 @@ describe("calculateNextScheduledTimestamp", () => {
111111    const  oldTimestamp  =  new  Date ( "2023-12-31T12:31:00.000Z" ) ;  // 23h59m ago 
112112
113113    const  startTime  =  performance . now ( ) ; 
114-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   oldTimestamp ) ; 
114+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
115115    const  duration  =  performance . now ( )  -  startTime ; 
116116
117117    // Should be fast due to dynamic skip-ahead (1439 steps > 10 threshold) 
@@ -127,7 +127,7 @@ describe("calculateNextScheduledTimestamp", () => {
127127    const  recentTimestamp  =  new  Date ( "2024-01-01T12:00:00.000Z" ) ;  // 30 minutes ago (6 steps) 
128128
129129    const  startTime  =  performance . now ( ) ; 
130-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   recentTimestamp ) ; 
130+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
131131    const  duration  =  performance . now ( )  -  startTime ; 
132132
133133    // Should still be reasonably fast with normal iteration 
@@ -142,7 +142,7 @@ describe("calculateNextScheduledTimestamp", () => {
142142    const  oldTimestamp  =  new  Date ( "2023-12-25T09:00:00.000Z" ) ;  // Old Monday 
143143
144144    const  startTime  =  performance . now ( ) ; 
145-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   oldTimestamp ) ; 
145+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
146146    const  duration  =  performance . now ( )  -  startTime ; 
147147
148148    // Should be fast and still calculate correctly from the old timestamp 
@@ -160,7 +160,7 @@ describe("calculateNextScheduledTimestamp", () => {
160160    const  schedule  =  "0 14 * * SUN" ;  // Every Sunday at 2 PM 
161161    const  twoHoursAgo  =  new  Date ( "2024-01-01T10:30:00.000Z" ) ;  // 2 hours before current time (12:30) 
162162
163-     const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   twoHoursAgo ) ; 
163+     const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
164164
165165    // Should properly calculate the next Sunday at 2 PM, not skip to "now" 
166166    expect ( nextRun . getHours ( ) ) . toBe ( 14 ) ; 
@@ -170,7 +170,7 @@ describe("calculateNextScheduledTimestamp", () => {
170170  } ) ; 
171171} ) ; 
172172
173- describe ( "calculateNextScheduledTimestamp  - Fuzzy Testing" ,  ( )  =>  { 
173+ describe ( "calculateNextScheduledTimestampFromNow  - Fuzzy Testing" ,  ( )  =>  { 
174174  beforeEach ( ( )  =>  { 
175175    vi . useFakeTimers ( ) ; 
176176    vi . setSystemTime ( new  Date ( "2024-01-15T12:30:00.000Z" ) ) ;  // Monday, mid-day 
@@ -254,7 +254,7 @@ describe("calculateNextScheduledTimestamp - Fuzzy Testing", () => {
254254
255255      try  { 
256256        const  startTime  =  performance . now ( ) ; 
257-         const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  timezone ,   lastTimestamp ) ; 
257+         const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  timezone ) ; 
258258        const  duration  =  performance . now ( )  -  startTime ; 
259259
260260        // Invariant 1: Result should always be a valid Date 
@@ -270,7 +270,7 @@ describe("calculateNextScheduledTimestamp - Fuzzy Testing", () => {
270270        expect ( duration ) . toBeLessThan ( 100 ) ;  // Should complete within 100ms 
271271
272272        // Invariant 4: Function should be deterministic 
273-         const  nextRun2  =  calculateNextScheduledTimestamp ( schedule ,  timezone ,   lastTimestamp ) ; 
273+         const  nextRun2  =  calculateNextScheduledTimestampFromNow ( schedule ,  timezone ) ; 
274274        expect ( nextRun . getTime ( ) ) . toBe ( nextRun2 . getTime ( ) ) ; 
275275      }  catch  ( error )  { 
276276        // If there's an error, log the inputs for debugging 
@@ -292,7 +292,7 @@ describe("calculateNextScheduledTimestamp - Fuzzy Testing", () => {
292292      const  veryOldTimestamp  =  new  Date ( Date . now ( )  -  Math . random ( )  *  5  *  365  *  24  *  60  *  60  *  1000 ) ; 
293293
294294      const  startTime  =  performance . now ( ) ; 
295-       const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   veryOldTimestamp ) ; 
295+       const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
296296      const  duration  =  performance . now ( )  -  startTime ; 
297297
298298      // Should complete quickly even with very old timestamps 
@@ -321,7 +321,7 @@ describe("calculateNextScheduledTimestamp - Fuzzy Testing", () => {
321321
322322      const  lastTimestamp  =  new  Date ( Date . now ( )  -  Math . random ( )  *  7  *  24  *  60  *  60  *  1000 ) ; 
323323
324-       const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  timezone ,   lastTimestamp ) ; 
324+       const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  timezone ) ; 
325325
326326      // Should handle DST transitions gracefully 
327327      expect ( nextRun ) . toBeInstanceOf ( Date ) ; 
@@ -354,8 +354,8 @@ describe("calculateNextScheduledTimestamp - Fuzzy Testing", () => {
354354      const  beforeBoundary  =  new  Date ( Date . now ( )  -  1000 ) ; 
355355      const  afterBoundary  =  new  Date ( Date . now ( )  +  1000 ) ; 
356356
357-       const  nextRun1  =  calculateNextScheduledTimestamp ( test . schedule ,  null ,   beforeBoundary ) ; 
358-       const  nextRun2  =  calculateNextScheduledTimestamp ( test . schedule ,  null ,   afterBoundary ) ; 
357+       const  nextRun1  =  calculateNextScheduledTimestampFromNow ( test . schedule ,  null ) ; 
358+       const  nextRun2  =  calculateNextScheduledTimestampFromNow ( test . schedule ,  null ) ; 
359359
360360      expect ( nextRun1 . getTime ( ) ) . toBeGreaterThan ( Date . now ( ) ) ; 
361361      expect ( nextRun2 . getTime ( ) ) . toBeGreaterThan ( Date . now ( ) ) ; 
@@ -378,7 +378,7 @@ describe("calculateNextScheduledTimestamp - Fuzzy Testing", () => {
378378
379379      try  { 
380380        const  startTime  =  performance . now ( ) ; 
381-         const  nextRun  =  calculateNextScheduledTimestamp ( schedule ,  null ,   lastTimestamp ) ; 
381+         const  nextRun  =  calculateNextScheduledTimestampFromNow ( schedule ,  null ) ; 
382382        const  duration  =  performance . now ( )  -  startTime ; 
383383
384384        expect ( nextRun ) . toBeInstanceOf ( Date ) ; 
@@ -409,7 +409,7 @@ describe("calculateNextScheduledTimestamp - Fuzzy Testing", () => {
409409
410410      const  results : Date [ ]  =  [ ] ; 
411411      for  ( let  j  =  0 ;  j  <  5 ;  j ++ )  { 
412-         results . push ( calculateNextScheduledTimestamp ( schedule ,  timezone ,   lastTimestamp ) ) ; 
412+         results . push ( calculateNextScheduledTimestampFromNow ( schedule ,  timezone ) ) ; 
413413      } 
414414
415415      // All results should be identical 
@@ -436,7 +436,7 @@ describe("calculateNextScheduledTimestamp - Fuzzy Testing", () => {
436436      const  lastTimestamp  =  new  Date ( Date . now ( )  -  testCase . minutesAgo  *  60  *  1000 ) ; 
437437
438438      const  startTime  =  performance . now ( ) ; 
439-       const  nextRun  =  calculateNextScheduledTimestamp ( testCase . schedule ,  null ,   lastTimestamp ) ; 
439+       const  nextRun  =  calculateNextScheduledTimestampFromNow ( testCase . schedule ,  null ) ; 
440440      const  duration  =  performance . now ( )  -  startTime ; 
441441
442442      // All cases should complete quickly and return valid results 
0 commit comments