mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-26 17:03:01 +00:00
Fix time duration value
- Make sure that duration is not < 0 - Handle nil ExpiresAt time in poll
This commit is contained in:
parent
fe31d4197b
commit
dd23ac4867
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
type Poll struct {
|
type Poll struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
ExpiresAt time.Time `json:"expires_at"`
|
ExpiresAt *time.Time `json:"expires_at"`
|
||||||
Expired bool `json:"expired"`
|
Expired bool `json:"expired"`
|
||||||
Multiple bool `json:"multiple"`
|
Multiple bool `json:"multiple"`
|
||||||
VotesCount int64 `json:"votes_count"`
|
VotesCount int64 `json:"votes_count"`
|
||||||
|
@ -197,11 +197,19 @@ func DurToStr(dur time.Duration) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TimeSince(t time.Time) string {
|
func TimeSince(t time.Time) string {
|
||||||
return DurToStr(time.Since(t))
|
d := time.Since(t)
|
||||||
|
if d < 0 {
|
||||||
|
d = 0
|
||||||
|
}
|
||||||
|
return DurToStr(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TimeUntil(t time.Time) string {
|
func TimeUntil(t time.Time) string {
|
||||||
return DurToStr(time.Until(t))
|
d := time.Until(t)
|
||||||
|
if d < 0 {
|
||||||
|
d = 0
|
||||||
|
}
|
||||||
|
return DurToStr(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatTimeRFC3339(t time.Time) string {
|
func FormatTimeRFC3339(t time.Time) string {
|
||||||
|
@ -126,7 +126,7 @@
|
|||||||
<span>{{.Poll.VotesCount}} votes</span>
|
<span>{{.Poll.VotesCount}} votes</span>
|
||||||
{{if .Poll.Expired}}
|
{{if .Poll.Expired}}
|
||||||
<span> - poll expired </span>
|
<span> - poll expired </span>
|
||||||
{{else}}
|
{{else if .Poll.ExpiresAt}}
|
||||||
<span>
|
<span>
|
||||||
- poll ends in
|
- poll ends in
|
||||||
<time datetime="{{FormatTimeRFC3339 .Poll.ExpiresAt}}" title="{{FormatTimeRFC822 .Poll.ExpiresAt}}">
|
<time datetime="{{FormatTimeRFC3339 .Poll.ExpiresAt}}" title="{{FormatTimeRFC822 .Poll.ExpiresAt}}">
|
||||||
|
Loading…
Reference in New Issue
Block a user