2016-01-17 12:53:15 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2016-04-28 14:36:59 -07:00
|
|
|
|
2017-11-13 15:57:20 -08:00
|
|
|
"github.com/FrankerFaceZ/FrankerFaceZ/socketserver/server"
|
2016-01-17 12:53:15 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
type CalendarData struct {
|
|
|
|
Weeks []CalWeekData
|
|
|
|
}
|
|
|
|
type CalWeekData struct {
|
|
|
|
Days []CalDayData
|
|
|
|
}
|
|
|
|
type CalDayData struct {
|
2016-01-17 14:09:09 -08:00
|
|
|
NoData bool
|
|
|
|
Date int
|
2016-01-17 12:53:15 -08:00
|
|
|
UniqUsers int
|
|
|
|
}
|
|
|
|
|
|
|
|
type CalendarMonthInfo struct {
|
2016-01-17 14:09:09 -08:00
|
|
|
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()
|
2016-01-17 16:50:17 -08:00
|
|
|
monthStartWeekday := time.Date(year, month, 1, 0, 0, 0, 0, server.CounterLocation).Weekday()
|
|
|
|
// 1 (start of month) - weekday of start of month = day offset of start of week at start of mont
|
|
|
|
monthWeekStartDay := 1 - int(monthStartWeekday)
|
2016-01-17 12:53:15 -08:00
|
|
|
// 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{
|
2016-01-17 14:09:09 -08:00
|
|
|
Year: year,
|
|
|
|
Month: month,
|
2016-01-17 12:53:15 -08:00
|
|
|
FirstSundayOffset: monthWeekStartDay,
|
2016-01-17 14:09:09 -08:00
|
|
|
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)
|
2016-01-17 16:50:17 -08:00
|
|
|
_ = layout
|
|
|
|
_ = err
|
2016-01-17 12:53:15 -08:00
|
|
|
}
|