Repository navigation
Time Zones
CTS does not use time zone names or POSIX TZ strings like TinyNTP. It sends two numbers in the Local Time Information characteristic:
| Value | Unit | Example (Zurich in summer) |
|---|---|---|
| time zone | 15 minutes, -48 .. 56 | 4 (UTC+1) |
| summer time (DST) offset | 0, 30, 60 or 120 minutes (as 0, 2, 4, 8) | 4 (+1 h) |
Local time = UTC + time zone + DST offset. Because the device that you read tells the current offsets, it follows the user when travelling and when the clocks change.
server.setTimeZone(60, 60); // UTC+1 and one hour of summer time nowThe first value is the standard time zone in minutes, the second the summer time offset that is valid now: change it when the clocks change (the server notifies the subscribed clients).
cts.begin();
std::tm utc = cts.getTm(); // UTC
std::tm local = cts.getLocalTm(); // UTC + the offsets of the device
const TinyCTSLocalTimeInfo& info = cts.getLocalTimeInfo();
info.isKnown(); // false if the device does not have the characteristic
info.utcOffsetMinutes(); // time zone + summer time in minutesIf the device has no Local Time Information, tell the client the zone yourself with cts.setLocalTimeInfo(TinyCTSLocalTimeInfo::fromMinutes(60, 0)).
The specification leaves it open if the Current Time characteristic contains UTC or the local time. TinyCTS sends UTC by default, together with the Local Time Information, so that the client can calculate the local time. Some clients (e.g. phones) expect the local time: use
-
server.setTimeIsLocal(true)(beforebegin()) client.setTimeIsLocal(true)tinycts --local
The library then converts between the two with the Local Time Information.