handle durations for times
This commit is contained in:
parent
99f0e73394
commit
3cd2f57f9e
|
@ -717,6 +717,12 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
|||
if err == nil {
|
||||
t := new(Time)
|
||||
t.StartTime = start
|
||||
dura, _ := obj.GetString("duration")
|
||||
if strings.HasPrefix(dura, "PT") {
|
||||
dura = strings.ToLower(dura[2:])
|
||||
d, _ := time.ParseDuration(dura)
|
||||
t.Duration = Duration(d)
|
||||
}
|
||||
xonk.Time = t
|
||||
}
|
||||
}
|
||||
|
@ -1002,6 +1008,9 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
|
|||
}
|
||||
if t := h.Time; t != nil {
|
||||
jo["startTime"] = t.StartTime.Format(time.RFC3339)
|
||||
if t.Duration != 0 {
|
||||
jo["duration"] = "PT" + strings.ToUpper(t.Duration.String())
|
||||
}
|
||||
}
|
||||
var atts []junk.Junk
|
||||
for _, d := range h.Donks {
|
||||
|
|
16
honk.go
16
honk.go
|
@ -20,6 +20,7 @@ import (
|
|||
"html/template"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -101,10 +102,23 @@ type Place struct {
|
|||
Url string
|
||||
}
|
||||
|
||||
type Duration int64
|
||||
|
||||
func (d Duration) String() string {
|
||||
s := time.Duration(d).String()
|
||||
if strings.HasSuffix(s, "m0s") {
|
||||
s = s[:len(s)-2]
|
||||
}
|
||||
if strings.HasSuffix(s, "h0m") {
|
||||
s = s[:len(s)-2]
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
type Time struct {
|
||||
StartTime time.Time
|
||||
EndTime time.Time
|
||||
Duration time.Duration
|
||||
Duration Duration
|
||||
}
|
||||
|
||||
type Honker struct {
|
||||
|
|
|
@ -44,6 +44,7 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
|
|||
<p>{{ .HTML }}
|
||||
{{ with .Time }}
|
||||
<p>Time: {{ .StartTime.Local.Format "03:04PM EDT Mon Jan 02"}}
|
||||
{{ if .Duration }}<br>Duration: {{ .Duration }}{{ end }}
|
||||
{{ end }}
|
||||
{{ with .Place }}
|
||||
<p>Location: {{ with .Url }}<a href="{{ . }}" rel=noreferrer>{{ end }}{{ .Name }}{{ if .Url }}</a>{{ end }}{{ if or .Latitude .Longitude }} <a href="https://www.openstreetmap.org/?mlat={{ .Latitude }}&mlon={{ .Longitude}}" rel=noreferrer>{{ .Latitude }} {{ .Longitude }}</a>{{ end }}
|
||||
|
|
9
web.go
9
web.go
|
@ -1054,8 +1054,8 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
|
|||
if timestart != "" {
|
||||
t := new(Time)
|
||||
now := time.Now().Local()
|
||||
for _, layout := range []string{"3:04pm", "15:04"} {
|
||||
start, err := time.Parse(layout, timestart)
|
||||
for _, layout := range []string{"2006-01-02 3:04pm", "2006-01-02 15:04", "3:04pm", "15:04"} {
|
||||
start, err := time.ParseInLocation(layout, timestart, now.Location())
|
||||
if err == nil {
|
||||
if start.Year() == 0 {
|
||||
start = time.Date(now.Year(), now.Month(), now.Day(), start.Hour(), start.Minute(), 0, 0, now.Location())
|
||||
|
@ -1064,6 +1064,11 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
|
|||
break
|
||||
}
|
||||
}
|
||||
timeend := r.FormValue("timeend")
|
||||
dur, err := time.ParseDuration(timeend)
|
||||
if err == nil {
|
||||
t.Duration = Duration(dur)
|
||||
}
|
||||
if !t.StartTime.IsZero() {
|
||||
honk.What = "event"
|
||||
honk.Time = t
|
||||
|
|
Loading…
Reference in New Issue