Open aliceand opened 7 years ago
The value used forUTC_OFFSET
should be the standard time offset from UTC.
The configTime()
function is a standard part of the esp8266 Arduino library - but it does not implement Daylight Time change (yet?).
The way that simpleDSTadjust library works is that the call to dstAdjusted.time()
takes care of returning standard time or daylight savings time based on the StartRule
and EndRule
. In the example, the EDT StartRule
adds 3600 sec (1 hour) to implement Daylight time = UTC/GMT -4 hours. The EndRule
adds 0 sec ie: no change to standard time.
I try to add offset of 4:30 into the UTC_OFFSET by:
But it seems just the decimal part will be added into the time and I have 4 hours offset, is the above syntax okey?
I think the syntax is good, especially for the added functionality it provides.
From: Mohammad Sent: Friday, April 28, 2017 12:44 AM To: neptune2/simpleDSTadjust Cc: aliceand ; Author Subject: Re: [neptune2/simpleDSTadjust] UTC OFFSET Configuration (#2)
I try to add offset of 4:30 into the UTC_OFFSET by:
But it seems just the decimal part will be added into the time and I have 4 hours offset, is the above syntax okey?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
@gr8linux Unfortunately, you cannot use #define UTC_OFFSET 4.5
(with non integer offsets).
The problem is that configTime()
arduino library function correctly multiples UTC_OFFSET by 3600 and calls the sntp_set_timezone()
esp8266 SDK library function which then divides the argument by 3600 to calculate the timezone. Unfortunately sntp_set_timezone()
only only accepts integer hour timezones (a bug). Obviously this does not work for countries such as Iran, India and others that use non-integer hour offsets from UTC.
See https://github.com/esp8266/Arduino/blob/master/cores/esp8266/time.c and https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf
HOWEVER, there is a way to work around this with my simpleDSTadjust library.
The following is an example for Iran that has a 4:30 offset from UTC today. (I assume this is why you want a 4:30 UTC offset). Note the switchover rule times are close but not 100% accurate.
#define UTC_OFFSET 3
struct dstRule StartRule = {"IRDT", Fourth, Wed, Mar, 0, 5400}; // Iran Daylight time = UTC/GMT +4:30 hours
struct dstRule EndRule = {"IRST", Fourth, Fri, Sep, 0, 1800}; // Iran Standard time = UTC/GMT +3:30 hours
Note: This rule works for 2017 but may break in the future since Iran does not use rule based dates for determining the Daylight/Standard time changes. See https://www.timeanddate.com/time/change/iran for details.
I looked at the use of simpleDSTadjust in the esp8266-weather-station-color-DST project.
One thing isn't clear: what value should be used for UTC_OFFSET (Standard Time offset or Daylight Time offset)? In the example it looks like Standard Time was used. I'm confused because configTime(UTC_OFFSET * 3600, 0, NTP_SERVERS); uses the constant, and seems to ignore simpleDSTadjust.