arduino-libraries / NTPClient

Connect to a NTP server
554 stars 376 forks source link

Added getFormattedDateTime method #207

Open leodrivera opened 6 months ago

leodrivera commented 6 months ago

Implement getFormattedDateTime, which has the advantage, when compared #94 that does not rely on external lib and parse more patterns. The #161 was used as base, however, I had to change all the calculation logic, as the results were not correct

Patterns

  %Y: Full year (e.g., 2023)
  %y: Last two digits of the year (e.g., 23 for 2023)
  %m: Month as a zero-padded decimal number (01 to 12)
  %d: Day of the month as a zero-padded decimal number (01 to 31)
  %H: Hour (00 to 23) as a zero-padded decimal number
  %M: Minute as a zero-padded decimal number (00 to 59)
  %S: Second as a zero-padded decimal number (00 to 59)
  %a: Abbreviated weekday name according to the current locale
  %A: Full weekday name according to the current locale
  %w: Weekday as a decimal number (0 for Sunday through 6 for Saturday)
  %b: Abbreviated month name according to the current locale
  %B: Full month name according to the current locale
  %p: "AM" or "PM" based on the hour (Note: This is locale-sensitive and might not be applicable in all languages)

With this new method, getFormattedTime loses the meaning of existing, given that we can obtain the same result through the parameter "%H:%M:%S"

timeClient.getFormattedDateTime("%H:%M:%S")

CLAassistant commented 6 months ago

CLA assistant check
All committers have signed the CLA.

github-actions[bot] commented 6 months ago

Memory usage change @ 3b359ebe1848a887e7947339ce2e992f20a40d52

Board flash % RAM for global variables %
esp8266:esp8266:huzzah N/A N/A N/A N/A
Click for full report table Board|`examples/Advanced`
flash|%|`examples/Advanced`
RAM for global variables|%|`examples/Basic`
flash|%|`examples/Basic`
RAM for global variables|%|`examples/FormattedDateTime`
flash|%|`examples/FormattedDateTime`
RAM for global variables|%|`examples/IsTimeSet`
flash|%|`examples/IsTimeSet`
RAM for global variables|% -|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|- `esp8266:esp8266:huzzah`|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A
Click for full report CSV ``` Board,examples/Advanced
flash,%,examples/Advanced
RAM for global variables,%,examples/Basic
flash,%,examples/Basic
RAM for global variables,%,examples/FormattedDateTime
flash,%,examples/FormattedDateTime
RAM for global variables,%,examples/IsTimeSet
flash,%,examples/IsTimeSet
RAM for global variables,% esp8266:esp8266:huzzah,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A ```
github-actions[bot] commented 6 months ago

Memory usage change @ 5b5c3178e554f9b75ac8983a92a0e03b128a6247

Board flash % RAM for global variables %
esp8266:esp8266:huzzah N/A N/A N/A N/A
Click for full report table Board|`examples/Advanced`
flash|%|`examples/Advanced`
RAM for global variables|%|`examples/Basic`
flash|%|`examples/Basic`
RAM for global variables|%|`examples/FormattedDateTime`
flash|%|`examples/FormattedDateTime`
RAM for global variables|%|`examples/IsTimeSet`
flash|%|`examples/IsTimeSet`
RAM for global variables|% -|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|- `esp8266:esp8266:huzzah`|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A
Click for full report CSV ``` Board,examples/Advanced
flash,%,examples/Advanced
RAM for global variables,%,examples/Basic
flash,%,examples/Basic
RAM for global variables,%,examples/FormattedDateTime
flash,%,examples/FormattedDateTime
RAM for global variables,%,examples/IsTimeSet
flash,%,examples/IsTimeSet
RAM for global variables,% esp8266:esp8266:huzzah,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A ```
nricciardi commented 1 week ago

Any updates?