diff --git a/qt_helpers.cpp b/qt_helpers.cpp index 62def121b..3f41d0f87 100644 --- a/qt_helpers.cpp +++ b/qt_helpers.cpp @@ -5,6 +5,7 @@ #include #include #include +#include QString font_as_stylesheet (QFont const& font) { @@ -35,3 +36,15 @@ void update_dynamic_property (QWidget * widget, char const * property, QVariant widget->style ()->polish (widget); widget->update (); } + +QDateTime qt_round_date_time_to (QDateTime dt, int seconds) +{ + dt.setSecsSinceEpoch (dt.addSecs (seconds - 1).toSecsSinceEpoch () / seconds * seconds); + return dt; +} + +QDateTime qt_truncate_date_time_to (QDateTime dt, int seconds) +{ + dt.setSecsSinceEpoch (dt.toSecsSinceEpoch () / seconds * seconds); + return dt; +} diff --git a/qt_helpers.hpp b/qt_helpers.hpp index 33f501437..638c50e2a 100644 --- a/qt_helpers.hpp +++ b/qt_helpers.hpp @@ -69,6 +69,12 @@ QString font_as_stylesheet (QFont const&); // conditional style sheet updates void update_dynamic_property (QWidget *, char const * property, QVariant const& value); +// round a QDateTime instance to an interval +QDateTime qt_round_date_time_to (QDateTime dt, int seconds); + +// truncate a QDateTime to an interval +QDateTime qt_truncate_date_time_to (QDateTime dt, int seconds); + template class VPtr {