Created
September 28, 2016 08:13
-
-
Save hapo31/22310c017d4fe4e7f43f9c0eede3923a to your computer and use it in GitHub Desktop.
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
// エラーチェックはしてないのでいじめないで | |
// http://www.groovy-lang.org/ | |
import java.util.Calendar; | |
import java.text.SimpleDateFormat; | |
if(args.length <= 0) { | |
println("Usase:") | |
println("\tgroovy cal.groovy [YYYY-mm]") | |
return | |
} | |
def days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] | |
def temp = args[0].split("-") | |
def year = Integer.parseInt(temp[0]) | |
def month = Integer.parseInt(temp[1]) | |
def cal = Calendar.getInstance() | |
def putTr = false; | |
def today = cal.get(Calendar.DAY_OF_MONTH) | |
def tomonth = cal.get(Calendar.MONTH) | |
cal.set(year, month - 1, 1) | |
def firstDay = cal.get(Calendar.DAY_OF_WEEK) | |
def lastDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH) | |
println "<html>\r\n<head>" | |
println """ | |
<meta charset="SHIFT-JIS"> | |
<style> | |
td { | |
background-color: #efefef; | |
} | |
.SUN { | |
background-color: red; | |
} | |
.SAT { | |
background-color: blue; | |
color: white; | |
} | |
.TODAY { | |
background-color: yellow; | |
} | |
.NODAY { | |
background-color: gray; | |
} | |
</style> | |
""" | |
println "</head>\r\n<body>" | |
println "<h1>${year}-${month}</h1>" | |
println "<table>\r\n<tr>" | |
for(def d in days) { | |
print "<th class='${d}'>" | |
print d | |
println "</th>" | |
} | |
println "</tr><tr>" | |
for(def i = 1; i < firstDay; ++i) { // 1週目の穴を埋める | |
print "<td class='NODAY'>" | |
println "</td>" | |
} | |
for(def i = 1; i <= lastDays; ++i) { | |
cal.set(Calendar.DAY_OF_MONTH, i) | |
def day = cal.get(Calendar.DAY_OF_WEEK) | |
if(day == 1) { | |
println "<tr>" | |
} | |
def clazz = days[day-1]; | |
if(tomonth == month - 1 && i == today) clazz += " TODAY" | |
println "<td class='${clazz}'>${i}</td>" | |
if(day == 7) { | |
println "</tr>" | |
} | |
} | |
def lastDay = cal.get(Calendar.DAY_OF_WEEK) | |
for(def i = 0; i < 7 - lastDay; ++i) { // 最終週の穴を埋める | |
print "<td class='NODAY'>" | |
println "</td>" | |
putTr = true | |
} | |
if(putTr) println("</tr>") | |
println "</table>\r\n</body>\r\n</html>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment