Skip to content

Commit

Permalink
fix use of time.TimeOnly
Browse files Browse the repository at this point in the history
Not available in earlier Go versions
  • Loading branch information
markuswustenberg committed Oct 9, 2024
1 parent f436d91 commit 8641527
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func start() error {
if r.Method == http.MethodPost && hxhttp.IsBoosted(r.Header) {
now = time.Now()

hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(time.TimeOnly))
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeOnly))

return partial(now), nil
}
Expand All @@ -62,9 +62,11 @@ func start() error {
return nil
}

const timeOnly = "15:04:05"

func page(now time.Time) Node {
return HTML5(HTML5Props{
Title: now.Format(time.TimeOnly),
Title: now.Format(timeOnly),

Head: []Node{
Script(Src("https://cdn.tailwindcss.com?plugins=forms,typography")),
Expand All @@ -75,7 +77,7 @@ func page(now time.Time) Node {
Div(Class("max-w-7xl mx-auto p-4 prose lg:prose-lg xl:prose-xl"),
H1(Text(`gomponents + HTMX`)),

P(Textf(`Time at last full page refresh was %v.`, now.Format(time.TimeOnly))),
P(Textf(`Time at last full page refresh was %v.`, now.Format(timeOnly))),

partial(now),

Expand All @@ -92,6 +94,6 @@ func page(now time.Time) Node {
}

func partial(now time.Time) Node {
return P(ID("partial"), Textf(`Time was last updated at %v.`, now.Format(time.TimeOnly)))
return P(ID("partial"), Textf(`Time was last updated at %v.`, now.Format(timeOnly)))
}
```
10 changes: 6 additions & 4 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func start() error {
if r.Method == http.MethodPost && hxhttp.IsBoosted(r.Header) {
now = time.Now()

hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(time.TimeOnly))
hxhttp.SetPushURL(w.Header(), "/?time="+now.Format(timeOnly))

return partial(now), nil
}
Expand All @@ -42,9 +42,11 @@ func start() error {
return nil
}

const timeOnly = "15:04:05"

func page(now time.Time) Node {
return HTML5(HTML5Props{
Title: now.Format(time.TimeOnly),
Title: now.Format(timeOnly),

Head: []Node{
Script(Src("https://cdn.tailwindcss.com?plugins=forms,typography")),
Expand All @@ -55,7 +57,7 @@ func page(now time.Time) Node {
Div(Class("max-w-7xl mx-auto p-4 prose lg:prose-lg xl:prose-xl"),
H1(Text(`gomponents + HTMX`)),

P(Textf(`Time at last full page refresh was %v.`, now.Format(time.TimeOnly))),
P(Textf(`Time at last full page refresh was %v.`, now.Format(timeOnly))),

partial(now),

Expand All @@ -72,5 +74,5 @@ func page(now time.Time) Node {
}

func partial(now time.Time) Node {
return P(ID("partial"), Textf(`Time was last updated at %v.`, now.Format(time.TimeOnly)))
return P(ID("partial"), Textf(`Time was last updated at %v.`, now.Format(timeOnly)))
}

0 comments on commit 8641527

Please sign in to comment.