| 12 | } |
| 13 | |
| 14 | void execute() override |
| 15 | { |
| 16 | Serial << _F("time_t is ") << sizeof(time_t) * 8 << _F(" bits") << endl; |
| 17 | |
| 18 | TEST_CASE("fromHttpDate()") |
| 19 | { |
| 20 | checkHttpDates(VALID_HTTP_DATE); |
| 21 | } |
| 22 | |
| 23 | TEST_CASE("fromISO8601 (32-bit)") |
| 24 | { |
| 25 | checkIsoTimes(VALID_ISO_DATETIME, false); |
| 26 | } |
| 27 | |
| 28 | TEST_CASE("fromISO8601 (time only)") |
| 29 | { |
| 30 | checkIsoTimes(VALID_ISO_TIME, true); |
| 31 | } |
| 32 | |
| 33 | if(sizeof(time_t) == 8) { |
| 34 | TEST_CASE("fromISO8601 (64-bit)") |
| 35 | { |
| 36 | checkIsoTimes(VALID_ISO_DATETIME64, false); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | TEST_CASE("fromISO8601 with offset") |
| 41 | { |
| 42 | auto check = [&](const String& strWithOffset, const String& strUtc, time_t time, int offsetMins) { |
| 43 | DateTime dt; |
| 44 | // Without zone, offset is applied to time |
| 45 | CHECK(dt.fromISO8601(strWithOffset)); |
| 46 | REQUIRE_EQ(dt.toUnixTime(), time); |
| 47 | REQUIRE_EQ(dt.toISO8601(), strUtc); |
| 48 | // With zone, get local time plus offset |
| 49 | DateTime::ZoneInfo zoneInfo; |
| 50 | CHECK(dt.fromISO8601(strWithOffset, &zoneInfo)); |
| 51 | REQUIRE_EQ(dt.toUnixTime(), time + (offsetMins * 60)); |
| 52 | REQUIRE_EQ(zoneInfo.offsetMins, offsetMins); |
| 53 | REQUIRE_EQ(dt.toISO8601(&zoneInfo), strWithOffset); |
| 54 | }; |
| 55 | |
| 56 | check(F("2024-05-22T06:28:15+12:45"), F("2024-05-21T17:43:15Z"), 1716313395, 12 * 60 + 45); |
| 57 | check(F("2024-05-22T06:28:15-23:45"), F("2024-05-23T06:13:15Z"), 1716444795, -(23 * 60 + 45)); |
| 58 | } |
| 59 | |
| 60 | TEST_CASE("setTime") |
| 61 | { |
| 62 | checkSetTime(VALID_HTTP_DATE); |
| 63 | checkSetTime(VALID_ISO_DATETIME); |
| 64 | if(sizeof(time_t) == 8) { |
| 65 | checkSetTime(VALID_ISO_DATETIME64); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | TEST_CASE("setTime speed check") |
| 70 | { |
| 71 | OneShotFastUs timer; |
nothing calls this directly
no test coverage detected