1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-06-28 15:27:43 +00:00
FrankerFaceZ/socketserver/cmd/statsweb/html.go

60 lines
1.6 KiB
Go
Raw Normal View History

2016-01-17 12:53:15 -08:00
package main
import (
"bitbucket.org/stendec/frankerfacez/socketserver/server"
2016-01-17 12:53:15 -08:00
"html/template"
"net/http"
"time"
)
type CalendarData struct {
Weeks []CalWeekData
}
type CalWeekData struct {
Days []CalDayData
}
type CalDayData struct {
NoData bool
Date int
2016-01-17 12:53:15 -08:00
UniqUsers int
}
type CalendarMonthInfo struct {
Year int
2016-01-17 12:53:15 -08:00
Month time.Month
// Ranges from -5 to +1.
// A value of +1 means the 1st of the month is a Sunday.
// A value of 0 means the 1st of the month is a Monday.
// A value of -5 means the 1st of the month is a Saturday.
FirstSundayOffset int
// True if the calendar for this month needs six sundays.
NeedSixSundays bool
}
func GetMonthInfo(at time.Time) CalendarMonthInfo {
year, month, _ := at.Date()
// 1 (start of month) - weekday of start of month = day offset of start of week at start of month
monthWeekStartDay := 1 - time.Date(year, month, 1, 0, 0, 0, 0, server.CounterLocation).Weekday()
// first day on calendar + 6 weeks < end of month?
sixthSundayDay := monthWeekStartDay + 5*7
sixthSundayDate := time.Date(year, month, sixthSundayDay, 0, 0, 0, 0, server.CounterLocation)
var needSixSundays bool = false
if sixthSundayDate.Month() == month {
needSixSundays = true
}
return CalendarMonthInfo{
Year: year,
Month: month,
2016-01-17 12:53:15 -08:00
FirstSundayOffset: monthWeekStartDay,
NeedSixSundays: needSixSundays,
2016-01-17 12:53:15 -08:00
}
}
func renderCalendar(w http.ResponseWriter, at time.Time) {
layout, err := template.ParseFiles("./webroot/layout.template.html", "./webroot/cal_entry.hbs", "./webroot/calendar.hbs")
data := CalendarData{}
data.Weeks = make([]CalWeekData, 6)
}