ropg / ezTime

ezTime — pronounced "Easy Time" — is a very easy to use Arduino time and date library that provides NTP network time lookups, extensive timezone support, formatted time and date strings, user events, millisecond precision and more.
MIT License
327 stars 92 forks source link

dateTime was ignoring specified local_or_utc value #55

Open TranscendOfSypherus opened 4 years ago

TranscendOfSypherus commented 4 years ago

Line 1210: always assumed the provided time_t was in local time.

thus the following output:

Timezone localTz;
localTz.setLocation("Australia/Melbourne");

// -- works for TIME_NOW as it gets hydrated in local time
Serial.println("Current Time: ");
Serial.print("         UTC: "); Serial.println(UTC.dateTime());
Serial.print("       Local: "); Serial.println(localTz.dateTime());
Serial.println();

// Current Time:
//          UTC: Saturday, 03-Aug-2019 03:56:27 UTC
//        Local: Saturday, 03-Aug-2019 13:56:27 AEST

time_t testTime = 1564953937;
Serial.println("    Simulate: ");
Serial.print("       Local: "); Serial.println(localTz.dateTime(testDate));
Serial.print("       Local: "); Serial.println(localTz.dateTime(testDate, LOCAL_TIME));
Serial.print("       Local: "); Serial.println(localTz.dateTime(testDate, UTC_TIME));

//  Simulate:
//       UTC: Sunday, 04-Aug-2019 21:25:37 UTC
//     Local: Sunday, 04-Aug-2019 11:25:37 AEST
//     Local: Sunday, 04-Aug-2019 11:25:37 AEST
//     Local: Sunday, 04-Aug-2019 11:25:37 AEST <--- wrong

with this PR:

// Current Time:
//          UTC: Saturday, 03-Aug-2019 03:56:27 UTC
//        Local: Saturday, 03-Aug-2019 13:56:27 AEST
//
//  Simulate:
//       UTC: Sunday, 04-Aug-2019 21:25:37 UTC
//     Local: Sunday, 04-Aug-2019 11:25:37 AEST
//     Local: Sunday, 04-Aug-2019 11:25:37 AEST
//     Local: Monday, 05-Aug-2019 07:25:37 AEST <--- correct
Scratchydisk commented 4 years ago

Thanks Transend... I can confirm this addresses an issue I was having when converting UTC to BST.