days_in_month.cpp 639 B

12345678910111213141516171819202122232425262728
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/date_time.h>
  5. namespace __vic {
  6. //----------------------------------------------------------------------------
  7. int days_in_month(int mon, int year) noexcept
  8. {
  9. // 1 2 3 4 5 6 7 8 9 10 11 12
  10. // 31 28/29 31 30 31 30 31 31 30 31 30 31
  11. switch(mon)
  12. {
  13. case 1: case 3: case 5: case 7: case 8: case 10: case 12:
  14. return 31;
  15. case 4: case 6: case 9: case 11:
  16. return 30;
  17. case 2:
  18. return is_leap_year(year) ? 29 : 28;
  19. }
  20. return 0;
  21. }
  22. //----------------------------------------------------------------------------
  23. } // namespace