-
Notifications
You must be signed in to change notification settings - Fork 356
added: settings for customizing time zone and DST #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
typedef struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly recommend against storing the strings in the server. Rather, store only in the client (e.g., HTML webpage). In addition, I would not store the index to the array, but rather the utcOffsetInSeconds itself. More reasons given below. For fun, see video of why timezones are hard. |
||
long utcOffsetInSeconds; | ||
String utcOffset; | ||
String region; | ||
} TimeZone; | ||
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I strongly recommend NOT storing the strings in the server code. Rather, have the server code store the following:
More info below. For fun, check out this video on why timezones are hard. |
||
typedef TimeZone TimeZoneList[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend removing this typedef. You call it a "list", but it's actually an array, which is a different data structure.... |
||
|
||
const TimeZoneList timeZones = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend not storing string values in this data structure. |
||
{-43200, "UTC−12:00", "Baker Island, Howland Island (both uninhabited)"}, | ||
{-39600, "UTC−11:00", "American Samoa, Niue"}, | ||
{-36000, "UTC−10:00", "Honolulu"}, | ||
{-34200, "UTC−09:30", "Marquesas Islands"}, | ||
{-32400, "UTC−09:00", "Anchorage"}, | ||
{-28800, "UTC−08:00", "Los Angeles, Vancouver, Tijuana"}, | ||
{-25200, "UTC−07:00", "Phoenix, Calgary, Ciudad Juárez"}, | ||
{-21600, "UTC−06:00", "Mexico City, Chicago, Guatemala City, Tegucigalpa, Winnipeg, San José, San Salvador"}, | ||
{-18000, "UTC−05:00", "New York, Toronto, Havana, Lima, Bogotá, Kingston"}, | ||
{-14400, "UTC−04:00", "Santiago, Santo Domingo, Manaus, Caracas, La Paz, Halifax"}, | ||
{-12600, "UTC−03:30", "St. John’s"}, | ||
{-10800, "UTC−03:00", "São Paulo, Buenos Aires, Montevideo"}, | ||
{ -7200, "UTC−02:00", "Brazil (Fernando de Noronha), South Georgia and the South Sandwich Islands"}, | ||
{ -3600, "UTC−01:00", "Cape Verde"}, | ||
{ 0, "UTC±00:00", "London, Dublin, Lisbon, Abidjan, Accra, Dakar"}, | ||
{ 3600, "UTC+01:00", "Berlin, Rome, Paris, Madrid, Warsaw, Lagos, Kinshasa, Algiers, Casablanca"}, | ||
{ 7200, "UTC+02:00", "Cairo, Johannesburg, Khartoum, Kiev, Bucharest, Athens, Jerusalem, Sofia"}, | ||
{ 10800, "UTC+03:00", "Moscow, Istanbul, Riyadh, Baghdad, Addis Ababa, Doha"}, | ||
{ 12600, "UTC+03:30", "Tehran"}, | ||
{ 14400, "UTC+04:00", "Dubai, Baku, Tbilisi, Yerevan, Samara"}, | ||
{ 16200, "UTC+04:30", "Kabul"}, | ||
{ 18000, "UTC+05:00", "Karachi, Tashkent, Yekaterinburg"}, | ||
{ 19800, "UTC+05:30", "Mumbai, Colombo"}, | ||
{ 20700, "UTC+05:45", "Kathmandu"}, | ||
{ 21600, "UTC+06:00", "Dhaka, Almaty, Omsk"}, | ||
{ 23400, "UTC+06:30", "Yangon"}, | ||
{ 25200, "UTC+07:00", "Jakarta, Ho Chi Minh City, Bangkok, Krasnoyarsk"}, | ||
{ 28800, "UTC+08:00", "Shanghai, Taipei, Kuala Lumpur, Singapore, Perth, Manila, Makassar, Irkutsk"}, | ||
{ 31500, "UTC+08:45", "Australia (Eucla) unofficial"}, | ||
{ 32400, "UTC+09:00", "Tokyo, Seoul, Pyongyang, Ambon, Yakutsk"}, | ||
{ 34200, "UTC+09:30", "Adelaide"}, | ||
{ 36000, "UTC+10:00", "Sydney, Port Moresby, Vladivostok"}, | ||
{ 37800, "UTC+10:30", "Lord Howe Island"}, | ||
{ 39600, "UTC+11:00", "Nouméa, Magadan"}, | ||
{ 43200, "UTC+12:00", "Auckland, Suva, Petropavlovsk-Kamchatsky"}, | ||
{ 45900, "UTC+12:45", "Chatham Islands"}, | ||
{ 46800, "UTC+13:00", "Kiribati (Phoenix Islands), Tonga, Tokelau"}, | ||
{ 50400, "UTC+14:00", "Kiribati (Line Islands)"} | ||
}; | ||
|
||
const uint8_t timeZoneCount = ARRAY_SIZE(timeZones); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,8 @@ unsigned long autoPlayTimeout = 0; | |
|
||
uint8_t showClock = 0; | ||
uint8_t clockBackgroundFade = 240; | ||
uint8_t currentTimeZoneIndex = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would now be called |
||
uint8_t dst = 0; // daylight saving on/off | ||
|
||
uint8_t currentPaletteIndex = 0; | ||
|
||
|
@@ -286,6 +288,7 @@ PatternAndNameList patterns = { | |
|
||
const uint8_t patternCount = ARRAY_SIZE(patterns); | ||
|
||
#include "TimeZones.h" | ||
#include "Fields.h" | ||
|
||
void setup() { | ||
|
@@ -511,6 +514,18 @@ void setup() { | |
sendInt(clockBackgroundFade); | ||
}); | ||
|
||
webServer.on("/timeZone", HTTP_POST, []() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the server side, I would recommend AGAINST storing the setting as an index into the array. Instead, I would recommend allowing the user to indicate any offset from UTC they want. Storing that value == stability across releases, and when geopolitical things change. Although not required here, if wanting to display multiple options for the same time zone offset (e.g., list London separately from Dakar), can also simply store a stable differentiator (e.g., int) that the client can use to find/display the proper string. Why do this?
|
||
String value = webServer.arg("value"); | ||
setTimeZone(value.toInt()); | ||
sendInt(currentTimeZoneIndex); | ||
}); | ||
Comment on lines
+517
to
+521
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be an index into an array, because the first change in the list (adding/removing a timezone) will either make the list not sorted, or will cause any stored values on existing devices to change timezone on upgrade. That's just a bug waiting to happen. |
||
|
||
webServer.on("/dst", HTTP_POST, []() { | ||
String value = webServer.arg("value"); | ||
setDst(value.toInt()); | ||
sendInt(dst); | ||
}); | ||
Comment on lines
+523
to
+527
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Daylight Saving Time is not a boolean True/False. Currently, those timezones that use DST all happen to offset by exactly one hour. However, when DST begins and ends is not always the same. Recommend to change this to store the following data:
Want to learn more? See http://ontimezone.com/exceptions.php.
Comment on lines
+523
to
+527
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Daylight Saving Time is, unfortunately, not a Existing rules that I am aware of include:
See, for example, http://ontimezone.com/exceptions.php for some differences, or view the fun video on timezones linked above. |
||
|
||
//list directory | ||
webServer.on("/list", HTTP_GET, handleFileList); | ||
//load editor | ||
|
@@ -921,6 +936,14 @@ void loadSettings() | |
|
||
showClock = EEPROM.read(9); | ||
clockBackgroundFade = EEPROM.read(10); | ||
|
||
currentTimeZoneIndex = EEPROM.read(11); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would need updates if accepting the above recommendations. In short: |
||
if (currentTimeZoneIndex < 0) | ||
currentTimeZoneIndex = 0; | ||
else if (currentTimeZoneIndex >= timeZoneCount) | ||
currentTimeZoneIndex = timeZoneCount -1; | ||
dst = EEPROM.read(12); | ||
timeClient.setTimeOffset(timeZones[currentTimeZoneIndex].utcOffsetInSeconds + (dst ? 3600 : 0)); | ||
} | ||
|
||
void setPower(uint8_t value) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These would all change, if accepting my recommendations below.