Skip to content

Commit

Permalink
Parsing for every month
Browse files Browse the repository at this point in the history
Fixes shyiko#3
  • Loading branch information
sjurba committed Dec 11, 2018
1 parent 38936ee commit 797a2bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target
.idea
22 changes: 7 additions & 15 deletions src/main/java/com/github/shyiko/skedule/internal/ScheduleImpl.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package com.github.shyiko.skedule.internal

import com.github.shyiko.skedule.InvalidScheduleException
import com.github.shyiko.skedule.Schedule
import java.lang.AssertionError
import java.time.DayOfWeek
import java.time.Duration
import java.time.LocalTime
import java.time.Month
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatterBuilder
import java.time.temporal.ChronoField
import java.time.temporal.ChronoUnit
import java.time.temporal.TemporalAdjusters
import java.util.EnumSet
import java.util.concurrent.TimeUnit
import com.github.shyiko.skedule.*
import java.time.*
import java.time.format.*
import java.time.temporal.*
import java.util.*
import java.util.concurrent.*

internal object ScheduleImpl {

Expand Down Expand Up @@ -168,7 +160,7 @@ internal object ScheduleImpl {
rawOrdinal.split(',').flatMapTo(mutableSetOf<Int>()) {
if (it.contains('-')) parseOrdinalRange(it, 1, 31) else setOf(parseOrdinal(it))
},
months = if (month == "") MONTH_ALL else
months = if (month == "month") MONTH_ALL else
EnumSet.copyOf(month.split(',').flatMap {
if (it.contains('-')) parseMonthRange(it) else setOf(parseMonth(it))
}),
Expand Down
26 changes: 19 additions & 7 deletions src/test/java/com/github/shyiko/skedule/ScheduleTest.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.github.shyiko.skedule

import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
import java.time.DayOfWeek
import java.time.LocalTime
import java.time.Month
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import org.assertj.core.api.Assertions.*
import org.testng.annotations.*
import java.time.*
import java.time.format.*

class ScheduleTest {

Expand Down Expand Up @@ -213,6 +210,21 @@ class ScheduleTest {
))
}

@Test
fun testEveryMonth() {
assertThat(
iterateOverSchedule(
"1st monday of month 09:00",
ZonedDateTime.parse("2018-01-01T00:00:00.007Z"),
skipFirstIfSame = false
)
).isEqualTo(listOf(
"2018-01-01T09:00:00Z",
"2018-02-05T09:00:00Z",
"2018-03-05T09:00:00Z"
))
}

@Test
fun testHourAlias() {
assertThat(
Expand Down

0 comments on commit 797a2bc

Please sign in to comment.