Hello,
In a project I use a GPS and need to make some calculations based on time and days of the week. I use an UBlox GPS and currently sync the Teensy RTC with the GPS with this :
isDayLightSaving() is a function that calculate if the code need to ad an hour to current time in regard with "day light saving".
syncTimeWithGps() is a function that set the teensy RTC with GPS time as soon as GPS have a fix. This is required to determine/use isDayLightSaving(). It sync RTC with CURRENT time, not UTC. I mean it take in account the timezone and day light saving offset. UTC time is still available from GPS, at any time.
Now, based on the RTC or GPS (preferably GPS) I have to determine :
- The week of the current year
- The elapsed seconds since the beginning of the current week (start at midnight GMT on Saturday night)
Using "TimeLib.h", I can't figure how to do this. Can someone point me to the right direction ?
I'm really useless with date calculations...
Thank you,
Manu
In a project I use a GPS and need to make some calculations based on time and days of the week. I use an UBlox GPS and currently sync the Teensy RTC with the GPS with this :
Code:
bool isDaylightSavingTime()
{
tmElements_t te;
// Date pour le 1er Mars
te.Year = year() - 1970;
te.Month = 3;
te.Day = 1;
te.Hour = 0;
te.Minute = 0;
te.Second = 0;
time_t dstStart, dstEnd;
// Date pour le troisième dimanche du mois de mars à 2H AM
dstStart = makeTime(te);
dstStart = nextSunday(nextSunday(nextSunday(dstStart)));
dstStart += 2 * SECS_PER_HOUR;
// Date pour le premier Dimanche de Novembre à 1H AM
te.Month = 11;
dstEnd = makeTime(te);
dstEnd = nextSunday(dstEnd);
dstEnd += SECS_PER_HOUR;
// Si l'heure d'été est active, alors la fonction renvoie "true"
return (now() >= dstStart && now() < dstEnd);
}
Code:
void syncTimeWithGps()
{
setTime(uBloxData.utcHour, uBloxData.utcMin, uBloxData.utcSec, uBloxData.utcDay, uBloxData.utcMonth, uBloxData.utcYear - 2000);
int32_t secondsToAdjust = timeZone * SECS_PER_HOUR; // Adjust timeZone
if (isDaylightSavingTime())
{
secondsToAdjust += SECS_PER_HOUR;
}
adjustTime(secondsToAdjust);
Teensy3Clock.set(now());
}
isDayLightSaving() is a function that calculate if the code need to ad an hour to current time in regard with "day light saving".
syncTimeWithGps() is a function that set the teensy RTC with GPS time as soon as GPS have a fix. This is required to determine/use isDayLightSaving(). It sync RTC with CURRENT time, not UTC. I mean it take in account the timezone and day light saving offset. UTC time is still available from GPS, at any time.
Now, based on the RTC or GPS (preferably GPS) I have to determine :
- The week of the current year
- The elapsed seconds since the beginning of the current week (start at midnight GMT on Saturday night)
Using "TimeLib.h", I can't figure how to do this. Can someone point me to the right direction ?
I'm really useless with date calculations...
Thank you,
Manu
Last edited: