Skip to content

Commit c0b6125

Browse files
Clean Up
1 parent 6365411 commit c0b6125

2 files changed

Lines changed: 37 additions & 24 deletions

File tree

src/commonMain/kotlin/io/github/kevincianfarini/cardiologist/PulseSchedule.kt

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,41 @@ import kotlinx.datetime.number
88

99
/**
1010
* A [Pulse] schedule that can be used with [schedulePulse] to define complex schedules.
11-
*
12-
* @constructor Creates a new PulseSchedule. Second values must be in range 0..59, minute values must be in range 0..59,
13-
* hour values must be in range 0..23, and day of month values must be in range 1..31. This constructor also
14-
* requires that seconds, minutes, hours, days of month, and months cannot be empty sets.
15-
* @throws IllegalArgumentException if the constructor is called with any of our bounds value or an improperly empty set.
1611
*/
1712
@Poko
18-
public class PulseSchedule(
19-
public val atSeconds: Set<Int>,
20-
public val atMinutes: Set<Int>,
21-
public val atHours: Set<Int>,
22-
public val onDaysOfMonth: Set<Int>,
23-
public val inMonths: Set<Month>,
24-
public val onDaysOfWeek: Set<DayOfWeek>,
13+
public class PulseSchedule internal constructor(
14+
public val atSeconds: List<Int>,
15+
public val atMinutes: List<Int>,
16+
public val atHours: List<Int>,
17+
public val onDaysOfMonth: List<Int>,
18+
public val inMonths: List<Month>,
19+
public val onDaysOfWeek: List<DayOfWeek>,
2520
) {
21+
22+
/**
23+
* Creates a new PulseSchedule. Second values must be in range 0..59, minute values must be in range 0..59,
24+
* hour values must be in range 0..23, and day of month values must be in range 1..31. This constructor also
25+
* requires that seconds, minutes, hours, days of month, and months cannot be empty sets.
26+
*
27+
* @throws IllegalArgumentException if the constructor is called with any of our bounds value or an improperly empty
28+
* set.
29+
*/
30+
public constructor(
31+
atSeconds: Set<Int>,
32+
atMinutes: Set<Int>,
33+
atHours: Set<Int>,
34+
onDaysOfMonth: Set<Int>,
35+
inMonths: Set<Month>,
36+
onDaysOfWeek: Set<DayOfWeek>,
37+
) : this(
38+
atSeconds = atSeconds.sorted(),
39+
atMinutes = atMinutes.sorted(),
40+
atHours = atHours.sorted(),
41+
onDaysOfMonth = onDaysOfMonth.sorted(),
42+
inMonths = inMonths.sorted(),
43+
onDaysOfWeek = onDaysOfWeek.sorted()
44+
)
45+
2646
init {
2747
require(!atSeconds.any { it !in 0..59 }) { "Seconds has an out of bound value: $atSeconds" }
2848
require(atSeconds.isNotEmpty()) { "Seconds cannot be empty!" }
@@ -36,13 +56,6 @@ public class PulseSchedule(
3656
// Don't check if onDaysOfWeek is empty because an empty set is equivalent to the wildcard `*` value in cron
3757
// expressions.
3858
}
39-
40-
internal val sortedSeconds = atSeconds.sorted()
41-
internal val sortedMinutes = atMinutes.sorted()
42-
internal val sortedHours = atHours.sorted()
43-
internal val sortedDaysOfMonth = onDaysOfMonth.sorted()
44-
internal val sortedMonths = inMonths.sorted()
45-
internal val sortedDaysOfWeek = onDaysOfWeek.sorted()
4659
}
4760

4861
public class PulseScheduleBuilder internal constructor() {

src/commonMain/kotlin/io/github/kevincianfarini/cardiologist/impl/LocalDateTime.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ internal fun LocalDateTime.nextMatch(schedule: PulseSchedule): LocalDateTime {
1717
// nanosecond component by one to ensure that we produce a match that's distinct from this value.
1818
val time = if (matches(schedule)) copy(nanosecond = 1) else this
1919
return with(schedule) {
20-
time.nextMonth(sortedMonths)
21-
.nextDay(sortedDaysOfMonth, sortedDaysOfWeek, sortedMonths)
22-
.nextHour(sortedHours, sortedDaysOfMonth, sortedDaysOfWeek, sortedMonths)
23-
.nextMinute(sortedMinutes, sortedHours, sortedDaysOfMonth, sortedDaysOfWeek, sortedMonths)
24-
.nextSecond(sortedSeconds, sortedMinutes, sortedHours, sortedDaysOfMonth, sortedDaysOfWeek, sortedMonths)
20+
time.nextMonth(inMonths)
21+
.nextDay(onDaysOfMonth, onDaysOfWeek, inMonths)
22+
.nextHour(atHours, onDaysOfMonth, onDaysOfWeek, inMonths)
23+
.nextMinute(atMinutes, atHours, onDaysOfMonth, onDaysOfWeek, inMonths)
24+
.nextSecond(atSeconds, atMinutes, atHours, onDaysOfMonth, onDaysOfWeek, inMonths)
2525
}
2626
}
2727

0 commit comments

Comments
 (0)