aboutsummaryrefslogtreecommitdiff
path: root/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/kotlin')
-rw-r--r--src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt
index 1190bc1a..3157affc 100644
--- a/src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt
+++ b/src/test/kotlin/test/pl/treksoft/kvision/utils/UtilsSpec.kt
@@ -1,7 +1,10 @@
package test.pl.treksoft.kvision.utils
+import pl.treksoft.kvision.utils.toDateF
import pl.treksoft.kvision.utils.toHexString
+import pl.treksoft.kvision.utils.toStringF
import test.pl.treksoft.kvision.SimpleSpec
+import kotlin.js.Date
import kotlin.test.Test
import kotlin.test.assertEquals
@@ -16,4 +19,32 @@ class UtilsSpec : SimpleSpec {
assertEquals("123456", res2, "Should convert int value to hex string")
}
}
-} \ No newline at end of file
+
+ @Test
+ fun toDateF() {
+ run {
+ val res = "2017-03-14 14:50:35".toDateF()
+ assertEquals(js("new Date(2017,2,14,14,50,35).getTime()"), res.getTime(), "Should convert String value to Date")
+ }
+ }
+
+ @Test
+ fun toStringF() {
+ run {
+ val date = js("new Date()")
+ val res = Date().toStringF()
+ val y = date.getFullYear()
+ val m = date.getMonth() + 1
+ val m2 = if (m<10) "0$m" else "$m"
+ val d = date.getDate()
+ val d2 = if (d<10) "0$d" else "$d"
+ val h = date.getHours()
+ val h2 = if (h<10) "0$h" else "$h"
+ val min = date.getMinutes()
+ val min2 = if (min<10) "0$min" else "$min"
+ val sec = date.getSeconds()
+ val sec2 = if (sec<10) "0$sec" else "$sec"
+ assertEquals("$y-$m2-$d2 $h2:$min2:$sec2", res, "Should convert Date value to String")
+ }
+ }
+}