1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

feat: implement summaries compat endpoint (resolve #44)

fix: fix all time view model
This commit is contained in:
Ferdinand Mütsch
2020-09-11 23:24:51 +02:00
parent a8009e107d
commit 21567e7601
12 changed files with 326 additions and 44 deletions

View File

@ -5,9 +5,12 @@ import (
"time"
)
func StartOfDay() time.Time {
ref := time.Now()
return time.Date(ref.Year(), ref.Month(), ref.Day(), 0, 0, 0, 0, ref.Location())
func StartOfToday() time.Time {
return StartOfDay(time.Now())
}
func StartOfDay(date time.Time) time.Time {
return time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
}
func StartOfWeek() time.Time {
@ -26,6 +29,21 @@ func StartOfYear() time.Time {
return time.Date(ref.Year(), time.January, 1, 0, 0, 0, 0, ref.Location())
}
func SplitRangeByDays(from time.Time, to time.Time) [][]time.Time {
intervals := make([][]time.Time, 0)
for t1 := from; t1.Before(to); {
t2 := StartOfDay(t1).Add(24 * time.Hour)
if t2.After(to) {
t2 = to
}
intervals = append(intervals, []time.Time{t1, t2})
t1 = t2
}
return intervals
}
func FmtWakatimeDuration(d time.Duration) string {
d = d.Round(time.Minute)
h := d / time.Hour