A simple pattern that works well is:
1. On boot, let `TimeLib` read from the Teensy RTC:
```cpp
time_t getTeensyTime() { return Teensy3Clock.get(); }
void setup() {
setSyncProvider(getTeensyTime);
setSyncInterval(300);
}
2. When GPS has a valid UTC date/time, update both TimeLib and the RTC:
void syncFromGps(time_t gpsUtc) {
setTime(gpsUtc);
if (abs((long)(gpsUtc - Teensy3Clock.get())) >= 1) {
Teensy3Clock.set(gpsUtc);
}
}
So the RTC gives you buffered/held time between GPS updates, and GPS corrects it whenever a valid fix is available.
Important:
- Keep the RTC in UTC, not local time.
- Apply timezone/DST only when displaying time.
- Do not write the RTC continuously in the loop, only when GPS time is valid.
If you want better than 1-second NMEA accuracy, add GPS PPS and sync on that edge.