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

feat: add wakatime-compatible alltime endpoint

This commit is contained in:
Ferdinand Mütsch
2020-09-06 12:15:46 +02:00
parent 97cb29ee4d
commit 587ac6a330
9 changed files with 216 additions and 64 deletions

View File

@ -1,6 +1,9 @@
package utils
import "time"
import (
"fmt"
"time"
)
func StartOfDay() time.Time {
ref := time.Now()
@ -23,6 +26,14 @@ func StartOfYear() time.Time {
return time.Date(ref.Year(), time.January, 1, 0, 0, 0, 0, ref.Location())
}
func FmtWakatimeDuration(d time.Duration) string {
d = d.Round(time.Minute)
h := d / time.Hour
d -= h * time.Hour
m := d / time.Minute
return fmt.Sprintf("%d hrs %d mins", h, m)
}
// https://stackoverflow.com/a/18632496
func firstDayOfISOWeek(year int, week int, timezone *time.Location) time.Time {
date := time.Date(year, 0, 0, 0, 0, 0, 0, timezone)