mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 01:35:56 +01:00
Multi-day events are always daytime
This commit is contained in:
parent
338d8b9834
commit
eae40012bf
2 changed files with 11 additions and 8 deletions
|
@ -17,7 +17,7 @@
|
|||
{{ $events := dict }}
|
||||
{{ range $page := .Data.Pages }}
|
||||
{{ range $page.Params.timings }}
|
||||
{{ $event := dict "Title" $page.Title "Page" $page.Page "Date" (time.AsTime .starts) }}
|
||||
{{ $event := dict "Title" $page.Title "Page" $page.Page "Date" (time.AsTime .starts) "Duration" (partial "iso8601.duration" .duration) }}
|
||||
{{ if $event.Date.Before time.Now }}{{ continue }}{{ end }}
|
||||
{{ $bundle := $event.Date.Format "Jan 2006" }}
|
||||
{{ $events = merge $events (dict $bundle (sort ((index $events $bundle) | append $event) "Date" "asc")) }}
|
||||
|
@ -35,7 +35,10 @@
|
|||
{{ if .Page.Params.emoji }}<span class="post-emoji">{{ .Page.Params.emoji }}</span>{{ end }}
|
||||
<span class="post-title">{{.Page.Title}}</span>
|
||||
<span class="post-day">
|
||||
{{ .Date.Format "Jan 2"}} <span class="daytime">{{ if or (lt (.Date.Format "15") 9) (gt (.Date.Format "15") 17) }}☾{{ else }}☀︎{{ end }}</span>
|
||||
{{- $hour := .Date.Format "15" -}}
|
||||
{{- $duration := .Duration.Hours -}}
|
||||
{{- $daytime := or (ge $duration 24) (and (gt $hour 9) (lt $hour 17)) }}
|
||||
{{ .Date.Format "Jan 2"}} <span class="daytime">{{ if $daytime }}☀︎{{ else }}☾{{ end }}</span>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
{{ $timePart := (index $parts 1 | strings.ToLower) }}
|
||||
{{ if eq $timePart "" }}{{ $timePart = "0s" }}{{ end }}
|
||||
{{ $duration := time.ParseDuration $timePart }}
|
||||
{{ $dayPart := replaceRE `^(\d+)D$` `$1` (index $parts 0) }}
|
||||
{{ with $dayPart }}
|
||||
{{ $dayCount := replaceRE `^(\d+)D$` `$1` (index $parts 0) }}
|
||||
{{ with $dayCount }}
|
||||
{{ $asHours := printf "%dh" (mul (int .) 24) }}
|
||||
{{ $origin := time.Now }}
|
||||
{{ $origin.Add (time.ParseDuration $asHours) }}
|
||||
{{ $origin.Add $duration }}
|
||||
{{ $duration = $origin.Sub $origin }}
|
||||
{{ $origin := time "1970-01-01" }}
|
||||
{{ $later := $origin.Add (time.ParseDuration $asHours) }}
|
||||
{{ $later = $later.Add $duration }}
|
||||
{{ $duration = $later.Sub $origin }}
|
||||
{{ end }}
|
||||
{{ return $duration }}
|
||||
|
|
Loading…
Reference in a new issue