Compare commits

...

8 Commits
0.3.1 ... 0.3.2

Author SHA1 Message Date
1431c0cda2 fix for parser 2020-10-10 22:17:48 +06:00
66e75b4315 add "each" 2020-10-10 21:39:00 +06:00
5a13437c17 add last and first 2020-10-10 21:12:32 +06:00
6d612ce95d start 0.3.2 2020-10-10 20:03:52 +06:00
92f1ec03dd fix in github_release 2020-10-08 18:17:46 +06:00
f23740a6a5 fix of github_release files 2020-10-08 18:04:27 +06:00
16d8850ca7 fix of github_release files 2020-10-08 17:53:24 +06:00
f278361470 Merge pull request #6 from InsanusMokrassar/0.3.1
0.3.1
2020-10-08 17:13:28 +06:00
7 changed files with 66 additions and 13 deletions

View File

@@ -9,6 +9,16 @@
* Typealias `KrontabTemplate` was added
* Extension `KrontabTemplate#toSchedule` was added
### 0.3.2
* Function `TimeBuilder#each` was added (works as `at`)
* Add opportunity to use `first` shortcuts:
* Value property `TimeBuilder#first` for including via functions like `TimeBuilder#at`
* Shortcut for kron string format `f` or `F`
* Add opportunity to use `last` shortcuts:
* Value property `TimeBuilder#last` for including via functions like `TimeBuilder#at`
* Shortcut for kron string format `l` or `L`
### 0.3.1
* Versions:

View File

@@ -17,7 +17,7 @@ plugins {
id "org.jetbrains.dokka" version "$dokka_version"
}
project.version = "0.3.1"
project.version = "0.3.2"
project.group = "com.insanusmokrassar"
apply from: "publish.gradle"

View File

@@ -1,9 +1,11 @@
private String getCurrentVersionChangelog() {
private String getCurrentVersionChangelog(String version) {
OutputStream changelogDataOS = new ByteArrayOutputStream()
exec {
standardOutput = changelogDataOS
commandLine 'chmod', "+x", './changelog_parser.sh'
commandLine './changelog_parser.sh', "$library_version", 'CHANGELOG.md'
}
exec {
standardOutput = changelogDataOS
commandLine './changelog_parser.sh', "$version", 'CHANGELOG.md'
}
return changelogDataOS.toString().trim()
@@ -23,6 +25,6 @@ if (new File(projectDir, "secret.gradle").exists()) {
releaseName "${project.version}"
targetCommitish "${project.version}"
body getCurrentVersionChangelog()
body getCurrentVersionChangelog("${project.version}")
}
}

View File

@@ -27,6 +27,8 @@ typealias KrontabTemplate = String
* * {int}/{int}
* * */{int}
* * {int}
* * F
* * L
*
* Additional info about ranges can be found in follow accordance:
*
@@ -39,8 +41,9 @@ typealias KrontabTemplate = String
* Examples:
*
* * "0/5 * * * *" for every five seconds triggering
* * "0/5,L * * * *" for every five seconds triggering and on 59 second
* * "0/15 30 * * *" for every 15th seconds in a half of each hour
* * "1 2 3 4 5" for triggering in near first second of second minute of third hour of fourth day of may
* * "1 2 3 F,4,L 5" for triggering in near first second of second minute of third hour of fourth day of may
*
* @see com.insanusmokrassar.krontab.internal.createKronScheduler
*/

View File

@@ -12,6 +12,17 @@ sealed class TimeBuilder (
) {
private var result: Set<Int>? = null
/**
* The first possible value of builder
*/
val first
get() = restrictionsRange.first
/**
* The last possible value of builder. Using of this variable equal to using "L" in strings
*/
val last
get() = restrictionsRange.last
/**
* After calling of this function this builder will allow any value of current time
*/
@@ -37,6 +48,13 @@ sealed class TimeBuilder (
result = (result ?: emptySet()) + value.clamp(restrictionsRange)
}
/**
* Shortcut for [at]. In fact will
*/
@Suppress("unused", "NOTHING_TO_INLINE")
inline infix fun each(value: Int) = at(value)
/**
* Just wrapper for more obvious writing something like "[from] 2 [every] 5". For example, for [SecondsBuilder] it
* will mean "[from] second second [every] 5 seconds", or "2, 7, 13, ..."
@@ -92,6 +110,15 @@ sealed class TimeBuilder (
@Suppress("MemberVisibilityCanBePrivate")
infix operator fun rangeTo(endIncluding: Int) = (this from 0) rangeTo endIncluding
/**
* Will include the last possible value
*/
fun includeLast() = at(restrictionsRange.last)
/**
* Will include the first possible value
*/
fun includeFirst() = at(restrictionsRange.first)
internal fun build() = result ?.map { it.toByte() } ?.toTypedArray()
}

View File

@@ -52,7 +52,13 @@ internal fun CronDateTime.toNearDateTime(relativelyTo: DateTime = DateTime.now()
}
klockDayOfMonth ?.let {
val left = it - current.dayOfMonth
val left = (it - current.dayOfMonth).let { diff ->
if (diff > 0 && current.endOfMonth.run { it > dayOfMonth && current.dayOfMonth == dayOfMonth }) {
0
} else {
diff
}
}
current += DateTimeSpan(months = if (left < 0) 1 else 0, days = left)
}

View File

@@ -6,13 +6,18 @@ private fun createSimpleScheduler(from: String, dataRange: IntRange): Array<Byte
val things = from.split(",")
val results = things.flatMap {
val currentToken = it.toLowerCase().replace(
"f", dataRange.first.toString()
).replace(
"l", dataRange.last.toString()
)
when {
it.contains("-") -> {
val splitted = it.split("-")
currentToken.contains("-") -> {
val splitted = currentToken.split("-")
(splitted.first().toInt().clamp(dataRange) .. splitted[1].toInt().clamp(dataRange)).toList()
}
it.contains("/") -> {
val (start, step) = it.split("/")
currentToken.contains("/") -> {
val (start, step) = currentToken.split("/")
val startNum = (if (start.isEmpty() || start == "*") {
0
} else {
@@ -21,8 +26,8 @@ private fun createSimpleScheduler(from: String, dataRange: IntRange): Array<Byte
val stepNum = step.toInt().clamp(dataRange)
(startNum .. dataRange.last step stepNum).map { it }
}
it == "*" -> return null
else -> listOf(it.toInt().clamp(dataRange))
currentToken == "*" -> return null
else -> listOf(currentToken.toInt().clamp(dataRange))
}
}