Merge pull request #1096 from safing/feature/add-current-time-broadcast-matching-data
Add current time to broadcast matching data
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package broadcasts
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/safing/portbase/config"
|
||||
@@ -69,13 +70,21 @@ func collectData() interface{} {
|
||||
data["Account"] = &Account{
|
||||
UserRecord: userRecord,
|
||||
UpToDate: userRecord.Meta().Modified > time.Now().Add(-7*24*time.Hour).Unix(),
|
||||
MayUseUSP: userRecord.MayUseSPN(),
|
||||
MayUseSPN: userRecord.MayUseSPN(),
|
||||
}
|
||||
}
|
||||
|
||||
// Time running.
|
||||
data["UptimeHours"] = int(time.Since(portmasterStarted).Hours())
|
||||
|
||||
// Get current time and date.
|
||||
now := time.Now()
|
||||
data["Current"] = &Current{
|
||||
UnixTime: now.Unix(),
|
||||
UTC: makeDateTimeInfo(now.UTC()),
|
||||
Local: makeDateTimeInfo(now),
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -93,10 +102,33 @@ type Location struct {
|
||||
type Account struct {
|
||||
*access.UserRecord
|
||||
UpToDate bool
|
||||
MayUseUSP bool
|
||||
MayUseSPN bool
|
||||
}
|
||||
|
||||
// DataError represents an error getting some matching data.
|
||||
type DataError struct {
|
||||
Error error
|
||||
}
|
||||
|
||||
// Current holds current date and time data.
|
||||
type Current struct {
|
||||
UnixTime int64
|
||||
UTC *DateTime
|
||||
Local *DateTime
|
||||
}
|
||||
|
||||
// DateTime holds date and time data in different formats.
|
||||
type DateTime struct {
|
||||
NumericDateTime int64
|
||||
NumericDate int64
|
||||
NumericTime int64
|
||||
}
|
||||
|
||||
func makeDateTimeInfo(t time.Time) *DateTime {
|
||||
info := &DateTime{}
|
||||
info.NumericDateTime, _ = strconv.ParseInt(t.Format("20060102150405"), 10, 64)
|
||||
info.NumericDate, _ = strconv.ParseInt(t.Format("20060102"), 10, 64)
|
||||
info.NumericTime, _ = strconv.ParseInt(t.Format("150405"), 10, 64)
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user