Check Expiration Date in C++11

I am working in C++11 and am looking to calculate the expiration date of an item based on its issue date. If the item as issued more than 30 days ago, it should be expired:

#include <ctime>

bool isExpired() {

    std::chrono::system_clock::time_point tend = tstart + std::chrono::hours(30 * 24);
    std::chrono::system_clock::time_point tnow = std::chrono::system_clock::now();

    bool expired = tnow >= tend;
    return expired;
}

however, I don’t seem to be able to concisely input a start date. Some other questions indicated that some like

auto ymd = jun/9/2017; // Yields a year_month_day type
std::chrono::system_clock::time_point tstart = sys_days(ymd);

Might work in C++11 but Xcode certainly doesn’t like it and I’m unsure if I’m straddling C++14 and above features.

What is a concise way to perform this calculation in c++11?

Answer

If I correctly understood your question (run it):

#include <iostream>
#include <chrono>
#include <sstream>
#include <iomanip>

bool is_expired( std::chrono::system_clock::time_point issued_time )
{
  using namespace std;
  using namespace std::chrono;
  typedef duration< int, ratio_multiply < hours::period, ratio<24> >::type > days;
  return duration_cast< days >( system_clock::now() - issued_time ) > days { 30 };
}

auto operator""_issued( const char* s ) // see http://e...content-available-to-author-only...e.com/w/cpp/language/user_literal
{
  std::istringstream iss { s };
  std::tm t {};
  iss >> std::get_time( &t, "%Y%m%d" );
  return std::chrono::system_clock::from_time_t( std::mktime( &t ) );
}

int main()
{
  std::cout << (is_expired( 20170101_issued ) ? "expired" : "valid") << std::endl;
  std::cout << (is_expired( 22000601_issued ) ? "expired" : "valid") << std::endl;
  return 0;
}