Created
November 5, 2011 10:54
-
-
Save nobusue/1341385 to your computer and use it in GitHub Desktop.
calコマンド: groovy cal.groovy <year> <month>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(" ") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CalendarクラスのGDKのサンプルとして