aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-09 18:31:25 -0400
committerLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-09 18:31:25 -0400
commita6ace0db337948e940dfa430e780edccf25eabc9 (patch)
tree25dc5107a4bb878f5f2af684388c750202e1b727
parenta3fa964c585f62ccf4c4113da1dc324839122c88 (diff)
parent2d538ff43c9b73223e4af8f8668d0f4f1412e3ab (diff)
downloaddonetick-a6ace0db337948e940dfa430e780edccf25eabc9.tar.gz
donetick-a6ace0db337948e940dfa430e780edccf25eabc9.tar.bz2
donetick-a6ace0db337948e940dfa430e780edccf25eabc9.zip
Merge branch 'dev'
Diffstat (limited to '')
-rw-r--r--internal/chore/model/model.go1
-rw-r--r--internal/chore/scheduler.go12
-rw-r--r--internal/database/database.go8
3 files changed, 20 insertions, 1 deletions
diff --git a/internal/chore/model/model.go b/internal/chore/model/model.go
index 90f6c29..3fb7a92 100644
--- a/internal/chore/model/model.go
+++ b/internal/chore/model/model.go
@@ -47,6 +47,7 @@ type FrequencyMetadata struct {
Days []*string `json:"days,omitempty"`
Months []*string `json:"months,omitempty"`
Unit *string `json:"unit,omitempty"`
+ Time string `json:"time,omitempty"`
}
type NotificationMetadata struct {
diff --git a/internal/chore/scheduler.go b/internal/chore/scheduler.go
index c1ff48d..5413447 100644
--- a/internal/chore/scheduler.go
+++ b/internal/chore/scheduler.go
@@ -22,6 +22,7 @@ func scheduleNextDueDate(chore *chModel.Chore, completedDate time.Time) (*time.T
if chore.FrequencyType == "once" {
return nil, nil
}
+
if chore.NextDueDate != nil {
// no due date set, use the current date
@@ -29,6 +30,17 @@ func scheduleNextDueDate(chore *chModel.Chore, completedDate time.Time) (*time.T
} else {
baseDate = completedDate.UTC()
}
+ if chore.FrequencyType == "day_of_the_month" || chore.FrequencyType == "days_of_the_week" || chore.FrequencyType == "interval" {
+ // time in frequency metadata stored as RFC3339 format like `2024-07-07T13:27:00-04:00`
+ // parse it to time.Time:
+ t, err := time.Parse(time.RFC3339, frequencyMetadata.Time)
+ if err != nil {
+ return nil, fmt.Errorf("error parsing time in frequency metadata")
+ }
+ // set the time to the time in the frequency metadata:
+ baseDate = time.Date(baseDate.Year(), baseDate.Month(), baseDate.Day(), t.Hour(), t.Minute(), 0, 0, t.Location())
+
+ }
if chore.IsRolling && chore.NextDueDate.Before(completedDate) {
// we need to check if chore due date is before the completed date to handle this senario:
// if user trying to complete chore due in future (multiple time for insance) due date will be calculated
diff --git a/internal/database/database.go b/internal/database/database.go
index 8fc8a68..67818db 100644
--- a/internal/database/database.go
+++ b/internal/database/database.go
@@ -2,6 +2,7 @@ package database
import (
"fmt"
+ "os"
"time"
"gorm.io/driver/postgres"
@@ -33,7 +34,12 @@ func NewDatabase(cfg *config.Config) (*gorm.DB, error) {
default:
- db, err = gorm.Open(sqlite.Open("donetick.db"), &gorm.Config{})
+ path := os.Getenv("DT_SQLITE_PATH")
+ if path == "" {
+ db, err = gorm.Open(sqlite.Open("donetick.db"), &gorm.Config{})
+ } else {
+ db, err = gorm.Open(sqlite.Open(path), &gorm.Config{})
+ }
}