Class tag support, add Adabelle
This commit is contained in:
42
tag.go
Normal file
42
tag.go
Normal file
@@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user