2020-09-06 13:15:46 +03:00
|
|
|
package v1
|
|
|
|
|
2020-09-12 00:24:51 +03:00
|
|
|
import (
|
2022-12-01 12:57:07 +03:00
|
|
|
"github.com/muety/wakapi/helpers"
|
2020-09-12 00:24:51 +03:00
|
|
|
"github.com/muety/wakapi/models"
|
2022-11-13 21:27:44 +03:00
|
|
|
"time"
|
2020-09-12 00:24:51 +03:00
|
|
|
)
|
|
|
|
|
2020-09-06 13:15:46 +03:00
|
|
|
// https://wakatime.com/developers#all_time_since_today
|
|
|
|
|
2020-09-12 17:09:23 +03:00
|
|
|
type AllTimeViewModel struct {
|
2021-02-05 20:47:28 +03:00
|
|
|
Data *AllTimeData `json:"data"`
|
2020-09-12 00:24:51 +03:00
|
|
|
}
|
|
|
|
|
2021-02-05 20:47:28 +03:00
|
|
|
type AllTimeData struct {
|
2021-02-11 00:08:00 +03:00
|
|
|
TotalSeconds float32 `json:"total_seconds"` // total number of seconds logged since account created
|
|
|
|
Text string `json:"text"` // total time logged since account created as human readable string>
|
|
|
|
IsUpToDate bool `json:"is_up_to_date"` // true if the stats are up to date; when false, a 202 response code is returned and stats will be refreshed soon>
|
|
|
|
Range *AllTimeRange `json:"range"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type AllTimeRange struct {
|
|
|
|
End string `json:"end"`
|
|
|
|
EndDate string `json:"end_date"`
|
|
|
|
Start string `json:"start"`
|
|
|
|
StartDate string `json:"start_date"`
|
|
|
|
Timezone string `json:"timezone"`
|
2020-09-06 18:20:37 +03:00
|
|
|
}
|
|
|
|
|
2021-12-26 19:02:14 +03:00
|
|
|
func NewAllTimeFrom(summary *models.Summary) *AllTimeViewModel {
|
|
|
|
total := summary.TotalTime()
|
2022-11-13 21:27:44 +03:00
|
|
|
tzName, _ := summary.FromTime.T().Zone()
|
2020-09-12 17:09:23 +03:00
|
|
|
return &AllTimeViewModel{
|
2021-02-05 20:47:28 +03:00
|
|
|
Data: &AllTimeData{
|
2020-09-12 00:24:51 +03:00
|
|
|
TotalSeconds: float32(total.Seconds()),
|
2022-12-01 12:57:07 +03:00
|
|
|
Text: helpers.FmtWakatimeDuration(total),
|
2020-09-12 00:24:51 +03:00
|
|
|
IsUpToDate: true,
|
2022-11-13 21:27:44 +03:00
|
|
|
Range: &AllTimeRange{
|
|
|
|
End: summary.ToTime.T().Format(time.RFC3339),
|
2022-12-01 12:57:07 +03:00
|
|
|
EndDate: helpers.FormatDate(summary.ToTime.T()),
|
2022-11-13 21:27:44 +03:00
|
|
|
Start: summary.FromTime.T().Format(time.RFC3339),
|
2022-12-01 12:57:07 +03:00
|
|
|
StartDate: helpers.FormatDate(summary.FromTime.T()),
|
2022-11-13 21:27:44 +03:00
|
|
|
Timezone: tzName,
|
|
|
|
},
|
2020-09-12 00:24:51 +03:00
|
|
|
},
|
|
|
|
}
|
2020-09-06 13:15:46 +03:00
|
|
|
}
|