Skip to content

Commit

Permalink
Merge pull request #29 from nullstalgia/timezones
Browse files Browse the repository at this point in the history
Timezones from WorldClock example
  • Loading branch information
sidoh authored Apr 4, 2020
2 parents 9f9cf08 + 8831499 commit df75b03
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 32 deletions.
78 changes: 51 additions & 27 deletions lib/Time/Timezones.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,62 @@
#include <Timezones.h>

//United Kingdom (London, Belfast)
static TimeChangeRule BST = {"BST", Last, Sun, Mar, 1, 60}; //British Summer Time
static TimeChangeRule GMT = {"GMT", Last, Sun, Oct, 2, 0}; //Standard Time
static Timezone UK(BST, GMT);

//US Eastern Time Zone (New York, Detroit)
static TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; //Eastern Daylight Time = UTC - 4 hours
static TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; //Eastern Standard Time = UTC - 5 hours
static Timezone usET(usEDT, usEST);

//US Central Time Zone (Chicago, Houston)
static TimeChangeRule usCDT = {"CDT", Second, dowSunday, Mar, 2, -300};
static TimeChangeRule usCST = {"CST", First, dowSunday, Nov, 2, -360};
static Timezone usCT(usCDT, usCST);

//US Mountain Time Zone (Denver, Salt Lake City)
static TimeChangeRule usMDT = {"MDT", Second, dowSunday, Mar, 2, -360};
static TimeChangeRule usMST = {"MST", First, dowSunday, Nov, 2, -420};
static Timezone usMT(usMDT, usMST);

//Arizona is US Mountain Time Zone but does not use DST
static Timezone usAZ(usMST, usMST);

//US Pacific Time Zone (Las Vegas, Los Angeles)
static TimeChangeRule usPDT = {"PDT", Second, dowSunday, Mar, 2, -420};
static TimeChangeRule usPST = {"PST", First, dowSunday, Nov, 2, -480};
static Timezone usPT(usPDT, usPST);
// https://github.com/JChristensen/Timezone/blob/master/examples/WorldClock/WorldClock.ino

// Australia Eastern Time Zone (Sydney, Melbourne)
TimeChangeRule aEDT = {"AEDT", First, Sun, Oct, 2, 660}; // UTC + 11 hours
TimeChangeRule aEST = {"AEST", First, Sun, Apr, 3, 600}; // UTC + 10 hours
Timezone ausET(aEDT, aEST);

// Moscow Standard Time (MSK, does not observe DST)
TimeChangeRule msk = {"MSK", Last, Sun, Mar, 1, 180};
Timezone tzMSK(msk);

// Central European Time (Frankfurt, Paris)
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 CE(CEST, CET);

// United Kingdom (London, Belfast)
TimeChangeRule BST = {"BST", Last, Sun, Mar, 1, 60}; // British Summer Time
TimeChangeRule GMT = {"GMT", Last, Sun, Oct, 2, 0}; // Standard Time
Timezone UK(BST, GMT);

// UTC
TimeChangeRule utcRule = {"UTC", Last, Sun, Mar, 1, 0}; // UTC
Timezone UTC(utcRule);

// US Eastern Time Zone (New York, Detroit)
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; // Eastern Daylight Time = UTC - 4 hours
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; // Eastern Standard Time = UTC - 5 hours
Timezone usET(usEDT, usEST);

// US Central Time Zone (Chicago, Houston)
TimeChangeRule usCDT = {"CDT", Second, Sun, Mar, 2, -300};
TimeChangeRule usCST = {"CST", First, Sun, Nov, 2, -360};
Timezone usCT(usCDT, usCST);

// US Mountain Time Zone (Denver, Salt Lake City)
TimeChangeRule usMDT = {"MDT", Second, Sun, Mar, 2, -360};
TimeChangeRule usMST = {"MST", First, Sun, Nov, 2, -420};
Timezone usMT(usMDT, usMST);

// Arizona is US Mountain Time Zone but does not use DST
Timezone usAZ(usMST);

// US Pacific Time Zone (Las Vegas, Los Angeles)
TimeChangeRule usPDT = {"PDT", Second, Sun, Mar, 2, -420};
TimeChangeRule usPST = {"PST", First, Sun, Nov, 2, -480};
Timezone usPT(usPDT, usPST);

Timezone& TimezonesClass::DEFAULT_TIMEZONE = usPT;
const char* TimezonesClass::DEFAULT_TIMEZONE_NAME = "PT";

TimezonesClass::TimezonesClass() {
timezonesByName["AUSET"] = &ausET;
timezonesByName["MSK"] = &tzMSK;
timezonesByName["CET"] = &CE;
timezonesByName["UK"] = &UK;
timezonesByName["UTC"] = &UTC;
timezonesByName["ET"] = &usET;
timezonesByName["CT"] = &usCT;
timezonesByName["MT"] = &usMT;
Expand Down
19 changes: 14 additions & 5 deletions web/src/settings/schema/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ export default {
"system.timezone": {
$id: "#/properties/system.timezone",
type: "string",
enum: [
"PT", "MT", "AZ", "CT", "ET", "UK"
oneOf: [
{ const: "PT", title: "(GMT-07:00) Pacific Time" },
{ const: "AZ", title: "(GMT-06:00) Arizona Time" },
{ const: "MT", title: "(GMT-06:00) Mountain Time" },
{ const: "CT", title: "(GMT-05:00) Central Time" },
{ const: "ET", title: "(GMT-04:00) Eastern Time" },
{ const: "UTC", title: "(GMT+00:00) Coordinated Universal Time" },
{ const: "UK", title: "(GMT+00:00) Western Europe Time" },
{ const: "CET", title: "(GMT+01:00) Central European Time" },
{ const: "MSK", title: "(GMT+03:00) Moscow Standard Time" },
{ const: "AUSET", title: "(GMT+10:00) Eastern Australia" },
],
title: "Timezone",
default: "",
examples: ["PT"],
pattern: "^(.*)$"
}
}
pattern: "^(.*)$",
},
},
};

0 comments on commit df75b03

Please sign in to comment.