Implemented SetIDFromDatabaseKey

This commit is contained in:
マリウス 2020-10-15 22:44:04 +01:00
parent 398460201e
commit 526fd502be
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F

View file

@ -2,6 +2,7 @@ package z
import ( import (
"errors" "errors"
"strings"
"time" "time"
"fmt" "fmt"
"github.com/gookit/color" "github.com/gookit/color"
@ -49,6 +50,17 @@ func NewEntry(
return newEntry, nil return newEntry, nil
} }
func (entry *Entry) SetIDFromDatabaseKey(key string) (error) {
splitKey := strings.Split(key, ":")
if len(splitKey) < 3 || len(splitKey) > 3 {
return errors.New("not a valid database key")
}
entry.ID = splitKey[2]
return nil
}
func (entry *Entry) SetBeginFromString(begin string) (time.Time, error) { func (entry *Entry) SetBeginFromString(begin string) (time.Time, error) {
var beginTime time.Time var beginTime time.Time
var err error var err error