validate_date_time.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/date_time.h>
  5. #include<__vic/string_buffer.h>
  6. namespace __vic {
  7. //----------------------------------------------------------------------------
  8. // y != 0 , m - 1..12, d - 1..{28..31}
  9. void validate_date(int y, int m, int d)
  10. {
  11. if(y == 0) throw invalid_date("Invalid year 0");
  12. if(m < 1 || m > 12) throw invalid_date(__vic::msg(32) <<
  13. "Invalid month " << m);
  14. if(d < 1 || d > days_in_month(m, y)) throw invalid_date(__vic::msg(32) <<
  15. "Invalid day of month " << d);
  16. }
  17. //----------------------------------------------------------------------------
  18. // h - 0..23, m - 0..59, s - 0..59
  19. void validate_time(int h, int m, int s)
  20. {
  21. if(h < 0 || h > 23) throw invalid_date(__vic::msg(32) <<
  22. "Invalid hours " << h);
  23. if(m < 0 || m > 59) throw invalid_date(__vic::msg(32) <<
  24. "Invalid minutes " << m);
  25. if(s < 0 || s > 59) throw invalid_date(__vic::msg(32) <<
  26. "Invalid seconds " << s);
  27. }
  28. //----------------------------------------------------------------------------
  29. } // namespace