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

BIN
plan.xlsx

Binary file not shown.

View File

@@ -6,14 +6,14 @@ import (
"github.com/b2dennis/meshi/xlsx"
)
var weekdays = [7]string{
var weekdays = []string{
"Sonntag",
"Montag",
"Dienstag",
"Mittwoch",
"Donnerstag",
"Freitag",
"Samstag",
"Sonntag",
}
templ Home(plan xlsx.Plan) {
@@ -31,7 +31,7 @@ templ Home(plan xlsx.Plan) {
@table.Header() {
@table.Row() {
@table.Head() {
Wochentag
Tag
}
@table.Head() {
Frühstück
@@ -44,7 +44,7 @@ templ Home(plan xlsx.Plan) {
}
}
}
for i,day := range(weekdays) {
for i := 0; i <= 6; i++ {
{{
class := ""
if i == 6 {
@@ -53,11 +53,11 @@ templ Home(plan xlsx.Plan) {
}}
@table.Row(table.RowProps{Class: class}) {
@table.Cell() {
{day}
{weekdays[plan[i][0].Date.Weekday()]}, {plan[i][0].Date.Format("02.01.2006")}
}
for _, menu := range plan.Menus[i] {
for _, menu := range plan[i] {
@table.Cell() {
{menu}
{menu.Text}
}
}
}

View File

@@ -14,14 +14,14 @@ import (
"github.com/b2dennis/meshi/xlsx"
)
var weekdays = [7]string{
var weekdays = []string{
"Sonntag",
"Montag",
"Dienstag",
"Mittwoch",
"Donnerstag",
"Freitag",
"Samstag",
"Sonntag",
}
func Home(plan xlsx.Plan) templ.Component {
@@ -109,7 +109,7 @@ func Home(plan xlsx.Plan) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "Wochentag")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "Tag")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -209,7 +209,7 @@ func Home(plan xlsx.Plan) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for i, day := range weekdays {
for i := 0; i <= 6; i++ {
class := ""
if i == 6 {
class = "border-b-0"
@@ -239,22 +239,35 @@ func Home(plan xlsx.Plan) templ.Component {
}
ctx = templ.InitializeContext(ctx)
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(day)
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(weekdays[plan[i][0].Date.Weekday()])
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/pages/home.templ`, Line: 56, Col: 36}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/pages/home.templ`, Line: 56, Col: 68}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, ", ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(plan[i][0].Date.Format("02.01.2006"))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/pages/home.templ`, Line: 56, Col: 108}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = table.Cell().Render(templ.WithChildren(ctx, templ_7745c5c3_Var11), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
for _, menu := range plan.Menus[i] {
templ_7745c5c3_Var13 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
for _, menu := range plan[i] {
templ_7745c5c3_Var14 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer {
@@ -266,18 +279,18 @@ func Home(plan xlsx.Plan) templ.Component {
}()
}
ctx = templ.InitializeContext(ctx)
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(menu)
var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(menu.Text)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/pages/home.templ`, Line: 60, Col: 41}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `ui/pages/home.templ`, Line: 60, Col: 46}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
return nil
})
templ_7745c5c3_Err = table.Cell().Render(templ.WithChildren(ctx, templ_7745c5c3_Var13), templ_7745c5c3_Buffer)
templ_7745c5c3_Err = table.Cell().Render(templ.WithChildren(ctx, templ_7745c5c3_Var14), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -301,7 +314,7 @@ func Home(plan xlsx.Plan) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "</body></html>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "</body></html>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}

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
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)
}
}
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)}))
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{Menus: menus}, err
return plan, err
}