• R/O
  • SSH

kink: Commit

Kink runtime


Commit MetaInfo

Revision72c4fa758d3d25394ebb84ba6262b44c8ea0cb2d (tree)
Zeit2020-11-23 00:55:03
Autormiyakawataku
Commitermiyakawataku

Log Message

add Offset.show

Ändern Zusammenfassung

Diff

diff -r 8f900b5d1e0a -r 72c4fa758d3d src/main/resources/kink-mods/kink/datetime/OFFSET.kn
--- a/src/main/resources/kink-mods/kink/datetime/OFFSET.kn Sun Nov 22 10:23:58 2020 +0900
+++ b/src/main/resources/kink-mods/kink/datetime/OFFSET.kn Mon Nov 23 00:55:03 2020 +0900
@@ -111,6 +111,10 @@
111111 Min
112112 }
113113
114+ 'show' {[:O](:Config_fun.opt)
115+ '{}{%02d}:{%02d}'.format(O.sign O.hour O.minute)
116+ }
117+
114118 ## O.repr
115119 #
116120 # `repr` method returns the string representation of the offset.
diff -r 8f900b5d1e0a -r 72c4fa758d3d src/test/kink/datetime/OFFSET_test.kn
--- a/src/test/kink/datetime/OFFSET_test.kn Sun Nov 22 10:23:58 2020 +0900
+++ b/src/test/kink/datetime/OFFSET_test.kn Mon Nov 23 00:55:03 2020 +0900
@@ -70,8 +70,9 @@
7070 }
7171 } # }}}1
7272
73-TEST.group('offset'){ # {{{1
74- TEST.group('.total_minutes'){
73+TEST.group('offset'){ # {{{
74+
75+ TEST.group('.total_minutes'){ # {{{
7576 TEST.test('for plus'){
7677 :Offset = OFFSET.new(5 * 60 + 45)
7778 :Total_mins = Offset.total_minutes
@@ -83,9 +84,9 @@
8384 :Total_mins = Offset.total_minutes
8485 Total_mins == -(3 * 60 + 30) || raise('got {}'.format(Total_mins.repr))
8586 }
86- }
87+ } # }}}
8788
88- TEST.group('.sign'){
89+ TEST.group('.sign'){ # {{{
8990 TEST.test('for plus'){
9091 :Offset = OFFSET.new(5 * 60 + 45)
9192 :Sign = Offset.sign
@@ -103,9 +104,9 @@
103104 :Sign = Offset.sign
104105 Sign == '+' || raise('got {}'.format(Sign.repr))
105106 }
106- }
107+ } # }}}
107108
108- TEST.group('.hour'){
109+ TEST.group('.hour'){ # {{{
109110 TEST.test('for plus'){
110111 :Offset = OFFSET.new(5 * 60 + 45)
111112 :Hour = Offset.hour
@@ -123,9 +124,9 @@
123124 :Hour = Offset.hour
124125 Hour == 0 || raise('got {}'.format(Hour.repr))
125126 }
126- }
127+ } # }}}
127128
128- TEST.group('.minute'){
129+ TEST.group('.minute'){ # {{{
129130 TEST.test('for plus'){
130131 :Offset = OFFSET.new(5 * 60 + 45)
131132 :Min = Offset.minute
@@ -143,9 +144,41 @@
143144 :Min = Offset.minute
144145 Min == 0 || raise('got {}'.format(Min.repr))
145146 }
146- }
147+ } # }}}
147148
148- TEST.group('.repr'){
149+ TEST.group('.show'){ # {{{
150+
151+ TEST.group('without config'){
152+ [ [OFFSET.new(6 * 60 + 30) '+06:30']
153+ [OFFSET.new(-(6 * 60 + 30)) '-06:30']
154+ [OFFSET.new(12 * 60 + 30) '+12:30']
155+ [OFFSET.new(-(12 * 60 + 30)) '-12:30']
156+ [OFFSET.new(0) '+00:00']
157+ ].each{([:Offset :Expected])
158+ TEST.test('{}.show = {}'.format(Offset.repr Expected.repr)){
159+ :Result = Offset.show
160+ Result == Expected || raise('got {}'.format(Result.repr))
161+ }
162+ }
163+ }
164+
165+ TEST.group('with empty config'){
166+ [ [OFFSET.new(6 * 60 + 30) '+06:30']
167+ [OFFSET.new(-(6 * 60 + 30)) '-06:30']
168+ [OFFSET.new(12 * 60 + 30) '+12:30']
169+ [OFFSET.new(-(12 * 60 + 30)) '-12:30']
170+ [OFFSET.new(0) '+00:00']
171+ ].each{([:Offset :Expected])
172+ TEST.test('{}.show = {}'.format(Offset.repr Expected.repr)){
173+ :Result = Offset.show{}
174+ Result == Expected || raise('got {}'.format(Result.repr))
175+ }
176+ }
177+ }
178+
179+ } # }}}
180+
181+ TEST.group('.repr'){ # {{{
149182 TEST.test('for plus'){
150183 :Offset = OFFSET.new(5 * 60 + 45)
151184 :Repr = Offset.repr
@@ -163,9 +196,9 @@
163196 :Repr = Offset.repr
164197 Repr == '(offset +00:00)' || raise('got {}'.format(Repr.repr))
165198 }
166- }
199+ } # }}}
167200
168- TEST.group('equality'){
201+ TEST.group('equality'){ # {{{
169202 TEST.test('for equal pair'){
170203 :X = OFFSET.new(123)
171204 :Y = OFFSET.new(123)
@@ -179,8 +212,9 @@
179212 X == Y && raise('got true')
180213 X != Y || raise('got false')
181214 }
182- }
183-} # }}}1
215+ } # }}}
216+
217+} # }}}
184218
185219 TEST.group('OFFSET.parse'){ # {{{
186220 TEST.test('prase "Z"'){
Show on old repository browser