summaryrefslogtreecommitdiff
path: root/src/helsinki.at
diff options
context:
space:
mode:
Diffstat (limited to 'src/helsinki.at')
-rw-r--r--src/helsinki.at/rhrdtime/rhrdtime.go38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/helsinki.at/rhrdtime/rhrdtime.go b/src/helsinki.at/rhrdtime/rhrdtime.go
index 519d465..5fa72a1 100644
--- a/src/helsinki.at/rhrdtime/rhrdtime.go
+++ b/src/helsinki.at/rhrdtime/rhrdtime.go
@@ -28,7 +28,6 @@ import (
"encoding/json"
"flag"
"fmt"
- "math"
"net/http"
"time"
@@ -36,35 +35,21 @@ import (
"github.com/gorilla/websocket"
)
-func getRDWeekAndOffset(t time.Time) (uint8, int) {
- //
- // This computes the current Rivendell Week based on the number
- // of weeks since epoch.
- //
- // Explanation:
- // epoch was at 01.01.1970 UTC which was a Thursday.
- // Monday in that week is (s-from-epoch + 3*24*60*60) seconds ago.
- // This needs to be adjusted by the timezone offset for Europe/Vienna
- // which is of course not constant (damn you daylight savings time)
- // Divide this by (7*24*60*60) and you get the number of
- // weeks since the Monday in the week of epoch adjusted for timezone offsets.
- // This week had week number 3 so add an offset of 2 and
- // get the modulo of 4. This rounded down gives you the current week
- // with 0 meaning Week 1. So add 1 to that number and you will get
- // the current RD week.
- //
-
- loc, err := time.LoadLocation("Europe/Vienna")
- if err != nil {
+var (
+ loc *time.Location
+)
+
+func init() {
+ var err error
+ if loc, err = time.LoadLocation("Europe/Vienna"); err != nil {
fmt.Println("Error while loading loaction Europe/Vienna:", err)
- return 0, 0
}
+}
+func getTZOffset(t time.Time) int {
t = t.In(loc)
_, offset := t.Zone()
-
- sEpoch := t.Unix() + int64(offset)
- return uint8(math.Floor(math.Mod((((float64(sEpoch)+259200)/604800)+2), 4)) + 1), offset
+ return offset
}
type ntpMessage struct {
@@ -73,7 +58,6 @@ type ntpMessage struct {
T3 int64 `json:"t3"`
T4 int64 `json:"t4"`
TZOffset int `json:"tz_offset"`
- Week uint8 `json:"week"`
}
func handleNTPClient(w http.ResponseWriter, r *http.Request) {
@@ -103,7 +87,7 @@ func handleNTPClient(w http.ResponseWriter, r *http.Request) {
}
n.T2 = (now_t2.Unix() * 1000) + int64(now_t2.Nanosecond()/1000000)
- n.Week, n.TZOffset = getRDWeekAndOffset(now_t2)
+ n.TZOffset = getTZOffset(now_t2)
now_t3 := time.Now()
n.T3 = (now_t3.Unix() * 1000) + int64(now_t3.Nanosecond()/1000000)