Repository navigation
Time zones: update the list to tz 2026e and refresh the saved code #723
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,28 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| namespace tt::settings { | ||
|
|
||
| /** Applies the saved time zone, first updating its code to the bundled timezones.csv row for its name */ | ||
| void initTimeZone(); | ||
|
|
||
| } | ||
| /** | ||
| * Find the code of a time zone in the bundled timezones.csv | ||
| * @param[in] name the time zone name, e.g. "Europe/Amsterdam" | ||
| * @param[out] outCode the code, set only when found | ||
| * @return true when found | ||
| */ | ||
| bool findTimeZoneCode(const std::string& name, std::string& outCode); | ||
|
|
||
| /** | ||
| * Find the code of a time zone in CSV text with the format of timezones.csv (LF or CRLF line endings) | ||
| * @param[in] csv the CSV text | ||
| * @param[in] name the time zone name, e.g. "Europe/Amsterdam" | ||
| * @param[out] outCode the code, set only when found | ||
| * @return true when found | ||
| */ | ||
| bool findTimeZoneCode(std::string_view csv, const std::string& name, std::string& outCode); | ||
|
|
||
| } // namespace tt::settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #include "doctest.h" | ||
|
|
||
| #include <Tactility/settings/Time.h> | ||
| #include <Tactility/settings/TimePrivate.h> | ||
|
|
||
| #include <tactility/paths.h> | ||
| #include <tactility/preferences.h> | ||
|
|
||
| #include <string> | ||
| #include <string_view> | ||
|
|
||
| using namespace tt; | ||
|
|
||
| namespace { | ||
|
|
||
| /** Writes the time zone like an older firmware did, without the radio region and event of setTimeZone() */ | ||
| void saveTimeZone(const char* name, const char* code) { | ||
| char root[128]; | ||
| REQUIRE(paths_get_data_path(root, sizeof(root)) == ERROR_NONE); | ||
| const std::string path = std::string(root) + "/settings/time.properties"; | ||
| Preferences* preferences = preferences_open(path.c_str()); | ||
| REQUIRE(preferences != nullptr); | ||
| preferences_put_string(preferences, "tz_name", name); | ||
| preferences_put_string(preferences, "tz_code", code); | ||
| preferences_close(preferences); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST_CASE("findTimeZoneCode finds the bundled code of a time zone") { | ||
| std::string code; | ||
| CHECK(settings::findTimeZoneCode("Europe/Amsterdam", code)); | ||
| CHECK_EQ(code, "CET-1CEST,M3.5.0,M10.5.0/3"); | ||
| CHECK(settings::findTimeZoneCode("Africa/Abidjan", code)); // first row | ||
| CHECK_EQ(code, "GMT0"); | ||
| CHECK(settings::findTimeZoneCode("Etc/Zulu", code)); // last row | ||
| CHECK_EQ(code, "UTC0"); | ||
| } | ||
|
|
||
| TEST_CASE("findTimeZoneCode only matches whole names") { | ||
| std::string code = "unchanged"; | ||
| CHECK_FALSE(settings::findTimeZoneCode("Europe/Amster", code)); | ||
| CHECK_FALSE(settings::findTimeZoneCode("Amsterdam", code)); | ||
| CHECK_FALSE(settings::findTimeZoneCode("", code)); | ||
| CHECK_FALSE(settings::findTimeZoneCode("Mars/Olympus_Mons", code)); | ||
| CHECK_EQ(code, "unchanged"); | ||
| CHECK(settings::findTimeZoneCode("Etc/GMT+1", code)); | ||
| CHECK_EQ(code, "<-01>1"); | ||
| } | ||
|
|
||
| TEST_CASE("findTimeZoneCode accepts CRLF line endings") { | ||
| const std::string_view csv = "\"Africa/Abidjan\",\"GMT0\"\r\n\"America/Winnipeg\",\"EST5\"\r\n\"Etc/Zulu\",\"UTC0\"\r"; | ||
| std::string code; | ||
| CHECK(settings::findTimeZoneCode(csv, "Africa/Abidjan", code)); | ||
| CHECK_EQ(code, "GMT0"); | ||
| CHECK(settings::findTimeZoneCode(csv, "America/Winnipeg", code)); | ||
| CHECK_EQ(code, "EST5"); | ||
| CHECK(settings::findTimeZoneCode(csv, "Etc/Zulu", code)); // last row, no line feed | ||
| CHECK_EQ(code, "UTC0"); | ||
| } | ||
|
|
||
| TEST_CASE("initTimeZone replaces an outdated saved code with the bundled one") { | ||
| saveTimeZone("America/Winnipeg", "CST6CDT,M3.2.0,M11.1.0"); | ||
| settings::initTimeZone(); | ||
| std::string bundled; | ||
| REQUIRE(settings::findTimeZoneCode("America/Winnipeg", bundled)); | ||
| CHECK_EQ(bundled, "EST5"); // CST all year from 1 November 2026 (IANA tz 2026e) | ||
| CHECK_EQ(settings::getTimeZoneCode(), bundled); | ||
| CHECK_EQ(settings::getTimeZoneName(), "America/Winnipeg"); | ||
| } | ||
|
|
||
| TEST_CASE("initTimeZone keeps a saved code that is current or not in the list") { | ||
| saveTimeZone("Europe/Amsterdam", "CET-1CEST,M3.5.0,M10.5.0/3"); | ||
| settings::initTimeZone(); | ||
| CHECK_EQ(settings::getTimeZoneCode(), "CET-1CEST,M3.5.0,M10.5.0/3"); | ||
|
|
||
| saveTimeZone("Custom/Zone", "<+0530>-5:30"); | ||
| settings::initTimeZone(); | ||
| CHECK_EQ(settings::getTimeZoneCode(), "<+0530>-5:30"); | ||
| CHECK_EQ(settings::getTimeZoneName(), "Custom/Zone"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.