Skip to content

Instantly share code, notes, and snippets.

@taisukeoe
Created September 1, 2014 15:43
Show Gist options
  • Save taisukeoe/1248bf6d97f43af35918 to your computer and use it in GitHub Desktop.
Save taisukeoe/1248bf6d97f43af35918 to your computer and use it in GitHub Desktop.
某勉強会の予定を調整さんに投げる用プロジェクト
scalaVersion := "2.11.0"
libraryDependencies += "com.github.nscala-time" %% "nscala-time" % "1.4.0"
import com.github.nscala_time.time.Imports._
import annotation.tailrec
import org.joda.time.DateTimeConstants
object Calculator extends App{
val start = nextMonday(DateTime.now.toLocalDate)
val days = start :: Stream.iterate(start + 1.day)(_ + 1.day).takeWhile(_.getDayOfWeek != DateTimeConstants.MONDAY).toList
val result = days.map {
d =>
val base = d.toString("M月d日(E)")
if(d.getDayOfWeek >= DateTimeConstants.SATURDAY)
base+" 10:00~\n"+base+" 22:00~"
else
base
}
result.foreach(println)
def nextMonday(start:LocalDate):LocalDate = {
@tailrec
def doCheckNextMonday(in:LocalDate):LocalDate = {
val tomorrow = in + 1.day
if (tomorrow.getDayOfWeek == DateTimeConstants.MONDAY)
tomorrow
else
doCheckNextMonday(tomorrow)
}
doCheckNextMonday(start)
}
}
$ sbt run
[info] Running Calculator
9月8日(月)
9月9日(火)
9月10日(水)
9月11日(木)
9月12日(金)
9月13日(土) 10:00~
9月13日(土) 22:00~
9月14日(日) 10:00~
9月14日(日) 22:00~
[success] Total time: 1 s, completed 2014/09/02 0:43:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment