Skip to content

Instantly share code, notes, and snippets.

@nobusue
Created November 5, 2011 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobusue/1341385 to your computer and use it in GitHub Desktop.
Save nobusue/1341385 to your computer and use it in GitHub Desktop.
calコマンド: groovy cal.groovy <year> <month>
import static java.util.Calendar.*
def cal = Calendar.instance
def year = cal[YEAR]
def month = cal[MONTH]
if(args && args[0] && args[0].isInteger() && args[1] && args[1].isInteger()) {
year = args[0].toInteger()
month = args[1].toInteger()
cal[YEAR] = year
cal[MONTH] = (month-1) % 12
}
def String[][] calMatrix = new String[6][7]
def days, firstDow
println "${cal[YEAR]}/${cal[MONTH]+1}"
cal[DATE] = 1
days = cal.getActualMaximum(DATE)
firstDow = cal[DAY_OF_WEEK]
(0..5).each{ week ->
(0..6).each{ day ->
calMatrix[week][day] = " "*3
}
}
(1..days).each{ d ->
def day = (d + firstDow - 2) % 7
def week = (d + firstDow -2).intdiv(7)
calMatrix[week][day] = d.toString().padLeft(3," ")
}
println "Sun Mon Tue Wed Thu Fri Sat"
calMatrix.each{ week ->
println week.join(" ")
}
@nobusue
Copy link
Author

nobusue commented Nov 5, 2011

CalendarクラスのGDKのサンプルとして

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment