Skip to content

Commit d25ec70

Browse files
committed
Add app/CLIApp
1 parent 8182ab3 commit d25ec70

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package app
2+
3+
import util.DateUtil
4+
import scala.annotation.tailrec
5+
import scala.io.StdIn.readLine
6+
import scala.util.{Success, Try}
7+
8+
object CLIApp extends App {
9+
val date1 = DateUtil.str2Date(getInput)
10+
val date2 = DateUtil.str2Date(getInput)
11+
println(s"date1: ${DateUtil.date2Str(date1)}")
12+
println(s"date2: ${DateUtil.date2Str(date2)}")
13+
println(s"yearsBetween: ${DateUtil.yearsBetween(date1, date2)}")
14+
println(s"compare : ${DateUtil.compare(date1, date2)}")
15+
16+
@tailrec
17+
def getInput: String = {
18+
println("入力してください (例: 2020-01-01)")
19+
val input = readLine()
20+
21+
Try(DateUtil.str2Date(input)) match {
22+
case Success(_) => input
23+
case _ => getInput
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)