0
# Schedule Builders
1
2
Fluent builders for creating different types of schedules in Quartz. Schedule builders provide type-safe, readable ways to configure trigger schedules including simple intervals, cron expressions, calendar-based intervals, and daily time intervals.
3
4
## Capabilities
5
6
### ScheduleBuilder Base Class
7
8
Abstract base class for all schedule builders providing common structure.
9
10
```java { .api }
11
/**
12
* Base class for all schedule builders
13
*/
14
abstract class ScheduleBuilder<T extends Trigger> {
15
/**
16
* Build the trigger instance with this schedule
17
* @return configured trigger instance
18
*/
19
protected abstract MutableTrigger build();
20
}
21
```
22
23
### SimpleScheduleBuilder Class
24
25
Builder for simple interval-based schedules with regular repetition patterns.
26
27
```java { .api }
28
/**
29
* Builder for SimpleTrigger schedules with interval-based repetition
30
*/
31
class SimpleScheduleBuilder extends ScheduleBuilder<SimpleTrigger> {
32
/**
33
* Create a simple schedule builder
34
* @return new builder instance
35
*/
36
static SimpleScheduleBuilder simpleSchedule();
37
38
/**
39
* Create builder for repeating every minute forever
40
* @return configured builder
41
*/
42
static SimpleScheduleBuilder repeatMinutelyForever();
43
44
/**
45
* Create builder for repeating every N minutes forever
46
* @param minutes interval in minutes
47
* @return configured builder
48
*/
49
static SimpleScheduleBuilder repeatMinutelyForever(int minutes);
50
51
/**
52
* Create builder for repeating every second forever
53
* @return configured builder
54
*/
55
static SimpleScheduleBuilder repeatSecondlyForever();
56
57
/**
58
* Create builder for repeating every N seconds forever
59
* @param seconds interval in seconds
60
* @return configured builder
61
*/
62
static SimpleScheduleBuilder repeatSecondlyForever(int seconds);
63
64
/**
65
* Create builder for repeating every hour forever
66
* @return configured builder
67
*/
68
static SimpleScheduleBuilder repeatHourlyForever();
69
70
/**
71
* Create builder for repeating every N hours forever
72
* @param hours interval in hours
73
* @return configured builder
74
*/
75
static SimpleScheduleBuilder repeatHourlyForever(int hours);
76
77
/**
78
* Set the repeat interval in milliseconds
79
* @param intervalInMillis interval in milliseconds
80
* @return this builder for method chaining
81
*/
82
SimpleScheduleBuilder withIntervalInMilliseconds(long intervalInMillis);
83
84
/**
85
* Set the repeat interval in seconds
86
* @param intervalInSeconds interval in seconds
87
* @return this builder for method chaining
88
*/
89
SimpleScheduleBuilder withIntervalInSeconds(int intervalInSeconds);
90
91
/**
92
* Set the repeat interval in minutes
93
* @param intervalInMinutes interval in minutes
94
* @return this builder for method chaining
95
*/
96
SimpleScheduleBuilder withIntervalInMinutes(int intervalInMinutes);
97
98
/**
99
* Set the repeat interval in hours
100
* @param intervalInHours interval in hours
101
* @return this builder for method chaining
102
*/
103
SimpleScheduleBuilder withIntervalInHours(int intervalInHours);
104
105
/**
106
* Set the number of times to repeat (0 = fire once)
107
* @param triggerRepeatCount number of repeats
108
* @return this builder for method chaining
109
*/
110
SimpleScheduleBuilder withRepeatCount(int triggerRepeatCount);
111
112
/**
113
* Repeat forever (until end time or trigger removal)
114
* @return this builder for method chaining
115
*/
116
SimpleScheduleBuilder repeatForever();
117
118
/**
119
* Set misfire instruction to ignore misfires
120
* @return this builder for method chaining
121
*/
122
SimpleScheduleBuilder withMisfireHandlingInstructionIgnoreMisfires();
123
124
/**
125
* Set misfire instruction to fire trigger immediately when misfire is detected
126
* @return this builder for method chaining
127
*/
128
SimpleScheduleBuilder withMisfireHandlingInstructionFireNow();
129
130
/**
131
* Set misfire instruction to reschedule with existing repeat count
132
* @return this builder for method chaining
133
*/
134
SimpleScheduleBuilder withMisfireHandlingInstructionNowWithExistingCount();
135
136
/**
137
* Set misfire instruction to reschedule with remaining repeat count
138
* @return this builder for method chaining
139
*/
140
SimpleScheduleBuilder withMisfireHandlingInstructionNowWithRemainingCount();
141
142
/**
143
* Set misfire instruction to reschedule at next scheduled time with existing count
144
* @return this builder for method chaining
145
*/
146
SimpleScheduleBuilder withMisfireHandlingInstructionNextWithExistingCount();
147
148
/**
149
* Set misfire instruction to reschedule at next scheduled time with remaining count
150
* @return this builder for method chaining
151
*/
152
SimpleScheduleBuilder withMisfireHandlingInstructionNextWithRemainingCount();
153
}
154
```
155
156
**Usage Examples:**
157
158
```java
159
// Basic simple schedules
160
Trigger everyMinute = newTrigger()
161
.withSchedule(repeatMinutelyForever())
162
.build();
163
164
Trigger every30Seconds = newTrigger()
165
.withSchedule(repeatSecondlyForever(30))
166
.build();
167
168
Trigger every2Hours = newTrigger()
169
.withSchedule(repeatHourlyForever(2))
170
.build();
171
172
// Custom intervals
173
Trigger customInterval = newTrigger()
174
.withSchedule(simpleSchedule()
175
.withIntervalInMilliseconds(45000) // 45 seconds
176
.withRepeatCount(10) // Fire 11 times total
177
.withMisfireHandlingInstructionFireNow())
178
.build();
179
180
// Limited repetition
181
Trigger limitedRepeats = newTrigger()
182
.withSchedule(simpleSchedule()
183
.withIntervalInMinutes(15)
184
.withRepeatCount(5) // Fire 6 times total (initial + 5 repeats)
185
.withMisfireHandlingInstructionNextWithRemainingCount())
186
.build();
187
188
// One-time execution
189
Trigger oneTime = newTrigger()
190
.withSchedule(simpleSchedule()
191
.withRepeatCount(0)) // Fire only once
192
.build();
193
194
// Static imports for cleaner syntax
195
import static org.quartz.SimpleScheduleBuilder.*;
196
197
Trigger clean = newTrigger()
198
.withSchedule(repeatMinutelyForever(5))
199
.build();
200
```
201
202
### CronScheduleBuilder Class
203
204
Builder for cron expression-based schedules supporting complex time patterns.
205
206
```java { .api }
207
/**
208
* Builder for CronTrigger schedules using cron expressions
209
*/
210
class CronScheduleBuilder extends ScheduleBuilder<CronTrigger> {
211
/**
212
* Create a cron schedule from expression string
213
* @param cronExpression the cron expression
214
* @return new builder instance
215
* @throws ParseException if cron expression is invalid
216
*/
217
static CronScheduleBuilder cronSchedule(String cronExpression);
218
219
/**
220
* Create a cron schedule from CronExpression object
221
* @param cronExpression the cron expression object
222
* @return new builder instance
223
*/
224
static CronScheduleBuilder cronSchedule(CronExpression cronExpression);
225
226
/**
227
* Create schedule for daily execution at specific hour and minute
228
* @param hour hour of day (0-23)
229
* @param minute minute of hour (0-59)
230
* @return configured builder for daily execution
231
*/
232
static CronScheduleBuilder dailyAtHourAndMinute(int hour, int minute);
233
234
/**
235
* Create schedule for weekly execution on specific day, hour, and minute
236
* @param dayOfWeek day of week (1=Sunday, 7=Saturday)
237
* @param hour hour of day (0-23)
238
* @param minute minute of hour (0-59)
239
* @return configured builder for weekly execution
240
*/
241
static CronScheduleBuilder weeklyOnDayAndHourAndMinute(int dayOfWeek, int hour, int minute);
242
243
/**
244
* Create schedule for monthly execution on specific day, hour, and minute
245
* @param dayOfMonth day of month (1-31)
246
* @param hour hour of day (0-23)
247
* @param minute minute of hour (0-59)
248
* @return configured builder for monthly execution
249
*/
250
static CronScheduleBuilder monthlyOnDayAndHourAndMinute(int dayOfMonth, int hour, int minute);
251
252
/**
253
* Set the time zone for cron expression evaluation
254
* @param timezone the time zone
255
* @return this builder for method chaining
256
*/
257
CronScheduleBuilder inTimeZone(TimeZone timezone);
258
259
/**
260
* Set misfire instruction to ignore misfires
261
* @return this builder for method chaining
262
*/
263
CronScheduleBuilder withMisfireHandlingInstructionIgnoreMisfires();
264
265
/**
266
* Set misfire instruction to fire once when misfire is detected
267
* @return this builder for method chaining
268
*/
269
CronScheduleBuilder withMisfireHandlingInstructionFireAndProceed();
270
271
/**
272
* Set misfire instruction to do nothing on misfire
273
* @return this builder for method chaining
274
*/
275
CronScheduleBuilder withMisfireHandlingInstructionDoNothing();
276
}
277
```
278
279
**Usage Examples:**
280
281
```java
282
// Basic cron schedules
283
Trigger dailyAt9AM = newTrigger()
284
.withSchedule(cronSchedule("0 0 9 * * ?"))
285
.build();
286
287
Trigger everyWeekday9AM = newTrigger()
288
.withSchedule(cronSchedule("0 0 9 ? * MON-FRI"))
289
.build();
290
291
Trigger every15Minutes = newTrigger()
292
.withSchedule(cronSchedule("0 */15 * * * ?"))
293
.build();
294
295
// Using convenience methods
296
Trigger dailyNoon = newTrigger()
297
.withSchedule(dailyAtHourAndMinute(12, 0))
298
.build();
299
300
Trigger mondayMorning = newTrigger()
301
.withSchedule(weeklyOnDayAndHourAndMinute(2, 9, 30)) // Monday 9:30 AM
302
.build();
303
304
Trigger monthlyFirst = newTrigger()
305
.withSchedule(monthlyOnDayAndHourAndMinute(1, 0, 0)) // 1st of month midnight
306
.build();
307
308
// With timezone and misfire handling
309
Trigger cronWithTimezone = newTrigger()
310
.withSchedule(cronSchedule("0 0 12 * * ?")
311
.inTimeZone(TimeZone.getTimeZone("America/New_York"))
312
.withMisfireHandlingInstructionFireAndProceed())
313
.build();
314
315
// Complex cron expressions
316
Trigger businessHours = newTrigger()
317
.withSchedule(cronSchedule("0 */30 9-17 ? * MON-FRI")) // Every 30 min, 9-5, weekdays
318
.build();
319
320
Trigger quarterlyReport = newTrigger()
321
.withSchedule(cronSchedule("0 0 9 1 1,4,7,10 ?")) // 9 AM on Jan 1, Apr 1, Jul 1, Oct 1
322
.build();
323
324
// Static imports for cleaner syntax
325
import static org.quartz.CronScheduleBuilder.*;
326
327
Trigger clean = newTrigger()
328
.withSchedule(dailyAtHourAndMinute(14, 30))
329
.build();
330
```
331
332
### CalendarIntervalScheduleBuilder Class
333
334
Builder for calendar-based interval schedules that respect calendar boundaries.
335
336
```java { .api }
337
/**
338
* Builder for CalendarIntervalTrigger schedules with calendar-aware intervals
339
*/
340
class CalendarIntervalScheduleBuilder extends ScheduleBuilder<CalendarIntervalTrigger> {
341
/**
342
* Create a calendar interval schedule builder
343
* @return new builder instance
344
*/
345
static CalendarIntervalScheduleBuilder calendarIntervalSchedule();
346
347
/**
348
* Set the interval for the schedule
349
* @param interval the interval value
350
* @param unit the interval unit (SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR)
351
* @return this builder for method chaining
352
*/
353
CalendarIntervalScheduleBuilder withInterval(int interval, DateBuilder.IntervalUnit unit);
354
355
/**
356
* Set interval in seconds
357
* @param intervalInSeconds interval in seconds
358
* @return this builder for method chaining
359
*/
360
CalendarIntervalScheduleBuilder withIntervalInSeconds(int intervalInSeconds);
361
362
/**
363
* Set interval in minutes
364
* @param intervalInMinutes interval in minutes
365
* @return this builder for method chaining
366
*/
367
CalendarIntervalScheduleBuilder withIntervalInMinutes(int intervalInMinutes);
368
369
/**
370
* Set interval in hours
371
* @param intervalInHours interval in hours
372
* @return this builder for method chaining
373
*/
374
CalendarIntervalScheduleBuilder withIntervalInHours(int intervalInHours);
375
376
/**
377
* Set interval in days
378
* @param intervalInDays interval in days
379
* @return this builder for method chaining
380
*/
381
CalendarIntervalScheduleBuilder withIntervalInDays(int intervalInDays);
382
383
/**
384
* Set interval in weeks
385
* @param intervalInWeeks interval in weeks
386
* @return this builder for method chaining
387
*/
388
CalendarIntervalScheduleBuilder withIntervalInWeeks(int intervalInWeeks);
389
390
/**
391
* Set interval in months
392
* @param intervalInMonths interval in months
393
* @return this builder for method chaining
394
*/
395
CalendarIntervalScheduleBuilder withIntervalInMonths(int intervalInMonths);
396
397
/**
398
* Set interval in years
399
* @param intervalInYears interval in years
400
* @return this builder for method chaining
401
*/
402
CalendarIntervalScheduleBuilder withIntervalInYears(int intervalInYears);
403
404
/**
405
* Preserve hour of day across daylight saving time changes
406
* @param preserveHourOfDayAcrossDaylightSavings true to preserve hour
407
* @return this builder for method chaining
408
*/
409
CalendarIntervalScheduleBuilder preserveHourOfDayAcrossDaylightSavings(boolean preserveHourOfDayAcrossDaylightSavings);
410
411
/**
412
* Skip day if hour does not exist due to daylight saving time
413
* @param skipDayIfHourDoesNotExist true to skip day
414
* @return this builder for method chaining
415
*/
416
CalendarIntervalScheduleBuilder skipDayIfHourDoesNotExist(boolean skipDayIfHourDoesNotExist);
417
418
/**
419
* Set the time zone for calendar calculations
420
* @param timezone the time zone
421
* @return this builder for method chaining
422
*/
423
CalendarIntervalScheduleBuilder inTimeZone(TimeZone timezone);
424
425
/**
426
* Set misfire instruction to ignore misfires
427
* @return this builder for method chaining
428
*/
429
CalendarIntervalScheduleBuilder withMisfireHandlingInstructionIgnoreMisfires();
430
431
/**
432
* Set misfire instruction to fire once when misfire is detected
433
* @return this builder for method chaining
434
*/
435
CalendarIntervalScheduleBuilder withMisfireHandlingInstructionFireAndProceed();
436
437
/**
438
* Set misfire instruction to do nothing on misfire
439
* @return this builder for method chaining
440
*/
441
CalendarIntervalScheduleBuilder withMisfireHandlingInstructionDoNothing();
442
}
443
```
444
445
**Usage Examples:**
446
447
```java
448
// Basic calendar intervals
449
Trigger daily = newTrigger()
450
.withSchedule(calendarIntervalSchedule()
451
.withIntervalInDays(1))
452
.build();
453
454
Trigger weekly = newTrigger()
455
.withSchedule(calendarIntervalSchedule()
456
.withIntervalInWeeks(1))
457
.build();
458
459
Trigger monthly = newTrigger()
460
.withSchedule(calendarIntervalSchedule()
461
.withIntervalInMonths(1))
462
.build();
463
464
// Calendar-aware scheduling with DST handling
465
Trigger dstAware = newTrigger()
466
.withSchedule(calendarIntervalSchedule()
467
.withIntervalInDays(1)
468
.preserveHourOfDayAcrossDaylightSavings(true)
469
.skipDayIfHourDoesNotExist(true)
470
.inTimeZone(TimeZone.getTimeZone("America/New_York")))
471
.build();
472
473
// Quarterly reports (every 3 months)
474
Trigger quarterly = newTrigger()
475
.withSchedule(calendarIntervalSchedule()
476
.withInterval(3, DateBuilder.IntervalUnit.MONTH)
477
.withMisfireHandlingInstructionFireAndProceed())
478
.build();
479
480
// Business day intervals (every weekday)
481
Trigger businessDaily = newTrigger()
482
.withSchedule(calendarIntervalSchedule()
483
.withIntervalInDays(1))
484
.modifiedByCalendar("businessDaysOnly") // Requires business day calendar
485
.build();
486
487
// Static imports for cleaner syntax
488
import static org.quartz.CalendarIntervalScheduleBuilder.*;
489
490
Trigger clean = newTrigger()
491
.withSchedule(calendarIntervalSchedule().withIntervalInDays(7))
492
.build();
493
```
494
495
### DailyTimeIntervalScheduleBuilder Class
496
497
Builder for daily time interval schedules that fire during specific time periods on selected days.
498
499
```java { .api }
500
/**
501
* Builder for DailyTimeIntervalTrigger schedules with time-of-day constraints
502
*/
503
class DailyTimeIntervalScheduleBuilder extends ScheduleBuilder<DailyTimeIntervalTrigger> {
504
/**
505
* Create a daily time interval schedule builder
506
* @return new builder instance
507
*/
508
static DailyTimeIntervalScheduleBuilder dailyTimeIntervalSchedule();
509
510
/**
511
* Set which days of the week the trigger should fire
512
* @param daysOfWeek set of day numbers (1=Sunday, 2=Monday, ..., 7=Saturday)
513
* @return this builder for method chaining
514
*/
515
DailyTimeIntervalScheduleBuilder onDaysOfTheWeek(Set<Integer> daysOfWeek);
516
517
/**
518
* Set which days of the week the trigger should fire
519
* @param daysOfWeek array of day numbers
520
* @return this builder for method chaining
521
*/
522
DailyTimeIntervalScheduleBuilder onDaysOfTheWeek(Integer... daysOfWeek);
523
524
/**
525
* Set trigger to fire only on Monday through Friday
526
* @return this builder for method chaining
527
*/
528
DailyTimeIntervalScheduleBuilder onMondayThroughFriday();
529
530
/**
531
* Set trigger to fire only on Saturday and Sunday
532
* @return this builder for method chaining
533
*/
534
DailyTimeIntervalScheduleBuilder onSaturdayAndSunday();
535
536
/**
537
* Set trigger to fire every day of the week
538
* @return this builder for method chaining
539
*/
540
DailyTimeIntervalScheduleBuilder onEveryDay();
541
542
/**
543
* Set the start time of day
544
* @param timeOfDay the start time
545
* @return this builder for method chaining
546
*/
547
DailyTimeIntervalScheduleBuilder startingDailyAt(TimeOfDay timeOfDay);
548
549
/**
550
* Set the end time of day
551
* @param timeOfDay the end time
552
* @return this builder for method chaining
553
*/
554
DailyTimeIntervalScheduleBuilder endingDailyAt(TimeOfDay timeOfDay);
555
556
/**
557
* Set the firing interval
558
* @param interval the interval value
559
* @param unit the interval unit (SECOND, MINUTE, HOUR only)
560
* @return this builder for method chaining
561
*/
562
DailyTimeIntervalScheduleBuilder withInterval(int interval, DateBuilder.IntervalUnit unit);
563
564
/**
565
* Set interval in seconds
566
* @param intervalInSeconds interval in seconds
567
* @return this builder for method chaining
568
*/
569
DailyTimeIntervalScheduleBuilder withIntervalInSeconds(int intervalInSeconds);
570
571
/**
572
* Set interval in minutes
573
* @param intervalInMinutes interval in minutes
574
* @return this builder for method chaining
575
*/
576
DailyTimeIntervalScheduleBuilder withIntervalInMinutes(int intervalInMinutes);
577
578
/**
579
* Set interval in hours
580
* @param intervalInHours interval in hours
581
* @return this builder for method chaining
582
*/
583
DailyTimeIntervalScheduleBuilder withIntervalInHours(int intervalInHours);
584
585
/**
586
* Set the repeat count (number of additional firings after the first)
587
* @param repeatCount repeat count or REPEAT_INDEFINITELY
588
* @return this builder for method chaining
589
*/
590
DailyTimeIntervalScheduleBuilder withRepeatCount(int repeatCount);
591
592
/**
593
* Set the time zone for time calculations
594
* @param timezone the time zone
595
* @return this builder for method chaining
596
*/
597
DailyTimeIntervalScheduleBuilder inTimeZone(TimeZone timezone);
598
599
/**
600
* Set misfire instruction to ignore misfires
601
* @return this builder for method chaining
602
*/
603
DailyTimeIntervalScheduleBuilder withMisfireHandlingInstructionIgnoreMisfires();
604
605
/**
606
* Set misfire instruction to fire once when misfire is detected
607
* @return this builder for method chaining
608
*/
609
DailyTimeIntervalScheduleBuilder withMisfireHandlingInstructionFireAndProceed();
610
611
/**
612
* Set misfire instruction to do nothing on misfire
613
* @return this builder for method chaining
614
*/
615
DailyTimeIntervalScheduleBuilder withMisfireHandlingInstructionDoNothing();
616
}
617
```
618
619
**Usage Examples:**
620
621
```java
622
// Business hours monitoring (every 15 minutes, 9 AM - 5 PM, weekdays)
623
Trigger businessHours = newTrigger()
624
.withSchedule(dailyTimeIntervalSchedule()
625
.onMondayThroughFriday()
626
.startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 0))
627
.endingDailyAt(TimeOfDay.hourAndMinuteOfDay(17, 0))
628
.withIntervalInMinutes(15))
629
.build();
630
631
// Weekend maintenance (every 2 hours on weekends)
632
Trigger weekendMaintenance = newTrigger()
633
.withSchedule(dailyTimeIntervalSchedule()
634
.onSaturdayAndSunday()
635
.withIntervalInHours(2))
636
.build();
637
638
// Custom days and times
639
Set<Integer> customDays = Set.of(2, 4, 6); // Monday, Wednesday, Friday
640
Trigger customSchedule = newTrigger()
641
.withSchedule(dailyTimeIntervalSchedule()
642
.onDaysOfTheWeek(customDays)
643
.startingDailyAt(TimeOfDay.hourMinuteAndSecondOfDay(8, 30, 0))
644
.endingDailyAt(TimeOfDay.hourMinuteAndSecondOfDay(18, 30, 0))
645
.withInterval(30, DateBuilder.IntervalUnit.MINUTE)
646
.withRepeatCount(20)) // Limited repeats per day
647
.build();
648
649
// High frequency during trading hours
650
Trigger tradingHours = newTrigger()
651
.withSchedule(dailyTimeIntervalSchedule()
652
.onMondayThroughFriday()
653
.startingDailyAt(TimeOfDay.hourAndMinuteOfDay(9, 30)) // Market open
654
.endingDailyAt(TimeOfDay.hourAndMinuteOfDay(16, 0)) // Market close
655
.withIntervalInSeconds(30)
656
.inTimeZone(TimeZone.getTimeZone("America/New_York"))
657
.withMisfireHandlingInstructionFireAndProceed())
658
.build();
659
660
// Static imports for cleaner syntax
661
import static org.quartz.DailyTimeIntervalScheduleBuilder.*;
662
663
Trigger clean = newTrigger()
664
.withSchedule(dailyTimeIntervalSchedule()
665
.onEveryDay()
666
.withIntervalInHours(1))
667
.build();
668
```
669
670
### TimeOfDay Class
671
672
Utility class for representing specific times of day used with DailyTimeIntervalTrigger.
673
674
```java { .api }
675
/**
676
* Represents a time of day (hour, minute, second)
677
*/
678
class TimeOfDay implements Serializable {
679
/**
680
* Create time from hour and minute (second = 0)
681
* @param hour hour of day (0-23)
682
* @param minute minute of hour (0-59)
683
* @return TimeOfDay instance
684
*/
685
static TimeOfDay hourAndMinuteOfDay(int hour, int minute);
686
687
/**
688
* Create time from hour, minute, and second
689
* @param hour hour of day (0-23)
690
* @param minute minute of hour (0-59)
691
* @param second second of minute (0-59)
692
* @return TimeOfDay instance
693
*/
694
static TimeOfDay hourMinuteAndSecondOfDay(int hour, int minute, int second);
695
696
/**
697
* Get the hour component
698
* @return hour (0-23)
699
*/
700
int getHour();
701
702
/**
703
* Get the minute component
704
* @return minute (0-59)
705
*/
706
int getMinute();
707
708
/**
709
* Get the second component
710
* @return second (0-59)
711
*/
712
int getSecond();
713
714
/**
715
* Check if this time is before another time
716
* @param timeOfDay the other time
717
* @return true if this time is before the other
718
*/
719
boolean before(TimeOfDay timeOfDay);
720
721
/**
722
* Check if this time is after another time
723
* @param timeOfDay the other time
724
* @return true if this time is after the other
725
*/
726
boolean after(TimeOfDay timeOfDay);
727
}
728
```
729
730
**Usage Examples:**
731
732
```java
733
// Creating TimeOfDay instances
734
TimeOfDay morning = TimeOfDay.hourAndMinuteOfDay(9, 0); // 9:00 AM
735
TimeOfDay evening = TimeOfDay.hourAndMinuteOfDay(17, 30); // 5:30 PM
736
TimeOfDay precise = TimeOfDay.hourMinuteAndSecondOfDay(12, 30, 45); // 12:30:45 PM
737
738
// Using in schedules
739
Trigger timeConstrained = newTrigger()
740
.withSchedule(dailyTimeIntervalSchedule()
741
.startingDailyAt(morning)
742
.endingDailyAt(evening)
743
.withIntervalInMinutes(30))
744
.build();
745
746
// Time comparisons
747
if (morning.before(evening)) {
748
System.out.println("Morning comes before evening");
749
}
750
```