mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-22 07:53:38 +01:00
Use time.Truncate instead of manually flooring the hour
This commit is contained in:
parent
fd08c8b1e5
commit
943d0a19d1
@ -55,7 +55,7 @@ func (uptime *Uptime) ProcessResult(result *Result) {
|
|||||||
if uptime.HourlyStatistics == nil {
|
if uptime.HourlyStatistics == nil {
|
||||||
uptime.HourlyStatistics = make(map[int64]*HourlyUptimeStatistics)
|
uptime.HourlyStatistics = make(map[int64]*HourlyUptimeStatistics)
|
||||||
}
|
}
|
||||||
unixTimestampFlooredAtHour := result.Timestamp.Unix() - (result.Timestamp.Unix() % 3600)
|
unixTimestampFlooredAtHour := result.Timestamp.Truncate(time.Hour).Unix()
|
||||||
hourlyStats, _ := uptime.HourlyStatistics[unixTimestampFlooredAtHour]
|
hourlyStats, _ := uptime.HourlyStatistics[unixTimestampFlooredAtHour]
|
||||||
if hourlyStats == nil {
|
if hourlyStats == nil {
|
||||||
hourlyStats = &HourlyUptimeStatistics{}
|
hourlyStats = &HourlyUptimeStatistics{}
|
||||||
@ -101,7 +101,7 @@ func (uptime *Uptime) recalculate() {
|
|||||||
// The oldest uptime bracket starts 7 days ago, so we'll start from there
|
// The oldest uptime bracket starts 7 days ago, so we'll start from there
|
||||||
timestamp := now.Add(-sevenDays)
|
timestamp := now.Add(-sevenDays)
|
||||||
for now.Sub(timestamp) >= 0 {
|
for now.Sub(timestamp) >= 0 {
|
||||||
hourlyUnixTimestamp := timestamp.Unix() - (timestamp.Unix() % 3600)
|
hourlyUnixTimestamp := timestamp.Truncate(time.Hour).Unix()
|
||||||
hourlyStats := uptime.HourlyStatistics[hourlyUnixTimestamp]
|
hourlyStats := uptime.HourlyStatistics[hourlyUnixTimestamp]
|
||||||
if hourlyStats == nil || hourlyStats.TotalExecutions == 0 {
|
if hourlyStats == nil || hourlyStats.TotalExecutions == 0 {
|
||||||
timestamp = timestamp.Add(time.Hour)
|
timestamp = timestamp.Add(time.Hour)
|
||||||
|
Loading…
Reference in New Issue
Block a user