Arduino Nano 33 IoT with 'Clock.ino' example
Central European time zone
I can't get myTZ.locIsDST(now()) to work !?
After the time changes as it should, this value stays the same.
here is the Serial Monitor output when the changes happens from CEST to CET
00:59:53 Sun 31 Oct 2021 UTC 02:59:53 Sun 31 Oct 2021 CEST is DST? 1
00:59:54 Sun 31 Oct 2021 UTC 02:59:54 Sun 31 Oct 2021 CEST is DST? 1
00:59:55 Sun 31 Oct 2021 UTC 02:59:55 Sun 31 Oct 2021 CEST is DST? 1
00:59:56 Sun 31 Oct 2021 UTC 02:59:56 Sun 31 Oct 2021 CEST is DST? 1
00:59:57 Sun 31 Oct 2021 UTC 02:59:57 Sun 31 Oct 2021 CEST is DST? 1
00:59:58 Sun 31 Oct 2021 UTC 02:59:58 Sun 31 Oct 2021 CEST is DST? 1
00:59:59 Sun 31 Oct 2021 UTC 02:59:59 Sun 31 Oct 2021 CEST is DST? 1
01:00:00 Sun 31 Oct 2021 UTC 02:00:00 Sun 31 Oct 2021 CET is DST? 1
01:00:01 Sun 31 Oct 2021 UTC 02:00:01 Sun 31 Oct 2021 CET is DST? 1
01:00:02 Sun 31 Oct 2021 UTC 02:00:02 Sun 31 Oct 2021 CET is DST? 1
01:00:03 Sun 31 Oct 2021 UTC 02:00:03 Sun 31 Oct 2021 CET is DST? 1
01:00:04 Sun 31 Oct 2021 UTC 02:00:04 Sun 31 Oct 2021 CET is DST? 1
01:00:05 Sun 31 Oct 2021 UTC 02:00:05 Sun 31 Oct 2021 CET is DST? 1
01:00:06 Sun 31 Oct 2021 UTC 02:00:06 Sun 31 Oct 2021 CET is DST? 1
I tried daylightSavingTime = myTZ.locIsDST(local);
and daylightSavingTime = myTZ.locIsDST(now());
the complete code:
// Arduino Timezone Library Copyright (C) 2018 by Jack Christensen and
// licensed under GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
//
// Arduino Timezone Library example sketch.
// Self-adjusting clock for one time zone.
// TimeChangeRules can be hard-coded or read from EEPROM, see comments.
// Jack Christensen Mar 2012
#include <Arduino.h>
#include <time.h>
#include <Timezone.h> // https://github.com/JChristensen/Timezone
// Central European Time (Frankfurt, Paris)
time_t local, utc;
int daylightSavingTime = 0;
TimeChangeRule *tcr; // pointer to the time change rule, use to get TZ abbrev
TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; // Central European Summer Time
TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central European Standard Time
Timezone myTZ(CEST, CET);
// declare functions
void printDateTime(time_t t, const char *tz);
void setup()
{
Serial.begin(115200);
setTime(23, 59, 40, 30, 10, 2021); //another way to set the time (hr,min,sec,day,mnth,yr)
}
void loop()
{
utc = now();
local = myTZ.toLocal(utc, &tcr);
Serial.println();
printDateTime(utc, "UTC ");
printDateTime(local, tcr->abbrev);
daylightSavingTime = myTZ.locIsDST(local));
Serial.print(" is DST? " + String(daylightSavingTime));
delay(30);// delay shortened here and in Time.cpp to speed up time zone change
}
// format and print a time_t value, with a time zone appended.
void printDateTime(time_t t, const char *tz)
{
char buf[32];
char m[4]; // temporary storage for month string (DateStrings.cpp uses shared buffer)
strcpy(m, monthShortStr(month(t)));
sprintf(buf, "%.2d:%.2d:%.2d %s %.2d %s %d %s",
hour(t), minute(t), second(t), dayShortStr(weekday(t)), day(t), m, year(t), tz);
Serial.print(buf);
}