Persistent Savings (#4956)

This commit is contained in:
Michael Geers 2022-10-25 22:05:03 +02:00 • committed by GitHub
parent 2905c0a3ee
commit cef8bb15fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 9 deletions

View file

@ -5,6 +5,7 @@ import (
"errors"
"strconv"
"sync/atomic"
"time"
"github.com/evcc-io/evcc/server/db"
"golang.org/x/exp/slices"
@ -62,6 +63,10 @@ func SetFloat(key string, val float64) {
SetString(key, strconv.FormatFloat(val, 'f', -1, 64))
}
func SetTime(key string, val time.Time) {
SetString(key, val.Format(time.RFC3339))
}
func SetJson(key string, val any) error {
b, err := json.Marshal(val)
if err == nil {
@ -96,6 +101,14 @@ func Float(key string) (float64, error) {
return strconv.ParseFloat(s, 64)
}
func Time(key string) (time.Time, error) {
s, err := String(key)
if err != nil {
return time.Now(), err
}
return time.Parse(time.RFC3339, s)
}
func Json(key string, res any) error {
s, err := String(key)
if err == nil {