import Ġio . fluid sonic . time .* Ċ import Ġkotlin . test .* Ċ import Ġkotlin . time .* Ċ import Ġkotlin . time . Duration . Companion . hours Ċ import Ġkotlin . time . Duration . Companion . minutes Ċ import Ġkotlin . time . Duration . Companion . nan oseconds Ċ import Ġkotlin . time . Duration . Companion . seconds Ċ import Ġkotlinx . datetime .* ĊĊ Ċ @ Opt In ( Experimental Time :: class ) Ċ class ĠManual Clock Tests Ġ{ ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Advance () Ġ{ Ċĉ ĉ val Ġclock Ġ= ĠManual Clock () Ċĉ ĉ val Ġepoch Ġ= ĠTimestamp . from Epoch Seconds ( 0 ) Ċĉ ĉ val Ġa Little After Epoch Ġ= Ġepoch . plus ( DateTime Period ( hours Ġ= Ġ 1 , Ġminutes Ġ= Ġ 2 , Ġseconds Ġ= Ġ 3 , Ġnan oseconds Ġ= Ġ 4 ), Ġtime Zone Ġ= ĠTime Zone . UTC ) Ċĉ ĉ val Ġa Lot After Epoch Ġ= Ċĉĉ ĉ epoch . plus ( DateTime Period ( years Ġ= Ġ 1 , Ġmonths Ġ= Ġ 2 , Ġdays Ġ= Ġ 3 , Ġhours Ġ= Ġ 4 , Ġminutes Ġ= Ġ 5 , Ġseconds Ġ= Ġ 6 , Ġnan oseconds Ġ= Ġ 7 ), Ġtime Zone Ġ= ĠTime Zone . UTC ) ĊĊĉ ĉ clock . set ( epoch ) ĊĊĉ ĉ clock . advance () Ġ// Ġodd , Ġshould Ġwe Ġprevent Ġthis ? Ċĉ ĉ clock . advance ( seconds ( 0 )) Ċĉ ĉ clock . advance ( hours Ġ= Ġ 0 ) Ċĉ ĉ clock . advance ( period Ġ= ĠDate Period (), Ġtime Zone Ġ= ĠTime Zone . UTC ) Ċĉ ĉ clock . advance ( period Ġ= ĠDateTime Period (), Ġtime Zone Ġ= ĠTime Zone . UTC ) Ċĉ ĉ assertEquals ( expected Ġ= Ġepoch , Ġactual Ġ= Ġclock . now ()) ĊĊĉ ĉ clock . advance ( duration Ġ= Ġhours ( 1 ) Ġ+ Ġminutes ( 2 ) Ġ+ Ġseconds ( 3 ) Ġ+ Ġnan oseconds ( 4 )) Ċĉ ĉ assertEquals ( expected Ġ= Ġa Little After Epoch , Ġactual Ġ= Ġclock . now ()) ĊĊĉ ĉ clock . set ( epoch ) Ċĉ ĉ clock . advance ( hours Ġ= Ġ 1 , Ġminutes Ġ= Ġ 2 , Ġseconds Ġ= Ġ 3 , Ġnan oseconds Ġ= Ġ 4 ) Ċĉ ĉ assertEquals ( expected Ġ= Ġa Little After Epoch , Ġactual Ġ= Ġclock . now ()) ĊĊĉ ĉ clock . set ( epoch ) Ċĉ ĉ clock . advance ( period Ġ= ĠDateTime Period ( 1 , Ġ 2 , Ġ 3 , Ġ 4 , Ġ 5 , Ġ 6 , Ġ 7 ), Ġtime Zone Ġ= ĠTime Zone . UTC ) Ċĉ ĉ assertEquals ( expected Ġ= Ġa Lot After Epoch , Ġactual Ġ= Ġclock . now ()) ĊĊĉ ĉ clock . set ( epoch ) Ċĉ ĉ clock . advance ( years Ġ= Ġ 1 , Ġmonths Ġ= Ġ 2 , Ġdays Ġ= Ġ 3 , Ġhours Ġ= Ġ 4 , Ġminutes Ġ= Ġ 5 , Ġseconds Ġ= Ġ 6 , Ġnan oseconds Ġ= Ġ 7 , Ġtime Zone Ġ= ĠTime Zone . UTC ) Ċĉ ĉ assertEquals ( expected Ġ= Ġa Lot After Epoch , Ġactual Ġ= Ġclock . now ()) Ċ ĉ } ĊĊĊ ĉ @ Test Ċ ĉ fun Ġtest Now () Ġ{ Ċĉ ĉ val Ġclock Ġ= ĠManual Clock () Ċĉ ĉ assertNull ( clock . now OrNull ()) Ċĉ ĉ assert Fails With < IllegalStateException > Ġ{ Ġclock . now () Ġ} ĊĊĉ ĉ val Ġtimestamp Ġ= ĠTimestamp . from Epoch Seconds ( 0 ) Ċĉ ĉ clock . set ( timestamp ) ĊĊĉ ĉ assertEquals ( expected Ġ= Ġtimestamp , Ġactual Ġ= Ġclock . now ()) Ċĉ ĉ assertEquals ( expected Ġ= Ġtimestamp , Ġactual Ġ= Ġclock . now OrNull ()) ĊĊĉ ĉ clock . set ( null ) Ċĉ ĉ assertNull ( clock . now OrNull ()) Ċĉ ĉ assert Fails With < IllegalStateException > Ġ{ Ġclock . now () Ġ} Ċ ĉ } ĊĊĊ ĉ @ Test Ċ ĉ fun Ġtest Set () Ġ{ Ċĉ ĉ val Ġclock Ġ= ĠManual Clock () Ċĉ ĉ val Ġepoch Ġ= ĠTimestamp . from Epoch Seconds ( 0 ) Ċĉ ĉ val Ġa Little After Epoch Ġ= Ġepoch . plus ( DateTime Period ( hours Ġ= Ġ 1 , Ġminutes Ġ= Ġ 2 , Ġseconds Ġ= Ġ 3 , Ġnan oseconds Ġ= Ġ 4 ), Ġtime Zone Ġ= ĠTime Zone . UTC ) ĊĊĉ ĉ clock . set ( date Ġ= ĠLocalDate ( 1 9 7 0 , Ġ 1 , Ġ 1 ), Ġtime Zone Ġ= ĠTime Zone . UTC ) Ċĉ ĉ assertEquals ( expected Ġ= Ġepoch , Ġactual Ġ= Ġclock . now ()) ĊĊĉ ĉ clock . set ( null ) Ċĉ ĉ assertNull ( clock . now OrNull ()) ĊĊĉ ĉ clock . set ( dateTime Ġ= ĠLocalDateTime ( 1 9 7 0 , Ġ 1 , Ġ 1 , Ġ 1 , Ġ 2 , Ġ 3 , Ġ 4 ), Ġtime Zone Ġ= ĠTime Zone . UTC ) Ċĉ ĉ assertEquals ( expected Ġ= Ġa Little After Epoch , Ġactual Ġ= Ġclock . now ()) ĊĊĉ ĉ clock . set ( null ) Ċĉ ĉ assertNull ( clock . now OrNull ()) ĊĊĉ ĉ clock . set ( year Ġ= Ġ 1 9 7 0 , Ġmonth Ġ= Ġ 1 , Ġday Ġ= Ġ 1 , Ġhour Ġ= Ġ 1 , Ġminute Ġ= Ġ 2 , Ġsecond Ġ= Ġ 3 , Ġnan ose cond Ġ= Ġ 4 , Ġtime Zone Ġ= ĠTime Zone . UTC ) Ċĉ ĉ assertEquals ( expected Ġ= Ġa Little After Epoch , Ġactual Ġ= Ġclock . now ()) Ċ ĉ } Ċ } Ċ