Skip to content

Commit 79d4de2

Browse files
committed
Don't remove millisecond precision when rescheduling events
1 parent bd5e254 commit 79d4de2

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

packages/snaps-controllers/src/cronjob/CronjobController.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,7 @@ export class CronjobController extends BaseController<
545545
* the controller state.
546546
*/
547547
#reschedule(events = Object.values(this.state.events)) {
548-
const now = DateTime.fromJSDate(new Date())
549-
.toUTC()
550-
.startOf('second')
551-
.toSeconds();
548+
const now = Date.now();
552549

553550
for (const event of events) {
554551
if (this.#timers.has(event.id)) {
@@ -557,10 +554,11 @@ export class CronjobController extends BaseController<
557554
continue;
558555
}
559556

560-
const eventDate = DateTime.fromISO(event.date)
557+
const eventDate = DateTime.fromISO(event.date, {
558+
setZone: true,
559+
})
561560
.toUTC()
562-
.startOf('second')
563-
.toSeconds();
561+
.toMillis();
564562

565563
// If the event is recurring and the date is in the past, execute it
566564
// immediately.
@@ -576,16 +574,14 @@ export class CronjobController extends BaseController<
576574
* Clear non-recurring events that are past their scheduled time.
577575
*/
578576
#clear() {
579-
const now = DateTime.fromJSDate(new Date())
580-
.toUTC()
581-
.startOf('second')
582-
.toSeconds();
577+
const now = Date.now();
583578

584579
for (const event of Object.values(this.state.events)) {
585-
const eventDate = DateTime.fromISO(event.date)
580+
const eventDate = DateTime.fromISO(event.date, {
581+
setZone: true,
582+
})
586583
.toUTC()
587-
.startOf('second')
588-
.toSeconds();
584+
.toMillis();
589585

590586
if (!event.recurring && eventDate < now) {
591587
this.#cancel(event.id);

0 commit comments

Comments
 (0)