Files
helioscal/tag.go
2020-09-13 21:27:40 +00:00

43 lines
679 B
Go

package main
import (
"fmt"
"strings"
"time"
)
type TagChange struct {
Start string
Value string
}
type TagChangeList []TagChange
type TagKey string
type TagMap map[TagKey]TagChangeList
func getTagAt(key string, t time.Time) (string, error) {
// Guaranteed to be in local time
date := t.Format("2006-01-02")
tagChanges := tags[TagKey(key)]
if tagChanges == nil {
return "", fmt.Errorf("tag key not found: %s", key)
}
value := ""
for _, change := range tagChanges {
if strings.Compare(change.Start, date) > 0 {
break
}
value = change.Value
}
if value == "" {
return "", fmt.Errorf("tag key '%s' has no value yet", key)
}
return value, nil
}