can fill values now
This commit is contained in:
parent
9a9af15fd4
commit
114738a2de
6 changed files with 179 additions and 5 deletions
46
date.go
46
date.go
|
|
@ -345,14 +345,22 @@ func (d date) CalculateMarketSecondsBetween(start, end, marketOpen, marketClose
|
|||
}
|
||||
|
||||
const (
|
||||
_secondsPerDay = 60 * 60 * 24
|
||||
_secondsPerHour = 60 * 60
|
||||
_secondsPerDay = 60 * 60 * 24
|
||||
)
|
||||
|
||||
func (d date) Diff(t1, t2 time.Time) (days int64) {
|
||||
func (d date) DiffDays(t1, t2 time.Time) (days int) {
|
||||
t1n := t1.Unix()
|
||||
t2n := t2.Unix()
|
||||
diff := t1n - t2n
|
||||
return diff / (_secondsPerDay)
|
||||
diff := t2n - t1n //yields seconds
|
||||
return int(diff / (_secondsPerDay))
|
||||
}
|
||||
|
||||
func (d date) DiffHours(t1, t2 time.Time) (hours int) {
|
||||
t1n := t1.Unix()
|
||||
t2n := t2.Unix()
|
||||
diff := t2n - t1n //yields seconds
|
||||
return int(diff / (_secondsPerHour))
|
||||
}
|
||||
|
||||
// NextDay returns the timestamp advanced a day.
|
||||
|
|
@ -386,3 +394,33 @@ func (d date) NextDayOfWeek(after time.Time, dayOfWeek time.Weekday) time.Time {
|
|||
dayDelta := 7 - int(afterWeekday-dayOfWeek)
|
||||
return after.AddDate(0, 0, dayDelta)
|
||||
}
|
||||
|
||||
// Start returns the earliest (min) time in a list of times.
|
||||
func (d date) Start(times []time.Time) time.Time {
|
||||
if len(times) == 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
start := times[0]
|
||||
for _, t := range times[1:] {
|
||||
if t.Before(start) {
|
||||
start = t
|
||||
}
|
||||
}
|
||||
return start
|
||||
}
|
||||
|
||||
// Start returns the earliest (min) time in a list of times.
|
||||
func (d date) End(times []time.Time) time.Time {
|
||||
if len(times) == 0 {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
end := times[0]
|
||||
for _, t := range times[1:] {
|
||||
if t.After(end) {
|
||||
end = t
|
||||
}
|
||||
}
|
||||
return end
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue