generate recurring days in the future
This commit is contained in:
parent
d3cc6f4206
commit
95c929f8df
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"git.sr.ht/~ewintr/gte/internal/task"
|
"git.sr.ht/~ewintr/gte/internal/task"
|
||||||
"git.sr.ht/~ewintr/gte/pkg/mstore"
|
"git.sr.ht/~ewintr/gte/pkg/mstore"
|
||||||
|
@ -17,6 +18,10 @@ func main() {
|
||||||
if !config.Valid() {
|
if !config.Valid() {
|
||||||
log.Fatal("please set IMAP_USER, IMAP_PASSWORD, etc environment variables")
|
log.Fatal("please set IMAP_USER, IMAP_PASSWORD, etc environment variables")
|
||||||
}
|
}
|
||||||
|
daysAhead, err := strconv.Atoi(os.Getenv("GTE_DAYS_AHEAD"))
|
||||||
|
if err != nil {
|
||||||
|
daysAhead = 0
|
||||||
|
}
|
||||||
|
|
||||||
mailStore, err := mstore.ImapConnect(config)
|
mailStore, err := mstore.ImapConnect(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -29,9 +34,10 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
rDate := task.Today.AddDays(daysAhead)
|
||||||
for _, t := range tasks {
|
for _, t := range tasks {
|
||||||
if t.RecursToday() {
|
if t.RecursOn(rDate) {
|
||||||
subject, body, err := t.CreateDueMessage(task.Today)
|
subject, body, err := t.CreateDueMessage(rDate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,11 +250,15 @@ func (t *Task) IsRecurrer() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) RecursToday() bool {
|
func (t *Task) RecursToday() bool {
|
||||||
|
return t.RecursOn(Today)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Task) RecursOn(date Date) bool {
|
||||||
if !t.IsRecurrer() {
|
if !t.IsRecurrer() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.Recur.RecursOn(Today)
|
return t.Recur.RecursOn(date)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) CreateDueMessage(date Date) (string, string, error) {
|
func (t *Task) CreateDueMessage(date Date) (string, string, error) {
|
||||||
|
|
Loading…
Reference in New Issue