• R/O
  • SSH

kink: Commit

Kink runtime


Commit MetaInfo

Revision66a6a003db514215b256c79e6e87c81d721f2333 (tree)
Time2019-11-25 22:10:19
Authormiyakawataku
Commitermiyakawataku

Log Message

add comparation methods to time

Change Summary

Incremental Difference

diff -r 0d35aa7a371e -r 66a6a003db51 src/main/resources/kink-mods/kink/datetime/TIME.kn
--- a/src/main/resources/kink-mods/kink/datetime/TIME.kn Mon Nov 25 22:02:19 2019 +0900
+++ b/src/main/resources/kink-mods/kink/datetime/TIME.kn Mon Nov 25 22:10:19 2019 +0900
@@ -1,8 +1,10 @@
11 :JAVA.require_from('kink/host_lang/java/')
22 :NUM.require_from('kink/')
3+:COMPARE.require_from('kink/')
34
45 :Nano_to_sec <- NUM.new(1 (-9))
56 :LocalTime_class <- JAVA.class('java.time.LocalTime')
7+:Object_class <- JAVA.class('java.lang.Object')
68
79 :new <- {(:Hour :Minute :Second)
810 :Sec_int = Second // 1
@@ -39,6 +41,16 @@
3941 Sec_int + Nano_int * 0.000_000_001
4042 }
4143
44+ ... COMPARE.trait{(:C)
45+ C.lt_fun{(:X :Y)
46+ X.Java_lt.call_method('compareTo' [Y.Java_lt]).to_kink_num < 0
47+ }
48+
49+ C.eq_fun{(:X :Y)
50+ X.Java_lt.call_method('equals' [Y.Java_lt.as(Object_class)]).to_kink_bool
51+ }
52+ }
53+
4254 'repr' {[:T]()
4355 'Time({%02d}:{%02d}:{%02d})'.format(T.hour T.minute T.second)
4456 }
diff -r 0d35aa7a371e -r 66a6a003db51 src/test/kink/datetime/TIME_test.kn
--- a/src/test/kink/datetime/TIME_test.kn Mon Nov 25 22:02:19 2019 +0900
+++ b/src/test/kink/datetime/TIME_test.kn Mon Nov 25 22:10:19 2019 +0900
@@ -20,6 +20,43 @@
2020 Result == 11.123456789 || raise('got {}'.format(Result.repr))
2121 }
2222
23+ TEST.group('comparation methods'){
24+ [ [TIME.new(1 2 3.123456789) TIME.new(23 59 59.123456789) true true true false false false]
25+ [TIME.new(23 59 59.123456789) TIME.new(1 2 3.123456789) false false true false true true]
26+ [TIME.new(12 12 12.123456789) TIME.new(12 12 12.123456789) false true false true true false]
27+ ].each{([:X :Y :Lt? :Le? :Ne? :Eq? :Ge? :Gt?])
28+ TEST.test('{} < {} : {}'.format(X.repr Y.repr Lt?.repr)){
29+ :Result = X < Y
30+ Result == Lt? || raise('got {}'.format(Result.repr))
31+ }
32+
33+ TEST.test('{} <= {} : {}'.format(X.repr Y.repr Le?.repr)){
34+ :Result = X <= Y
35+ Result == Le? || raise('got {}'.format(Result.repr))
36+ }
37+
38+ TEST.test('{} != {} : {}'.format(X.repr Y.repr Ne?.repr)){
39+ :Result = X != Y
40+ Result == Ne? || raise('got {}'.format(Result.repr))
41+ }
42+
43+ TEST.test('{} == {} : {}'.format(X.repr Y.repr Eq?.repr)){
44+ :Result = X == Y
45+ Result == Eq? || raise('got {}'.format(Result.repr))
46+ }
47+
48+ TEST.test('{} >= {} : {}'.format(X.repr Y.repr Ge?.repr)){
49+ :Result = X >= Y
50+ Result == Ge? || raise('got {}'.format(Result.repr))
51+ }
52+
53+ TEST.test('{} > {} : {}'.format(X.repr Y.repr Gt?.repr)){
54+ :Result = X > Y
55+ Result == Gt? || raise('got {}'.format(Result.repr))
56+ }
57+ }
58+ }
59+
2360 TEST.group('.repr'){
2461 TEST.test('0 is padded'){
2562 :Time = TIME.new(1 2 3.000000000)
Show on old repository browser