fork(3) download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <sstream>
  4. #include <iomanip>
  5.  
  6. bool is_expired( std::chrono::system_clock::time_point issued_time )
  7. {
  8. using namespace std;
  9. using namespace std::chrono;
  10. typedef duration< int, ratio_multiply < hours::period, ratio<24> >::type > days;
  11. return duration_cast< days >( system_clock::now() - issued_time ) > days { 30 };
  12. }
  13.  
  14. auto operator""_issued( const char* s ) // see http://e...content-available-to-author-only...e.com/w/cpp/language/user_literal
  15. {
  16. std::istringstream iss { s };
  17. std::tm t {};
  18. iss >> std::get_time( &t, "%Y%m%d" );
  19. return std::chrono::system_clock::from_time_t( std::mktime( &t ) );
  20. }
  21.  
  22. int main()
  23. {
  24. std::cout << (is_expired( 20170101_issued ) ? "expired" : "valid") << std::endl;
  25. std::cout << (is_expired( 22000601_issued ) ? "expired" : "valid") << std::endl;
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5452KB
stdin
Standard input is empty
stdout
expired
valid