MoonModules / WLED

Control WS2812B and many more types of digital RGB LEDs with an ESP8266 or ESP32 over WiFi! MoonModules adds features on top of upstream.
https://mm.kno.wled.ge
GNU General Public License v3.0
202 stars 64 forks source link

Scrolling text: support for arbitrary date/time formats #53

Open softhack007 opened 1 year ago

softhack007 commented 1 year ago

Is your feature request related to a problem? Please describe.

The WLED "scrolling text" effect has a few fixed formats to display date or time. Unfortunately people have diverging preferences on how a "digital clock" should look like, plus there are different formats that are considered "normal way" in each nation.

Describe the solution you'd like

The solution could be to allow userdefined time/date formats from the "strftime()" standard function.

https://cplusplus.com/reference/ctime/strftime/

For example, naming a segment "%I:%M%p" would result in "03:21PM" (12hr format, leading zeros, dots, capital letter AM/PM).

Additional context

This is an idea that came up in a discussion on discord. It would be rather simple to implement, because strftime() seems to be availeable on esp32, and WLED already has a feature to convert internal "unixtime" to the tm struct needed by the function.

Maybe a special "marker" would be necessary (like seg name starting with "##") to instruct scrolling text to use strftime format.

Thank you for your ideas for making WLED better!

dosipod commented 1 year ago

Interesting , that would mean you could have day or week in there ? image And might not be linked to the post about time but rather general limitation with text is that its only ASCII

softhack007 commented 1 year ago

Some docs on the "system time" api that also supports strftime() and struct tm

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html#get-current-time

time_t now; 
char strftime_buf[64]; 
struct tm timeinfo;
  // get unix epoch time
  time(&now); 
  // Set timezone to China Standard Time 
  setenv("TZ", "CST-8", 1); 
  tzset();

  localtime_r(&now, &timeinfo); 
  strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); 
   ESP_LOGI(TAG, "The current date/time in Shanghai is: %s", strftime_buf);