Support Board
Date/Time: Sun, 24 Nov 2024 18:33:49 +0000
Post From: Getting the Seconds between 2 SCDateTime objects, which may or may not be > 24 hrs
[2024-05-22 10:02:53] |
ycomp - Posts: 318 |
/*** Total Seconds (i.e. that can be > 24 hours) ***/
inline constexpr double SECONDS_IN_DAY = 24 * 60 * 60; /** * @param seconds the total seconds * @return the SCDateTime value */ inline SCDateTime fromSeconds(int64_t seconds) { return SCDateTime{ seconds / SECONDS_IN_DAY }; } /** * @param dt the SCDateTime * @return the SCDateTime value as total seconds */ inline int64_t seconds(const SCDateTime& dt) { return static_cast<int64_t>( dt.GetAsDouble() * SECONDS_IN_DAY); } /** * @param dt1 the first SCDateTime * @param dt2 the second SCDateTime * @return the number of seconds between dt1 and dt2 * - positive if dt1 is later than dt2, negative if dt1 is earlier than dt2 */ inline int seconds(const SCDateTime& dt1, const SCDateTime& dt2) { return static_cast<int>( seconds(dt1) - seconds(dt2) ); } |