Browse Source

Use TriggerContext's Clock instead of new Date()

Closes gh-27546
pull/27555/head
Juergen Hoeller 3 years ago
parent
commit
e4934a90eb
  1. 6
      spring-context/src/main/java/org/springframework/scheduling/support/CronTrigger.java

6
spring-context/src/main/java/org/springframework/scheduling/support/CronTrigger.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -105,11 +105,11 @@ public class CronTrigger implements Trigger {
} }
} }
else { else {
date = new Date(); date = new Date(triggerContext.getClock().millis());
} }
ZonedDateTime dateTime = ZonedDateTime.ofInstant(date.toInstant(), this.zoneId); ZonedDateTime dateTime = ZonedDateTime.ofInstant(date.toInstant(), this.zoneId);
ZonedDateTime next = this.expression.next(dateTime); ZonedDateTime next = this.expression.next(dateTime);
return next != null ? Date.from(next.toInstant()) : null; return (next != null ? Date.from(next.toInstant()) : null);
} }

Loading…
Cancel
Save