all repos — honk @ b60b88b850ecd6aa480df78600855bc79d634347

my fork of honk

handle durations for times
Ted Unangst tedu@tedunangst.com
Thu, 03 Oct 2019 00:11:02 -0400
commit

b60b88b850ecd6aa480df78600855bc79d634347

parent

dea3cb9d2c80622a1ff6273f60ac0fa87e0d3847

4 files changed, 32 insertions(+), 3 deletions(-)

jump to
M activity.goactivity.go

@@ -717,6 +717,12 @@ start, err := time.Parse(time.RFC3339, starttime)

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 @@ jo["tag"] = tags

} 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 {
M honk.gohonk.go

@@ -20,6 +20,7 @@ "fmt"

"html/template" "log" "os" + "strings" "time" )

@@ -101,10 +102,23 @@ Longitude float64

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 {
M views/honk.htmlviews/honk.html

@@ -44,6 +44,7 @@ <p>{{ .HTPrecis }}

<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 }}
M web.goweb.go

@@ -1054,8 +1054,8 @@ timestart := r.FormValue("timestart")

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())

@@ -1063,6 +1063,11 @@ }

t.StartTime = start break } + } + timeend := r.FormValue("timeend") + dur, err := time.ParseDuration(timeend) + if err == nil { + t.Duration = Duration(dur) } if !t.StartTime.IsZero() { honk.What = "event"