Skip to content

Commit

Permalink
Adding TIC::Horodate::addSeconds()
Browse files Browse the repository at this point in the history
  • Loading branch information
lains committed Jun 14, 2023
1 parent 9e95e7d commit 0a3349c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
17 changes: 16 additions & 1 deletion include/TIC/DatasetView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
} // namespace TIC

#ifdef __TIC_LIB_USE_STD_STRING__
/* std::to_string() for Horodate */
namespace std {
std::string to_string(const TIC::Horodate& horodate);
}
#endif
22 changes: 22 additions & 0 deletions src/TIC/DatasetView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0a3349c

Please sign in to comment.