-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
26 lines (23 loc) · 675 Bytes
/
utils.go
File metadata and controls
26 lines (23 loc) · 675 Bytes
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
package subscription_with_debug
import "time"
func calculatePaymentCycles(totalAmount int64, cycles int) []int64 {
div := totalAmount / int64(cycles)
mod := int(totalAmount % int64(cycles))
paymentAmounts := make([]int64, cycles)
for i := 0; i < cycles; i++ {
paymentAmounts[i] = div
if i < mod {
paymentAmounts[i] += 1
}
}
return paymentAmounts
}
func calculatePaymentTimings(anchor time.Time, cycles int, cycleDuration time.Duration) []int64 {
anchorMillis := anchor.UnixMilli()
timings := make([]int64, cycles)
for i := 0; i < cycles; i++ {
d := time.Duration(i+1) * cycleDuration
timings[i] = anchorMillis + d.Milliseconds()
}
return timings
}