Temp timezone fix #11

Merged
Jannover5000r merged 22 commits from temp-timezoneFix into main 2026-08-23 00:02:29 +02:00
2 changed files with 53 additions and 5 deletions
Showing only changes of commit b3628700ae - Show all commits

2
.gitignore vendored
View file

@ -11,3 +11,5 @@ login_*.json
AGENTS.md AGENTS.md
untislogger untislogger
untislogger* untislogger*
CHANGES_SUMMARY.md

48
main.go
View file

@ -186,6 +186,12 @@ func scheduleTimetableUpdate() {
// Build maps keyed by a stable lesson identifier // Build maps keyed by a stable lesson identifier
currMap := make(map[string]NamedTimetableEntry) currMap := make(map[string]NamedTimetableEntry)
prevMap := make(map[string]NamedTimetableEntry) prevMap := make(map[string]NamedTimetableEntry)
// Also build timeslot-based maps for better exchange detection
currTimeslotMap := make(map[string]NamedTimetableEntry)
prevTimeslotMap := make(map[string]NamedTimetableEntry)
// Get current date to filter out new day changes
today := time.Now().Format("02-01-2006")
for _, e := range currentEntries { for _, e := range currentEntries {
key := lessonKey(e) key := lessonKey(e)
@ -200,6 +206,11 @@ func scheduleTimetableUpdate() {
// Check for modified or new lessons // Check for modified or new lessons
for key, curr := range currMap { for key, curr := range currMap {
// Skip lessons that are not for today to avoid new day spam
if curr.Date != today {
continue
}
if prev, exists := prevMap[key]; exists { if prev, exists := prevMap[key]; exists {
// Existing lesson — check for changes // Existing lesson — check for changes
subject := getSubject(curr) subject := getSubject(curr)
@ -211,6 +222,21 @@ func scheduleTimetableUpdate() {
changes = append(changes, fmt.Sprintf("Room changed for %s: %s → %s", subject, oldRoom, newRoom)) changes = append(changes, fmt.Sprintf("Room changed for %s: %s → %s", subject, oldRoom, newRoom))
} }
for _, e := range currentEntries {
key := lessonKey(e)
currMap[key] = e
// Create timeslot key (date + startTime + endTime)
timeslotKey := e.Date + "|" + e.StartTime + "|" + e.EndTime
currTimeslotMap[timeslotKey] = e
}
for _, e := range prevEntries {
key := lessonKey(e)
prevMap[key] = e
// Create timeslot key (date + startTime + endTime)
timeslotKey := e.Date + "|" + e.StartTime + "|" + e.EndTime
prevTimeslotMap[timeslotKey] = e
}
// Code/status change? // Code/status change?
if prev.Code != curr.Code { if prev.Code != curr.Code {
oldStatus := formatStatus(prev.Code) oldStatus := formatStatus(prev.Code)
@ -218,20 +244,40 @@ func scheduleTimetableUpdate() {
changes = append(changes, fmt.Sprintf("Status changed for %s: %s → %s", subject, oldStatus, newStatus)) changes = append(changes, fmt.Sprintf("Status changed for %s: %s → %s", subject, oldStatus, newStatus))
} }
} else { } else {
// New lesson // New lesson - but check if it's actually an exchange in the same timeslot
timeslotKey := curr.Date + "|" + curr.StartTime + "|" + curr.EndTime
if prevInTimeslot, exists := prevTimeslotMap[timeslotKey]; exists {
// This is an exchange: old lesson was removed, new one added in same timeslot
oldSubject := getSubject(prevInTimeslot)
newSubject := getSubject(curr)
room := formatRoom(curr.Ro)
changes = append(changes, fmt.Sprintf("Lesson exchanged: %s → %s in %s", oldSubject, newSubject, room))
} else {
// Truly new lesson
subject := getSubject(curr) subject := getSubject(curr)
room := formatRoom(curr.Ro) room := formatRoom(curr.Ro)
changes = append(changes, fmt.Sprintf("New lesson: %s in %s", subject, room)) changes = append(changes, fmt.Sprintf("New lesson: %s in %s", subject, room))
} }
} }
}
// Check for removed lessons // Check for removed lessons
for key, prev := range prevMap { for key, prev := range prevMap {
// Skip lessons that were not for today
if prev.Date != today {
continue
}
if _, exists := currMap[key]; !exists { if _, exists := currMap[key]; !exists {
subject := getSubject(prev) subject := getSubject(prev)
// Check if this removal is part of an exchange (already handled above)
timeslotKey := prev.Date + "|" + prev.StartTime + "|" + prev.EndTime
if _, newExists := currTimeslotMap[timeslotKey]; !newExists {
// Only report as removed if no new lesson took its place
changes = append(changes, fmt.Sprintf("Lesson removed: %s", subject)) changes = append(changes, fmt.Sprintf("Lesson removed: %s", subject))
} }
} }
}
// Send notification if changes detected // Send notification if changes detected
if len(changes) > 0 { if len(changes) > 0 {