Daily Light Time Zone

What the is the best way to set time zone for DST on and DST off:

right now I do the following since I’m eastern time zone(-4).

if (Time.isDST() )
{
Time.zone(-4);
}else
{
Time.zone(-5);
}
char timeBuffer[32] = “”;
sprintf(timeBuffer, “Time:%2d:%02d:%02d\tDate:%02d/%02d/%4d”, Time.hour(), Time.minute(), Time.second(), Time.month(), Time.day(), Time.year());
Serial.println(timeBuffer);
delay(2000);

Would this be the best way to do this?

I don't think isDST() works (the way you're using it). I use this function,

void setZone() {
	int month = Time.month();
	int day = Time.day();
	int weekday = Time.weekday();
	int previousSunday = day - weekday + 1;

	if (month < 3 || month > 11) {
		Time.zone(-8);
	}else if (month > 3 && month < 11) {
		Time.zone(-7);
	}else if (month == 3) {
		int offset = (previousSunday >= 8)? -7 : -8;
		Time.zone(offset);
	} else{
		int offset = (previousSunday <= 0)? -7 : -8;
		Time.zone(offset);
	}
}

You would just need to change the -7 and -8 to -4 and -5 for the Eastern time zone.

2 Likes

Thanks that runs great… …question how offen would you run this, like in a loop or many be every minute?

I call it once every day at 3AM. How often you call it depends on when you need the correct time on the 2 days every year when the time changes. I don't care about the middle of the night for my use, so that's why I do it (as well as sync the time with the cloud, and other once per day items) at 3 AM.