@@ -50,7 +50,6 @@ func RunNTPCheck(ctx context.Context) {
5050func ntpCheck (ctx context.Context ) error {
5151 z := zinit .Default ()
5252 zcl , err := perf .TryGetZbusClient (ctx )
53-
5453 if err != nil {
5554 return fmt .Errorf ("ntpCheck expects zbus client in the context and found none %w" , err )
5655 }
@@ -76,8 +75,14 @@ func getCurrentUTCTime(zcl zbus.Client) (time.Time, error) {
7675 Func func () (time.Time , error )
7776 }
7877
79- // List of time servers
78+ // List of time servers, and here not in the global vars, so we can inject zcl to pass to getTimeChainWithZCL
8079 var timeServers = []TimeServer {
80+ {
81+ Name : "tfchain" ,
82+ Func : func () (time.Time , error ) {
83+ return getTimeChainWithZCL (zcl )
84+ },
85+ },
8186 {
8287 Name : "worldtimeapi" ,
8388 Func : getWorldTimeAPI ,
@@ -90,16 +95,12 @@ func getCurrentUTCTime(zcl zbus.Client) (time.Time, error) {
9095 Name : "timeapi.io" ,
9196 Func : getTimeAPI ,
9297 },
93- {
94- Name : "tfchain" ,
95- Func : func () (time.Time , error ) {
96- return getTimeChainWithZCL (zcl )
97- },
98- },
9998 }
10099 for _ , server := range timeServers {
100+ log .Info ().Msg (fmt .Sprint ("running NTP check against " , server .Name ))
101101 utcTime , err := server .Func ()
102102 if err == nil {
103+ log .Info ().Msg (fmt .Sprint ("utc time from " , server .Name , ": " , utcTime ))
103104 return utcTime , nil
104105 }
105106 log .Error ().Err (err ).Str ("server" , server .Name ).Msg ("failed to get time from server" )
@@ -132,13 +133,14 @@ func getWorldClockAPI() (time.Time, error) {
132133 defer timeRes .Body .Close ()
133134
134135 var utcTime struct {
135- CurrentDateTime time. Time `json:"currentDateTime"`
136+ CurrentDateTime string `json:"currentDateTime"` // Changed to string, needs manual parsing
136137 }
137138 if err := json .NewDecoder (timeRes .Body ).Decode (& utcTime ); err != nil {
138139 return time.Time {}, errors .Wrapf (err , "failed to decode date response from worldclockapi" )
139140 }
140141
141- return utcTime .CurrentDateTime , nil
142+ // Parse the time manually, handling the "Z"
143+ return time .Parse ("2006-01-02T15:04Z" , utcTime .CurrentDateTime )
142144}
143145
144146func getTimeAPI () (time.Time , error ) {
@@ -149,13 +151,14 @@ func getTimeAPI() (time.Time, error) {
149151 defer timeRes .Body .Close ()
150152
151153 var utcTime struct {
152- DateTime time. Time `json:"dateTime"`
154+ DateTime string `json:"dateTime"` // Changed to string, needs manual parsing
153155 }
154156 if err := json .NewDecoder (timeRes .Body ).Decode (& utcTime ); err != nil {
155157 return time.Time {}, errors .Wrapf (err , "failed to decode date response from timeapi.io" )
156158 }
157159
158- return utcTime .DateTime , nil
160+ // Parse the time manually, handling the fractional seconds
161+ return time .Parse ("2006-01-02T15:04:05.999999" , utcTime .DateTime )
159162}
160163
161164func getTimeChainWithZCL (zcl zbus.Client ) (time.Time , error ) {
0 commit comments