Beam-lib  2.16.3
This is the Beam C++ class library.
BTimeUs.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BTimeUs.h BTimeUs functions
3  * T.Barnaby, Beam Ltd, 2018-08-15
4  * Copyright (c) 2018 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  *
7  * Implements a microsecond accurate time class. Stores the time as a number of microseconds
8  * to the TAI standard with no leap seconds. 0 time is 1970-01-02T00:00:00.
9  * The class provides conversions between UTC time and TAI microsecond time (leap second handling)
10  *
11  * Uses some sepcial values.
12  * 0 - DateTime not set.
13  */
14 #ifndef BTimeUs_h
15 #define BTimeUs_h
16 
17 #include <BTypes.h>
18 #include <BError.h>
19 #include <BString.h>
20 #include <BTime.h>
21 
22 class BTimeUs {
23 public:
24  BTimeUs(BUInt64 t = 0);
25  BTimeUs(BTime t);
26 
27  void set(BUInt64 microSeconds);
28  void set(BUInt year, BUInt month, BUInt day, BUInt hour = 0, BUInt minute = 0, BUInt second = 0, BUInt microSecond = 0);
29  void setYearDay(BUInt year, BUInt yearDay, BUInt hour = 0, BUInt minute = 0, BUInt second = 0, BUInt microSecond = 0);
30 
31  void getDate(BUInt& year, BUInt& month, BUInt& day) const;
32  void getTime(BUInt& hour, BUInt& minute, BUInt& second) const;
33  BUInt64 getSeconds() const;
34  BUInt64 getMicroSeconds() const;
35 
36  int isSet() const{ return otime != 0; }
37  int isLeapYear();
38  void addSeconds(BInt64 seconds);
39  void addMicroSeconds(BInt64 microSeconds);
40 
41  BString getString(BString format = "isoT") const;
42  BString getStringUs(BString format = "isoT") const;
43  BError setString(const BString dateTime);
44 
45  // Operator functions
46  operator BTime() const { return BTime(getSeconds()); }
47  int operator==(const BTimeUs& time) const { return (otime == time.otime); }
48  int operator!=(const BTimeUs& time) const { return (otime != time.otime); }
49  int operator>(const BTimeUs& time) const { return (otime > time.otime); }
50  int operator>=(const BTimeUs& time) const { return (otime >= time.otime); }
51  int operator<(const BTimeUs& time) const { return (otime < time.otime); }
52  int operator<=(const BTimeUs& time) const { return (otime <= time.otime); }
53  BTimeUs operator+(BInt64 microSeconds) const { return BTimeUs(otime + microSeconds); }
54  BTimeUs& operator+=(BInt64 microSeconds){ addMicroSeconds(microSeconds); return *this; }
55 
56 private:
57  BUInt64 otime;
58 };
59 
60 #endif
BTimeUs & operator+=(BInt64 microSeconds)
Definition: BTimeUs.h:54
int64_t BInt64
Definition: BTypes.h:22
int operator>=(const BTimeUs &time) const
Definition: BTimeUs.h:50
Definition: BTimeUs.h:22
Definition: BString.h:18
BString getString(BString format="isoT") const
Gets the date/time in string format.
Definition: BTimeUs.cpp:121
void setYearDay(BUInt year, BUInt yearDay, BUInt hour=0, BUInt minute=0, BUInt second=0, BUInt microSecond=0)
Set the date and time from UTC.
Definition: BTimeUs.cpp:57
int operator>(const BTimeUs &time) const
Definition: BTimeUs.h:49
uint64_t BUInt64
Definition: BTypes.h:23
BTimeUs operator+(BInt64 microSeconds) const
Definition: BTimeUs.h:53
int operator<=(const BTimeUs &time) const
Definition: BTimeUs.h:52
void addSeconds(BInt64 seconds)
Add the given number of seconds.
Definition: BTimeUs.cpp:106
BUInt32 format
Definition: BFirmware.h:33
void getTime(BUInt &hour, BUInt &minute, BUInt &second) const
Return the time information UTC.
Definition: BTimeUs.cpp:86
BTimeUs(BUInt64 t=0)
Definition: BTimeUs.cpp:33
BUInt32 BUInt
Definition: BTypes.h:30
int isLeapYear()
Returns if a leap year.
Definition: BTimeUs.cpp:114
BUInt64 getMicroSeconds() const
Return the number of micro seconds TAI.
Definition: BTimeUs.cpp:102
int operator!=(const BTimeUs &time) const
Definition: BTimeUs.h:48
void addMicroSeconds(BInt64 microSeconds)
Add the given number of seconds.
Definition: BTimeUs.cpp:110
BString getStringUs(BString format="isoT") const
Gets the date/time in string format.
Definition: BTimeUs.cpp:139
void getDate(BUInt &year, BUInt &month, BUInt &day) const
Return the date information UTC.
Definition: BTimeUs.cpp:68
int isSet() const
Check if set.
Definition: BTimeUs.h:36
int operator==(const BTimeUs &time) const
Definition: BTimeUs.h:47
int operator<(const BTimeUs &time) const
Definition: BTimeUs.h:51
Definition: BError.h:25
BError setString(const BString dateTime)
Sets the date/time from string format.
Definition: BTimeUs.cpp:157
BUInt64 getSeconds() const
Return the number of seconds TAI.
Definition: BTimeUs.cpp:98
Definition: BTime.h:20
void set(BUInt64 microSeconds)
Set the time to TAI us.
Definition: BTimeUs.cpp:41