mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-17 03:06:42 -07:00
transition time ranged queries to timeframe (#117)
This commit is contained in:
parent
ad3c51a70e
commit
d327729bff
26 changed files with 2032 additions and 335 deletions
|
|
@ -6,23 +6,6 @@ import (
|
|||
|
||||
// should this be in db package ???
|
||||
|
||||
type Timeframe struct {
|
||||
Period Period
|
||||
T1u int64
|
||||
T2u int64
|
||||
}
|
||||
|
||||
func TimeframeToTimeRange(timeframe Timeframe) (t1, t2 time.Time) {
|
||||
if timeframe.T1u == 0 && timeframe.T2u == 0 {
|
||||
t2 = time.Now()
|
||||
t1 = StartTimeFromPeriod(timeframe.Period)
|
||||
} else {
|
||||
t1 = time.Unix(timeframe.T1u, 0)
|
||||
t2 = time.Unix(timeframe.T2u, 0)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type Period string
|
||||
|
||||
const (
|
||||
|
|
@ -31,9 +14,12 @@ const (
|
|||
PeriodMonth Period = "month"
|
||||
PeriodYear Period = "year"
|
||||
PeriodAllTime Period = "all_time"
|
||||
PeriodDefault Period = "day"
|
||||
)
|
||||
|
||||
func (p Period) IsZero() bool {
|
||||
return p == ""
|
||||
}
|
||||
|
||||
func StartTimeFromPeriod(p Period) time.Time {
|
||||
now := time.Now()
|
||||
switch p {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue