diff --git a/include/TIC/DatasetView.h b/include/TIC/DatasetView.h index 6befacf..fc63abf 100644 --- a/include/TIC/DatasetView.h +++ b/include/TIC/DatasetView.h @@ -41,6 +41,14 @@ class Horodate { static Horodate fromLabelBytes(const uint8_t* bytes, unsigned int count); + /** + * @brief Make the current horodate go forward a given seconds in time + * + * @param seconds The seconds to add + * @return true if the result is in the same day as the original value, false otherwise (in that case, the current horodate is *not* modified, calculation in cancelled) + */ + bool addSeconds(unsigned int seconds); + private: /** * @brief Comparison of timestamps with another horodate @@ -128,4 +136,11 @@ class DatasetView { unsigned int dataSz; /*!< The size of the label in bytes */ Horodate horodate; /*!< The horodate for this dataset */ }; -} // namespace TIC \ No newline at end of file +} // namespace TIC + +#ifdef __TIC_LIB_USE_STD_STRING__ +/* std::to_string() for Horodate */ +namespace std { + std::string to_string(const TIC::Horodate& horodate); +} +#endif diff --git a/src/TIC/DatasetView.cpp b/src/TIC/DatasetView.cpp index 47262e6..1780e80 100644 --- a/src/TIC/DatasetView.cpp +++ b/src/TIC/DatasetView.cpp @@ -70,6 +70,28 @@ TIC::Horodate TIC::Horodate::fromLabelBytes(const uint8_t* bytes, unsigned int c return result; } +bool TIC::Horodate::addSeconds(unsigned int seconds) { + uint8_t initialSecond = this->second; + uint8_t initialMinute = this->minute; + uint8_t initialHour = this->hour; + this->second+=30; /* Forward in time */ + if (this->second < 60) + return true; + this->second = 0; + this->minute++; + if (this->minute < 60) + return true; + this->minute = 0; + this->hour++; + if (this->hour < 24) + return true; + /* Day overflow, cancel calculation, reset to initial values */ + this->hour = initialHour; + this->minute = initialMinute; + this->second = initialSecond; + return false; +} + int TIC::Horodate::timeStampOnlyCmp(const TIC::Horodate& other) const { if (this->year > other.year) return 1; if (this->year < other.year) return -1;