File tree Expand file tree Collapse file tree 2 files changed +60
-2
lines changed
spring-modulith-moments/src/main/java/org/springframework/modulith/moments/support Expand file tree Collapse file tree 2 files changed +60
-2
lines changed Original file line number Diff line number Diff line change 43
43
*
44
44
* @author Oliver Drotbohm
45
45
*/
46
- public class Moments {
46
+ public class Moments implements Now {
47
47
48
48
private static final MonthDay DEC_31ST = MonthDay .of (Month .DECEMBER , 31 );
49
49
@@ -123,13 +123,27 @@ Moments shiftBy(Duration duration) {
123
123
return this ;
124
124
}
125
125
126
- LocalDateTime now () {
126
+ /*
127
+ * (non-Javadoc)
128
+ * @see org.springframework.modulith.moments.support.Now#now()
129
+ */
130
+ @ Override
131
+ public LocalDateTime now () {
127
132
128
133
Instant instant = clock .instant ().plus (shift );
129
134
130
135
return LocalDateTime .ofInstant (instant , properties .getZoneId ());
131
136
}
132
137
138
+ /*
139
+ * (non-Javadoc)
140
+ * @see org.springframework.modulith.moments.support.Now#today()
141
+ */
142
+ @ Override
143
+ public LocalDate today () {
144
+ return now ().toLocalDate ();
145
+ }
146
+
133
147
private void emitEventsFor (LocalDateTime time ) {
134
148
events .publishEvent (HourHasPassed .of (time .truncatedTo (ChronoUnit .HOURS )));
135
149
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2023 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ package org .springframework .modulith .moments .support ;
17
+
18
+ import java .time .LocalDate ;
19
+ import java .time .LocalDateTime ;
20
+
21
+ /**
22
+ * An abstraction of the current point in time and today. Useful if application code needs to look them up, but you need
23
+ * a mechanism to shift the time for testing local development purposes.
24
+ *
25
+ * @author Oliver Drotbohm
26
+ * @since 1.1
27
+ * @see TimeMachine
28
+ */
29
+ public interface Now {
30
+
31
+ /**
32
+ * Returns the current point in time.
33
+ *
34
+ * @return will never be {@literal null}.
35
+ */
36
+ LocalDateTime now ();
37
+
38
+ /**
39
+ * Returns the current date.
40
+ *
41
+ * @return will never be {@literal null}.
42
+ */
43
+ LocalDate today ();
44
+ }
You can’t perform that action at this time.
0 commit comments