summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-08-28 15:51:40 +0200
committerKevin Chabowski <kevin@kch42.de>2013-08-28 15:52:31 +0200
commitfa85fb714847545afefd2659701d5ff01ea3a0a7 (patch)
tree8fa8b3eebab7809582acc9920c847356f056d0f2
parent24a1a8b96f133ff84ede87e13f4ffd7c7b316606 (diff)
downloadmailremind-fa85fb714847545afefd2659701d5ff01ea3a0a7.tar.gz
mailremind-fa85fb714847545afefd2659701d5ff01ea3a0a7.tar.bz2
mailremind-fa85fb714847545afefd2659701d5ff01ea3a0a7.zip
Added MultiChronos
-rw-r--r--chronos/chronos.go53
1 files changed, 52 insertions, 1 deletions
diff --git a/chronos/chronos.go b/chronos/chronos.go
index 1d2c943..74fec19 100644
--- a/chronos/chronos.go
+++ b/chronos/chronos.go
@@ -210,7 +210,7 @@ func ParseChronos(s string) (c Chronos, err error) {
return
}
c.Freq.Count = uint(count)
-
+
var ok bool
if c.Freq.Unit, ok = tuLookup[elems[3]]; !ok {
err = fmt.Errorf("Unknown timeunit %s", elems[3])
@@ -227,3 +227,54 @@ func ParseChronos(s string) (c Chronos, err error) {
return
}
+
+type MultiChronos []Chronos
+
+func (mc MultiChronos) NextAfter(t time.Time) time.Time {
+ var nearest time.Time
+
+ for _, c := range mc {
+ next := c.NextAfter(t)
+ if next.IsZero() {
+ continue
+ }
+
+ if nearest.IsZero() {
+ nearest = next
+ } else if next.Before(nearest) {
+ nearest = next
+ }
+ }
+
+ return nearest
+}
+
+func (mc MultiChronos) String() (s string) {
+ sep := ""
+
+ for _, c := range mc {
+ s += sep + c.String()
+ sep = "\n"
+ }
+
+ return
+}
+
+func ParseMultiChronos(s string) (mc MultiChronos, err error) {
+ parts := strings.Split(s, "\n")
+ for l, _part := range parts {
+ part := strings.TrimSpace(_part)
+ if part == "" {
+ continue
+ }
+
+ c, err := ParseChronos(part)
+ if err != nil {
+ return nil, fmt.Errorf("Line %d: %s", l+1, err)
+ }
+
+ mc = append(mc, c)
+ }
+
+ return
+}