/* _,.---._ .-._ .--.-. ,--.--------. * _,..---._ ,-.' , - `. /==/ \ .-._/==/ //==/, - , -\ * /==/, - \ /==/_, , - \|==|, \/ /, |==\ -\\==\.-. - ,-./ * |==| _ _\==| .=. |==|- \| | \==\- \`--`\==\- \ * |==| .=. |==|_ : ;=: - |==| , | -| `--`-' \==\_ \ * |==|,| | -|==| , '=' |==| - _ | |==|- | * |==| '=' /\==\ - ,_ /|==| /\ , | |==|, | * |==|-, _`/ '.='. - .' /==/, | |- | /==/ -/ * `-.`.____.' `--`--'' `--`./ `--` `--`--` * _ __ ,---. .-._ .=-.-. _,.----. * .-`.' ,`..--.' \ /==/ \ .-._ /==/_ /.' .' - \ * /==/, - \==\-/\ \ |==|, \/ /, /==|, |/==/ , ,-' * |==| _ .=. /==/-|_\ | |==|- \| ||==| ||==|- | . * |==| , '=',\==\, - \ |==| , | -||==|- ||==|_ `-' \ * |==|- '..'/==/ - ,| |==| - _ ||==| ,||==| _ , | * |==|, | /==/- /\ - \|==| /\ , ||==|- |\==\. / * /==/ - | \==\ _.\=\.-'/==/, | |- |/==/. / `-.`.___.-' * `--`---' `--` `--`./ `--``--`-` * * @(#)Copyright (c) 2024, Nathan D. Fisher. * * This is free software. It comes with NO WARRANTY. * Permission to use, modify and distribute this source code * is granted subject to the following conditions. * 1/ that the above copyright notice and this notice * are preserved in all copies and that due credit be given * to the author. * 2/ that any changes to this code are clearly commented * as such so that the author does not get blamed for bugs * other than his own. */ #include #include // NULL #include // memcmp #include #include "epoch.h" uint8_t monthGetDays(Month month, Year *year) { switch (month) { case January: case March: case May: case July: case August: case October: case December: return 31; case February: switch (year->tag) { case leapYear: return 28; default: return 29; } default: return 30; } } uint32_t monthGetSeconds(Month month, Year *year) { return (int64_t)monthGetDays(month, year) * SECONDS_PER_DAY; } int monthIncrement(Month *month) { if (*month == December) return 1; else *month += 1; return 0; } int monthDecrement(Month *month) { if (*month == January) return 1; else *month -= 1; return 0; } const char *MonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; const char *MonthAbbrs[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; const char* monthName(Month month) { return MonthNames[month - 1]; } const char* monthAbbr(Month month) { return MonthAbbrs[month - 1]; } int parseMonth(const char *s) { int i; for (i = 0; i < 12; i++) { if (strncasecmp(s, MonthAbbrs[i], 4) == 0 || strncasecmp(s, MonthNames[i], 10) == 0) return i + 1; } return -1; }