add date parsing

This commit is contained in:
2025-12-15 09:48:39 +00:00
parent 16ec9a6e7c
commit f38c1715fc
4 changed files with 84 additions and 28 deletions

View File

@@ -1,23 +1,66 @@
package xlsx
import (
"fmt"
"strconv"
"time"
"github.com/xuri/excelize/v2"
)
type Plan struct {
Menus [7][3]string
type Plan = [7][3]struct {
Text string
Date time.Time
}
func Load() (Plan, error) {
f, err := excelize.OpenFile("./plan.xlsx")
defer func() {
err := f.Close()
if err != nil {
fmt.Println(err)
}
}()
if err != nil {
return Plan{}, err
}
var menus [7][3]string
for x := 0; x <= 2; x++ {
for y := 0; y <= 6; y++ {
menus[y][x], err = f.GetCellValue("Menüplan", string([]rune{rune('B' + x), rune('2' + y)}))
var plan [7][3]struct {
Text string
Date time.Time
}
today := time.Now().Format("01-02-06")
v := ""
offset := 1
for v != today {
offset++
v, err = f.GetCellValue("Menüplan", "A"+strconv.Itoa(offset))
if err != nil {
fmt.Println(err)
}
}
return Plan{Menus: menus}, err
for x := 0; x <= 2; x++ {
for y := 0; y <= 6; y++ {
plan[y][x] = struct {
Text string
Date time.Time
}{}
plan[y][x].Text, err = f.GetCellValue("Menüplan", string([]rune{rune('B' + x)})+strconv.Itoa(y+offset))
if err != nil {
fmt.Println(err)
continue
}
datestr, err := f.GetCellValue("Menüplan", "A"+strconv.Itoa(y+offset))
if err != nil {
fmt.Println(err)
continue
}
time, err := time.Parse("01-02-06", datestr)
if err != nil {
fmt.Println(err)
continue
}
plan[y][x].Date = time
}
}
return plan, err
}