Refactored time selecting
This commit is contained in:
parent
02794e9629
commit
cd8765e0f2
12 changed files with 122 additions and 56 deletions
29
helper.go
29
helper.go
|
|
@ -5,8 +5,9 @@ import (
|
|||
werr "git.gibonuddevalla.se/go/wrappederror"
|
||||
|
||||
// Standard
|
||||
"time"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var rxpTimezone *regexp.Regexp
|
||||
|
|
@ -15,7 +16,7 @@ func init() {
|
|||
rxpTimezone = regexp.MustCompile(`(\d\d)(\d\d)$`)
|
||||
}
|
||||
|
||||
func stringToTime(strTime string) (t time.Time, err error) {// {{{
|
||||
func stringToTime(strTime string) (t time.Time, err error) { // {{{
|
||||
// `date` command %z gives timezone like +0200 instead of +02:00.
|
||||
// This can easily be fixed here, not requiring all scripts to be fixed.
|
||||
t, err = time.Parse(time.RFC3339, strTime)
|
||||
|
|
@ -37,8 +38,8 @@ func stringToTime(strTime string) (t time.Time, err error) {// {{{
|
|||
}
|
||||
|
||||
return
|
||||
}// }}}
|
||||
func parseHTMLDateTime(str string, dflt time.Time) (t time.Time, err error) {
|
||||
} // }}}
|
||||
func parseHTMLDateTime(str string, dflt time.Time) (t time.Time, err error) { // {{{
|
||||
// Browser sending 2024-06-27T10:43 (16 characters) when seconds is 00.
|
||||
if len(str) == 16 {
|
||||
str += ":00"
|
||||
|
|
@ -52,4 +53,24 @@ func parseHTMLDateTime(str string, dflt time.Time) (t time.Time, err error) {
|
|||
}
|
||||
}
|
||||
return
|
||||
} // }}}
|
||||
|
||||
func applyTimeOffset(t time.Time, duration time.Duration, amountStr string) time.Time { // {{{
|
||||
amount, err := strconv.Atoi(amountStr)
|
||||
if err != nil {
|
||||
return t
|
||||
}
|
||||
|
||||
return t.Add(duration * time.Duration(amount))
|
||||
} // }}}
|
||||
func presetTimeInterval(duration time.Duration, presetStr string, timeFrom, timeTo *time.Time) () {
|
||||
if presetStr == "" {
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
presetTime, _ := strconv.Atoi(presetStr)
|
||||
(*timeFrom) = now.Add(duration * -1 * time.Duration(presetTime))
|
||||
(*timeTo) = now
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue