in query/common/dimval.go [146:213]
func formatTimeDimension(val int64, meta TimeDimensionMeta, cache map[TimeDimensionMeta]map[int64]string) (result string) {
// We will not process timeUnit for application/hll because if application/hll holds the raw uint32
// value. If we convert it to milliseconds, it will overflow.
if meta.TimeUnit != "" {
val = utils.AdjustOffset(meta.FromOffset, meta.ToOffset,
meta.DSTSwitchTs, val)
switch meta.TimeUnit {
case "day":
val /= SecondsPerDay
case "hour":
val /= SecondsPerHour
case "minute":
val /= SecondsPerMinute
case "millisecond":
val *= 1000
}
return strconv.FormatInt(val, 10)
}
// skip timezone table dims
// TODO(shz): support timezone table dims
if !meta.IsTimezoneTable {
if cacheMap, ok := cache[meta]; ok {
if result, exists := cacheMap[val]; exists {
return result
}
} else if cache != nil {
cache[meta] = make(map[int64]string)
}
}
switch meta.TimeBucketizer {
case "time of day":
t := time.Unix(val, 0)
return t.UTC().Format("15:04")
case "hour of day":
t := time.Unix(val-val%3600, 0)
return t.UTC().Format("15:04")
case "hour of week":
t := time.Unix(val+SecondsPer4Day, 0)
return t.UTC().Format("Monday 15:04")
case "day of week":
// 1970-01-01 was a Thursday
t := time.Unix(((val+4)%7)*SecondsPerDay, 0)
return t.UTC().Format("Monday")
default:
bucket, err := ParseRegularTimeBucketizer(meta.TimeBucketizer)
if err != nil {
return strconv.FormatInt(val, 10)
}
switch bucket.Unit {
case "m":
t := time.Unix(val, 0)
return t.UTC().Format("2006-01-02 15:04")
case "h":
t := time.Unix(val-val%3600, 0)
return t.UTC().Format("2006-01-02 15:00")
case "d":
t := time.Unix(val-val%(24*60*60), 0)
return t.UTC().Format("2006-01-02")
}
}
if !meta.IsTimezoneTable {
cache[meta][val] = result
}
return
}