Skip to content

Instantly share code, notes, and snippets.

@tuanpmt
Created May 2, 2022 08:42
Show Gist options
  • Save tuanpmt/f88e81d0c32ee20746bf03c19201b5fe to your computer and use it in GitHub Desktop.
Save tuanpmt/f88e81d0c32ee20746bf03c19201b5fe to your computer and use it in GitHub Desktop.
Keep it simple, stupid
//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