@@ -64,41 +64,34 @@ func (i *Interval) ShouldTriggerBackup(now time.Time, lastBackupTime *time.Time)
6464 }
6565}
6666
67- // daily trigger: calendar-based if TimeOfDay set, otherwise next calendar day
67+ // daily trigger: honour the TimeOfDay slot and catch up the previous one
6868func (i * Interval ) shouldTriggerDaily (now , lastBackup time.Time ) bool {
69- if i .TimeOfDay != nil {
70- target , err := time .Parse ("15:04" , * i .TimeOfDay )
71- if err == nil {
72- todayTarget := time .Date (
73- now .Year (),
74- now .Month (),
75- now .Day (),
76- target .Hour (),
77- target .Minute (),
78- 0 ,
79- 0 ,
80- now .Location (),
81- )
82-
83- // if it's past today's target time and we haven't backed up today
84- if now .After (todayTarget ) && ! isSameDay (lastBackup , now ) {
85- return true
86- }
69+ if i .TimeOfDay == nil {
70+ return ! isSameDay (lastBackup , now )
71+ }
8772
88- // if it's exactly the target time and we haven't backed up today
89- if now . Equal ( todayTarget ) && ! isSameDay ( lastBackup , now ) {
90- return true
91- }
73+ t , err := time . Parse ( "15:04" , * i . TimeOfDay )
74+ if err != nil {
75+ return false // malformed ⇒ play safe
76+ }
9277
93- // if it's before today's target time, don't trigger yet
94- if now .Before (todayTarget ) {
95- return false
96- }
97- }
78+ // Today's scheduled slot (todayTgt)
79+ todayTgt := time .Date (
80+ now .Year (), now .Month (), now .Day (),
81+ t .Hour (), t .Minute (), 0 , 0 , now .Location (),
82+ )
83+
84+ // The last scheduled slot that should already have happened
85+ var lastScheduled time.Time
86+ if now .Before (todayTgt ) {
87+ lastScheduled = todayTgt .AddDate (0 , 0 , - 1 )
88+ } else {
89+ lastScheduled = todayTgt
9890 }
9991
100- // no TimeOfDay: if it's a new calendar day
101- return ! isSameDay (lastBackup , now )
92+ // Fire when we are past that slot AND no backup has been taken since it
93+ return (now .After (lastScheduled ) || now .Equal (lastScheduled )) &&
94+ lastBackup .Before (lastScheduled )
10295}
10396
10497// weekly trigger: on specified weekday/calendar week, otherwise ≥7 days
0 commit comments