Created
May 2, 2022 08:42
-
-
Save tuanpmt/f88e81d0c32ee20746bf03c19201b5fe to your computer and use it in GitHub Desktop.
Keep it simple, stupid
This file contains 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
//for understanding weekday2 there are more details to think about | |
const char *weekday2(int dayOfWeek) | |
{ | |
if ((dayOfWeek < 1) || (dayOfWeek > 7)) { | |
ESP_LOGE(TAG, "dayOfWeek must be in range 1..7"); | |
return NULL; | |
} | |
const char *weekdays = { | |
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" | |
}; | |
return weekdays[dayOfWeek - 1]; | |
} | |
// Simple, easy to understand | |
const char *weekday1(int dayOfWeek) | |
{ | |
switch (dayOfWeek) { | |
case 1: return "Monday"; | |
case 2: return "Tuesday"; | |
case 3: return "Wednesday"; | |
case 4: return "Thursday"; | |
case 5: return "Friday"; | |
case 6: return "Saturday"; | |
case 7: return "Sunday"; | |
default: ESP_LOGE(TAG, "dayOfWeek must be in range 1..7"); | |
} | |
return NULL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment