Skip to content

Instantly share code, notes, and snippets.

@chuckwagoncomputing
Created November 19, 2021 23:12
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 chuckwagoncomputing/53a820fea4797629c71c2e2c3ff53cd7 to your computer and use it in GitHub Desktop.
Save chuckwagoncomputing/53a820fea4797629c71c2e2c3ff53cd7 to your computer and use it in GitHub Desktop.
Calendar Generator
package main
import (
"os"
"fmt"
"time"
)
func main () {
year := 2022
t := time.Date(year, 1, 1, 0, 0, 0, 0, time.UTC)
f, err := os.Create("calendar.html")
if err != nil {
fmt.Println("Error creating file")
}
defer f.Close()
f.WriteString("<html><head><link rel=\"stylesheet\" href=\"layout.css\"><link rel=\"stylesheet\" href=\"styles.css\"></head><body>")
for ; t.Year() == year; t = t.AddDate(0, 0, 1) {
if t.Day() == 1 {
f.WriteString("<div class=\"month\"><div class=\"monthHeading\">" + t.Month().String() + " " + fmt.Sprintf("%d", year) + "</div>")
f.WriteString("<table class=\"monthTable\">")
f.WriteString("<tr class=\"dayNames\"><td><div>Sun</div></td><td><div>Mon</div></td><td><div>Tues</div></td><td><div>Wed</div></td><td><div>Thu</div></td><td><div>Fri</div></td><td><div>Sat</div></td></tr><tr>")
for i := 0; i < int(t.Weekday()); i++ {
l := fmt.Sprintf("%d", t.AddDate(0, 0, 0 + i - int(t.Weekday())).Day())
f.WriteString("<td class=\"otherDay\"><p>" + l + "</p></td>")
}
}
if (t.Weekday() == 0) {
f.WriteString("<tr>")
}
f.WriteString("<td class=\"monthDay\">")
f.WriteString("<p>" + fmt.Sprintf("%d", t.Day()) + "</p>")
f.WriteString("<div contentEditable=\"true\" class=\"eventInput\"></div>")
f.WriteString("</td>")
if (t.Weekday() == 6) {
f.WriteString("</tr>")
}
if t.Day() == time.Date(t.Year(), t.Month() + 1, 0, 0, 0, 0, 0, time.UTC).Day() {
for c := 1; c <= (6 - int(t.Weekday())); c++ {
f.WriteString("<td class=\"otherDay\"><p>" + fmt.Sprintf("%d", c) + "</p></td>")
}
f.WriteString("</tr></table></div>")
}
}
f.WriteString("</body></html>")
}
html, body {
padding: 1px;
margin: 0px;
}
.month {
page-break-after: always;
}
@page {
size: letter landscape;
margin: 15px;
}
.monthHeading {
height: 10%;
text-align: center;
}
.monthTable {
margin-left: 1px;
width: 100%;
height: 90%;
border-collapse: collapse;
}
.monthTable td {
padding: 0px;
margin: 0px;
position: relative;
width: 1%;
}
.monthTable td p {
top: 0;
left: 5px;
position: absolute;
}
.dayNames td {
text-align: center;
padding: 0px;
margin: 0px;
}
.eventInput {
border: none;
background: white;
width: 98%;
padding: 0px;
margin: 0px;
bottom: 0;
left: 0;
margin-left: 2px;
position: absolute;
}
.monthHeading {
font: 48px "Dynalight", cursive;
}
.monthTable td {
vertical-align: top;
border: 1px solid black;
}
.dayNames, .dayNames * {
height: 29px;
}
.dayNames td {
font: 48px "Dynalight", cursive;
border: none;
font-size: 24px;
}
.otherDay {
color: transparent;
text-shadow: 0 0 0 #aaa;
}
.monthTable td p {
font: 48px "Dynalight", cursive;
font-size: 24px;
}
.eventInput {
font: 14px "Dynalight", cursive;
min-height: 12px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment