-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
52 lines (43 loc) · 1.18 KB
/
util.go
File metadata and controls
52 lines (43 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"log"
"os"
"path/filepath"
"time"
)
func startWeeklySync() {
ticker := time.NewTicker(7 * 24 * time.Hour) // 1 week
defer ticker.Stop()
for {
log.Println("Weekly sync started...")
checkTokenCount()
if err := syncMissingCurrentOwners(); err != nil {
log.Println("Weekly sync error:", err)
} else {
log.Println("Weekly sync completed successfully.")
}
<-ticker.C
}
}
// Rubix Week Epoch starting reference date is Jan 01 2025.
var RubixWeekEpochStartDate = time.Date(2025, time.January, 1, 0, 0, 0, 0, time.UTC)
// To calculate the week number that's going on since reference date for a transaction
func GetWeeksPassed() int {
now := time.Now().UTC()
duration := now.Sub(RubixWeekEpochStartDate)
// Handle case where current time is before ReferenceDate
if duration < 0 {
return 0 // If the current time is before the start date, return 0 intervals
}
weeksPassed := int(duration.Hours() / (24 * 7))
// Add +1 to ensure the first week starts as week 1
return weeksPassed + 1
}
func getAppDir() (string, error) {
// Use executable directory
exe, err := os.Executable()
if err != nil {
return "", err
}
return filepath.Dir(exe), nil
}