Compare commits

..

19 Commits

Author SHA1 Message Date
renovate[bot]
ad12e4116a Update kotlin_version to v2.2.21 2025-11-10 20:37:14 +00:00
2cce483dc8 update github_release to support environment variables 2025-05-16 12:44:14 +06:00
fe5cdbefe8 Merge pull request #143 from InsanusMokrassar/2.7.2
2.7.2
2025-02-15 21:23:58 +06:00
4379635174 fixes 2025-02-15 21:07:13 +06:00
d0c3bae000 update dependencies 2025-02-15 21:05:34 +06:00
dfedd58b76 start 2.7.2 2025-02-15 21:03:08 +06:00
b59c325641 Merge pull request #140 from InsanusMokrassar/2.7.1
2.7.1
2025-01-08 12:26:30 +06:00
de64a4d806 __small__ optimization 2025-01-08 12:24:06 +06:00
409ca3770f fix parser 2025-01-08 12:22:29 +06:00
08ef7281e5 start 2.7.1 2025-01-08 12:17:21 +06:00
c28bf17335 Merge pull request #138 from InsanusMokrassar/2.7.0
2.7.0
2024-12-30 08:53:12 +06:00
bd590c3e3e update gradle wrapper version 2024-12-30 08:51:18 +06:00
9c11c0c7fc add support of wasm 2024-12-30 08:49:41 +06:00
79375f21e3 update dependencies 2024-12-30 08:35:20 +06:00
0b4dc1b328 start 2.7.0 2024-12-30 08:33:27 +06:00
4afebd8b7e Merge pull request #131 from InsanusMokrassar/2.6.1
2.6.1
2024-11-06 08:50:36 +06:00
c76ca1798e fixes in parsing of ktontab templates 2024-11-06 08:46:10 +06:00
58917c6458 start 2.6.1 2024-11-06 07:38:24 +06:00
5ef6134d9f Merge pull request #129 from InsanusMokrassar/2.6.0
2.6.0
2024-11-03 21:52:59 +06:00
8 changed files with 139 additions and 89 deletions

View File

