Skip to content

Instantly share code, notes, and snippets.

/struct Secret

Created March 7, 2016 19:05
Show Gist options
  • Save anonymous/d6b7654bdfce13e97e7e to your computer and use it in GitHub Desktop.
Save anonymous/d6b7654bdfce13e97e7e to your computer and use it in GitHub Desktop.
struct STimeStamp
{
/** Default (empty) constructor */
STimeStamp() : Days(0), Secs(0), USecs(0) {}
/** Copy constructor
@param _obj Time Stamp to be copied */
STimeStamp(const STimeStamp& _obj) : Days(_obj.Days), Secs(_obj.Secs), USecs(_obj.USecs) {}
/** Returns true if time stamp is set to any value (<b>Not</b> to reasonable one)*/
bool isValid(void) { return !(Days==0 && Secs==0 && USecs==0); }
/** normalize time stamp.
This method sets all fields in time stamp to proper range */
void normalize() {
while (USecs > 1e6) {
Secs++;
USecs = (unsigned)(USecs - 1e6);
}
while (Secs > 86400) {
Days++;
Secs = (unsigned)(Secs - 86400);
}
}
/** Reset time stamp to improper value */
void reset(void) { Days=0; Secs=0; USecs=0; }
/** Date */
unsigned Days;
/** Time - seconds */
unsigned Secs;
/** Time - useconds */
unsigned USecs;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment