@@ -15,8 +15,13 @@ import (
15
15
16
16
// time and date handling
17
17
18
- // another name for time.Now() to use for testing
19
- var now = time .Now
18
+ // all the upload processing takes place (conceptually) at
19
+ // a single instant. Most of the time this wouldn't matter
20
+ // but it protects against time skew if time.Now
21
+ // increases the day between calls, as might happen (rarely) by chance
22
+ // or if there are long scheduling delays between calls.
23
+ var thisInstant = time .Now ().UTC ()
24
+
20
25
var distantPast = 21 * 24 * time .Hour
21
26
22
27
// reports that are too old (21 days) are not uploaded
@@ -26,7 +31,8 @@ func tooOld(date string) bool {
26
31
logger .Printf ("tooOld: %v" , err )
27
32
return false
28
33
}
29
- return now ().Sub (t ) > distantPast
34
+ age := thisInstant .Sub (t )
35
+ return age > distantPast
30
36
}
31
37
32
38
// return the expiry date of a countfile in YYYY-MM-DD format
@@ -57,14 +63,13 @@ func expiry(fname string) time.Time {
57
63
logger .Printf ("time.Parse: %v for %s" , err , fname )
58
64
return farFuture // don't process it, whatever it is
59
65
}
60
- // TODO(pjw): check for off-by-one-day?
61
66
return expiry
62
67
}
63
68
64
69
// stillOpen returns true if the counter file might still be active
65
70
func stillOpen (fname string ) bool {
66
71
expiry := expiry (fname )
67
- return expiry .After (now ()) // TODO(pjw): off by one day?
72
+ return expiry .After (thisInstant )
68
73
}
69
74
70
75
// avoid parsing count files multiple times
0 commit comments