@@ -1,5 +1,26 @@
# Changelog
## 2.7.2
* `Version`:
* `Kotlin`: `2.1.10`
* `Serialization`: `1.8.0`
## 2.7.1
* Fixes in parser and checker
## 2.7.0
* `Version`:
* `Kotlin`: `2.1.0`
* `Coroutines`: `1.10.1`
* Add WASM support (solution of [#137](https://github.com/InsanusMokrassar/krontab/issues/137))
## 2.6.1
* Fixes in parsing of string parts
## 2.6.0
* Fix of `doOnceTz` behaviour: now it will use local time as utc time to get next waking up time

View File

@@ -8,6 +8,7 @@
![Android](https://img.shields.io/badge/Android-green?style=for-the-badge&logo=android&logoColor=white)
![Js](https://img.shields.io/badge/JavaScript-323330?style=for-the-badge&logo=javascript&logoColor=F7DF1E)
![Linux x64](https://img.shields.io/badge/Linux%20x64-white?style=for-the-badge&logo=linux&logoColor=black)
![WASM](https://img.shields.io/badge/WASM-654FF0?style=for-the-badge&logo=webassembly&logoColor=white)
[![KDocs](https://img.shields.io/badge/KDocs-323330?style=for-the-badge&logo=Kotlin&logoColor=7F52FF)](https://insanusmokrassar.github.io/krontab/)
[![Tutorials](https://img.shields.io/badge/Tutorials-0288D1?style=for-the-badge&logo=mkdocs&logoColor=white)](https://docs.inmo.dev/krontab/index.html)

View File

@@ -62,6 +62,11 @@ kotlin {
linuxX64()
mingwX64()
linuxArm64()
wasm {
browser()
nodejs()
d8()
}
sourceSets {
@@ -85,6 +90,7 @@ kotlin {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
implementation kotlin('test')
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlin_coroutines_version"
}
}

View File

@@ -11,12 +11,20 @@ private String getCurrentVersionChangelog(String version) {
return changelogDataOS.toString().trim()
}
if (new File(projectDir, "secret.gradle").exists()) {
apply from: './secret.gradle'
def githubTokenVariableName = "GITHUB_RELEASE_TOKEN"
def githubTokenVariableFromEnv = System.getenv(githubTokenVariableName)
def secretFile = new File(projectDir, "secret.gradle")
if (secretFile.exists() || project.hasProperty(githubTokenVariableName) || (githubTokenVariableFromEnv != "" && githubTokenVariableFromEnv != null)) {
if (secretFile.exists()) {
apply from: './secret.gradle'
}
apply plugin: "com.github.breadmoirai.github-release"
def githubReleaseToken = project.hasProperty(githubTokenVariableName) ? project.property(githubTokenVariableName).toString() : githubTokenVariableFromEnv
githubRelease {
token "${project.property('GITHUB_RELEASE_TOKEN')}"
token githubReleaseToken
owner = "InsanusMokrassar"
repo = "${rootProject.name}"

View File

@@ -9,11 +9,11 @@ android.useAndroidX=true
android.enableJetifier=false
kotlin_version=2.0.21
kotlin_coroutines_version=1.9.0
kotlin_serialization_version=1.7.3
kotlin_version=2.2.21
kotlin_coroutines_version=1.10.1
kotlin_serialization_version=1.8.0
dokka_version=1.9.20
dokka_version=2.0.0
klockVersion=5.4.0
@@ -23,7 +23,7 @@ github_release_plugin_version=2.5.2
## Android
android_gradle_version=8.2.2
android_gradle_version=8.7.2
android_minSdkVersion=21
android_compileSdkVersion=35
android_buildToolsVersion=35.0.0
@@ -36,5 +36,5 @@ androidx_work_version=2.10.0
## Common
version=2.6.0
android_code_version=44
version=2.7.2
android_code_version=48

View File

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip

View File

@@ -41,53 +41,83 @@ private fun <T> createSimpleScheduler(from: String, dataRange: IntRange, dataCon
* FSM for parsing of incoming data. If at the end of parsing it have non-null state and string is not empty, data passed check
*
* 1.
* * \\d -> 1
* * \\* -> 2
* * \\- -> 5
* * , -> 1
* * m -> 6
* * o -> 7
* * w -> 7
* * "\\d" -> 2
* * "\\*" -> 4
* * "F" -> 7
* * "f" -> 7
* * "L" -> 7
* * "l" -> 7
* * "/" -> 6
* 2.
* * / -> 3
* * "\\d" -> 2
* * "/" -> 6
* * "," -> 1
* * "-" -> 3
* * "m" -> 9
* * "o" -> 10
* * "w" -> 10
* 3.
* * \\d -> 3
* * \\* -> 4
* * "L" -> 7
* * "l" -> 7
* * "\\d" -> 8
* 4.
* * , -> 1
* * "/" -> 6
* * "," -> 1
* 5.
* * \\d -> 5
* * , -> 1
* * "/" -> 6
* 6.
* * s -> 7
* 7. Empty, end of parse
* * "\\d" -> 8
* * "\\*" -> 7
* 7.
* * "," -> 1
* 8.
* * "\\d" -> 8
* * "," -> 1
* 9.
* * "s" -> 10 // end of ms
* 10. Empty, end of parse
*/
private val checkIncomingPartTransitionsMap = listOf(
listOf(
Regex("\\d") to 0,
Regex("\\*") to 1,
Regex("-") to 4,
Regex(",") to 0,
Regex("m") to 5,
Regex("o") to 6,
Regex("w") to 6,
),
listOf(
Regex("/") to 2,
),
listOf(
Regex("\\d") to 2,
listOf( // 0
Regex("\\d") to 1,
Regex("\\*") to 3,
Regex("[Ff]") to 6,
Regex("[Ll]") to 6,
Regex("/") to 5,
),
listOf(
listOf( // 1
Regex("\\d") to 1,
Regex("/") to 5,
Regex(",") to 0,
Regex("-") to 2,
Regex("m") to 8,
Regex("o") to 9,
Regex("w") to 9,
),
listOf( // 2
Regex("[Ll]") to 6,
Regex("\\d") to 7,
),
listOf( // 3
Regex("/") to 5,
Regex(",") to 0,
),
listOf(
Regex("\\d") to 4,
listOf( // 4
Regex("/") to 5,
),
listOf( // 5
Regex("\\d") to 7,
Regex("\\*") to 6,
),
listOf( // 6
Regex(",") to 0,
),
listOf(
Regex("s") to 6, // end of ms
listOf( // 7
Regex("\\d") to 7,
Regex(",") to 0,
),
listOf( // 8
Regex("s") to 9, // end of ms
),
listOf(), // empty state, end of parsing
)

View File

@@ -2,6 +2,7 @@ package dev.inmo.krontab.utils
import korlibs.time.*
import dev.inmo.krontab.KronSchedulerTz
import dev.inmo.krontab.KrontabTemplate
import dev.inmo.krontab.buildSchedule
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.takeWhile
@@ -11,73 +12,51 @@ import kotlin.test.*
@ExperimentalCoroutinesApi
@FlowPreview
class StringParseTest {
@Test
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
val kronScheduler = buildSchedule("*/1 * * * *")
private fun makeSimpleEverySecondTest(template: KrontabTemplate) {
val kronScheduler = buildSchedule(template)
val flow = kronScheduler.asFlowWithoutDelays()
runTest {
val mustBeCollected = 10
var collected = 0
var previousTime: DateTime? = null
flow.takeWhile {
collected < mustBeCollected
}.collect {
previousTime ?.let { previousTime ->
assertEquals(previousTime + 1.seconds, it)
}
previousTime = it
collected++
}
assertEquals(mustBeCollected, collected)
}
}
@Test
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
makeSimpleEverySecondTest("*/1 * * * *")
}
@Test
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithWrongAmountOfSpaces() {
val kronScheduler = buildSchedule("*/1 * * * * ")
val flow = kronScheduler.asFlowWithoutDelays()
runTest {
val mustBeCollected = 10
var collected = 0
flow.takeWhile {
collected < mustBeCollected
}.collect {
collected++
}
assertEquals(mustBeCollected, collected)
val templatesFirstReplacers = listOf(
"*/1",
"*",
"/1",
"f,/1",
)
templatesFirstReplacers.forEach { replacer ->
makeSimpleEverySecondTest("$replacer * * * * ")
}
}
@Test
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithGarbageInTemplate() {
val kronScheduler = buildSchedule(" sdf */1 * * * oo * ")
val flow = kronScheduler.asFlowWithoutDelays()
runTest {
val mustBeCollected = 10
var collected = 0
flow.takeWhile {
collected < mustBeCollected
}.collect {
collected++
}
assertEquals(mustBeCollected, collected)
}
makeSimpleEverySecondTest(" sdf */1 * * * oo * ")
}
@Test
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithInsufficientArgsInTemplate() {
val kronScheduler = buildSchedule(" sdf */1 ")
val flow = kronScheduler.asFlowWithoutDelays()
runTest {
val mustBeCollected = 10
var collected = 0
flow.takeWhile {
collected < mustBeCollected
}.collect {
collected++
}
assertEquals(mustBeCollected, collected)
}
makeSimpleEverySecondTest(" sdf */1 ")
}
@Test
fun testThatFlowIsCorrectlyWorkEverySecondWhenMillisIsHalfOfSecondBuiltOnString() {
@@ -88,9 +67,14 @@ class StringParseTest {
runTest {
val mustBeCollected = 10
var collected = 0
var previousTime: DateTime? = null
flow.takeWhile {
collected < mustBeCollected
}.collect {
previousTime ?.let { previousTime ->
assertEquals(previousTime.copy(milliseconds = 500) + 1.seconds, it)
}
previousTime = it
collected++
}
assertEquals(mustBeCollected, collected)