Beamlib 3.1.2
This is the Beam C++ class library.
Loading...
Searching...
No Matches
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) 2022 All Right Reserved, Beam Ltd, https://www.beam.ltd.uk
5 * For license see LICENSE.txt at the root of the beamlib source tree.
6 *******************************************************************************
7 *
8 * Implements a microsecond accurate time class. Stores the time as a number of microseconds
9 * to the TAI standard with no leap seconds. 0 time is 1970-01-02T00:00:00.
10 * The class provides conversions between UTC time and TAI microsecond time (leap second handling)
11 *
12 * Uses some sepcial values.
13 * 0 - DateTime not set.
14 */
15#ifndef BTimeUs_h
16#define BTimeUs_h
17
18#include <BTypes.h>
19#include <BError.h>
20#include <BString.h>
21#include <BTime.h>
22
24class BTimeUs {
25public:
26 BTimeUs(BUInt64 t = 0);
27 BTimeUs(BTime t);
28
29 void set(BUInt64 microSeconds);
30 void set(BUInt year, BUInt month, BUInt day, BUInt hour = 0, BUInt minute = 0, BUInt second = 0, BUInt microSecond = 0);
31 void setYearDay(BUInt year, BUInt yearDay, BUInt hour = 0, BUInt minute = 0, BUInt second = 0, BUInt microSecond = 0);
32
33 void getDate(BUInt& year, BUInt& month, BUInt& day) const;
34 void getTime(BUInt& hour, BUInt& minute, BUInt& second) const;
35 BUInt64 getSeconds() const;
36 BUInt64 getMicroSeconds() const;
37
38 int isSet() const{ return otime != 0; }
39 int isLeapYear();
40 void addSeconds(BInt64 seconds);
41 void addMicroSeconds(BInt64 microSeconds);
42
43 BString getString(BString format = "isoT") const;
44 BString getStringUs(BString format = "isoT") const;
45 BError setString(const BString dateTime);
46
47 // Operator functions
48 operator BTime() const { return BTime(getSeconds()); }
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 int operator<(const BTimeUs& time) const { return (otime < time.otime); }
54 int operator<=(const BTimeUs& time) const { return (otime <= time.otime); }
55 BTimeUs operator+(BInt64 microSeconds) const { return BTimeUs(otime + microSeconds); }
56 BTimeUs& operator+=(BInt64 microSeconds){ addMicroSeconds(microSeconds); return *this; }
57
58private:
59 BUInt64 otime;
60};
61
62#endif
double getTime()
Definition: BDebug.cpp:103
BUInt32 format
Definition: BFirmware.h:5
BUInt32 BUInt
Definition: BTypes.h:33
int64_t BInt64
Definition: BTypes.h:25
uint64_t BUInt64
Definition: BTypes.h:26
Error return class. This class is used to return the error status from a function....
Definition: BError.h:31
This class stores and manipulates ASCII strings.
Definition: BString.h:20
Time storage as an unsigned 64bit value to TAI standard.
Definition: BTimeUs.h:24
int isLeapYear()
Returns if a leap year.
Definition: BTimeUs.cpp:115
int operator<(const BTimeUs &time) const
Definition: BTimeUs.h:53
int operator!=(const BTimeUs &time) const
Definition: BTimeUs.h:50
int operator<=(const BTimeUs &time) const
Definition: BTimeUs.h:54
BError setString(const BString dateTime)
Sets the date/time from string format.
Definition: BTimeUs.cpp:158
BString getStringUs(BString format="isoT") const
Gets the date/time in string format.
Definition: BTimeUs.cpp:140
int operator>=(const BTimeUs &time) const
Definition: BTimeUs.h:52
void addMicroSeconds(BInt64 microSeconds)
Add the given number of seconds.
Definition: BTimeUs.cpp:111
BTimeUs & operator+=(BInt64 microSeconds)
Definition: BTimeUs.h:56
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:58
BTimeUs operator+(BInt64 microSeconds) const
Definition: BTimeUs.h:55
BString getString(BString format="isoT") const
Gets the date/time in string format.
Definition: BTimeUs.cpp:122
void getDate(BUInt &year, BUInt &month, BUInt &day) const
Return the date information UTC.
Definition: BTimeUs.cpp:69
void set(BUInt64 microSeconds)
Set the time to TAI us.
Definition: BTimeUs.cpp:42
int operator>(const BTimeUs &time) const
Definition: BTimeUs.h:51
BUInt64 getMicroSeconds() const
Return the number of micro seconds TAI.
Definition: BTimeUs.cpp:103
int isSet() const
Check if set.
Definition: BTimeUs.h:38
BUInt64 getSeconds() const
Return the number of seconds TAI.
Definition: BTimeUs.cpp:99
void addSeconds(BInt64 seconds)
Add the given number of seconds.
Definition: BTimeUs.cpp:107
int operator==(const BTimeUs &time) const
Definition: BTimeUs.h:49
Implements a simple date/time class. Stores the date/time as a number of seconds since Unix epoch 197...
Definition: BTime.h:27