<div dir="ltr">Elevator pitch:<br><br>(2.5h - 14min + 9300ms).total_seconds()<br># 8169.3<br><br>from datetime import datetime as dt<br>start = dt.now()<br>end = dt.now()<br>(end-start) < 5s<br># True<br><br><br>chrono::duration:<br><br>In C++ 14 the std::chrono::duration was introduced which corresponds somewhat to<br>datetime.timedelta.<br><br>C++ 14 introduced so-called chrono literals[1], which are literals specified as<br>[number][h|min|s|ms|us|ns], e.g.<br><br>* 2.5h<br>* 14min<br>* 9300ms<br><br>These literals should correspond to<br><br>* datetime.timedelta(0, 9000)  # 2.5h = 2.5*3600 = 9000 seconds<br>* datetime.timedelta(0, 840)   # 14min = 14*60 = 840 seconds<br>* datetime.timedelta(0, 9, 300000)  # 9300ms = 9 seconds + 3*10^5 microseconds<br><br><br>If a literal was interpreted as a datetime.timedelta, the following would work<br>out of the box:<br><br>2.5h - 14min + 9300ms * 2<br><br>which would correspond to<br><br>from datetime import timedelta as D<br><br>D(hours=2.5) - D(minutes=14) + D(milliseconds=9300) * 2<br># datetime.timedelta(0, 8178, 600000)  # (*2 precedes, so that's to be expected)<br><br><br>(D(hours=2.5) - D(minutes=14) + D(milliseconds=9300)) * 2<br># datetime.timedelta(0, 16338, 600000)<br><br><br><br>Notes:<br><br>* C++ uses `min` instead of `m`.  `min` is a keyword in Python.<br>* In C++, `1d` means the first day of a month [2].<br>* In C++, `1990y` means the year 1990 (in the Proleptic Gregorian calendar) [3].<br>* C++ have the types signed integers and not floats, so 2.5h would not be valid.<br>* My apologies if this has been discussed before; my search-fu gave me nothing.<br><br><br><br>References:<br><br><br>[1] std::literals::chrono_literals::operator""min<br><a href="http://en.cppreference.com/w/cpp/chrono/operator%22%22min">http://en.cppreference.com/w/cpp/chrono/operator%22%22min</a><br><br>[2] <a href="http://en.cppreference.com/w/cpp/chrono/day">http://en.cppreference.com/w/cpp/chrono/day</a><br><br><div>[3] <a href="http://en.cppreference.com/w/cpp/chrono/year">http://en.cppreference.com/w/cpp/chrono/year</a></div><div><br></div><div><br></div><div>Best regards,</div><div>Pål Grønås Drange</div><div><br></div></div>