Beam-lib  2.16.3
This is the Beam C++ class library.
BTime.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BTime.h BTime functions
3  * T.Barnaby, Beam Ltd, 2012-11-12
4  * Copyright (c) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  *
7  * Implements a simple date/time class. Stores the date/time as a number of seconds
8  * since 1970-01-02T00:00:00. Has a range until 2106-02-07.
9  *
10  * Uses some sepcial values.
11  * 0 - DateTime not set.
12  */
13 #ifndef BTime_h
14 #define BTime_h
15 
16 #include <BTypes.h>
17 #include <BError.h>
18 #include <BString.h>
19 
20 class BTime {
21 public:
22  BTime(BUInt32 t = 0);
23 
24  void set(BUInt32 seconds);
25  void set(BUInt year, BUInt month, BUInt day, BUInt hour = 0, BUInt minute = 0, BUInt second = 0);
26  void setYearDay(BUInt year, BUInt yearDay, BUInt hour = 0, BUInt minute = 0, BUInt second = 0);
27 
28  void getDate(BUInt& year, BUInt& month, BUInt& day) const;
29  void getTime(BUInt& hour, BUInt& minute, BUInt& second) const;
30  BUInt32 getSeconds() const;
31 
32  int isSet() const{ return otime != 0; }
33  int isLeapYear();
34  void addSeconds(int seconds);
35 
36  BString getString(BString format = "isoT") const;
37  BError setString(const BString dateTime);
38 
39  // Operator functions
40  int operator==(const BTime& time) const { return (otime == time.otime); }
41  int operator!=(const BTime& time) const { return (otime != time.otime); }
42  int operator>(const BTime& time) const { return (otime > time.otime); }
43  int operator>=(const BTime& time) const { return (otime >= time.otime); }
44  int operator<(const BTime& time) const { return (otime < time.otime); }
45  int operator<=(const BTime& time) const { return (otime <= time.otime); }
46  BTime operator+(int seconds) const { return BTime(getSeconds() + seconds); }
47  BTime& operator+=(int seconds){ addSeconds(seconds); return *this; }
48 
49 private:
50  BUInt32 otime;
51 };
52 
53 #endif
BTime operator+(int seconds) const
Definition: BTime.h:46
Definition: BString.h:18
void set(BUInt32 seconds)
Set the date and time.
Definition: BTime.cpp:27
void addSeconds(int seconds)
Add the given number of seconds.
Definition: BTime.cpp:88
int isLeapYear()
Returns if a leap year.
Definition: BTime.cpp:92
void setYearDay(BUInt year, BUInt yearDay, BUInt hour=0, BUInt minute=0, BUInt second=0)
Set the date and time.
Definition: BTime.cpp:43
BUInt32 format
Definition: BFirmware.h:33
void getDate(BUInt &year, BUInt &month, BUInt &day) const
Retun the date information.
Definition: BTime.cpp:54
int isSet() const
Check if set.
Definition: BTime.h:32
BUInt32 BUInt
Definition: BTypes.h:30
uint32_t BUInt32
Definition: BTypes.h:21
BError setString(const BString dateTime)
Sets the date/time from string format.
Definition: BTime.cpp:125
int operator>(const BTime &time) const
Definition: BTime.h:42
BTime & operator+=(int seconds)
Definition: BTime.h:47
int operator!=(const BTime &time) const
Definition: BTime.h:41
BTime(BUInt32 t=0)
Definition: BTime.cpp:23
Definition: BError.h:25
BString getString(BString format="isoT") const
Gets the date/time in string format.
Definition: BTime.cpp:99
BUInt32 getSeconds() const
Return the number of seconds.
Definition: BTime.cpp:84
void getTime(BUInt &hour, BUInt &minute, BUInt &second) const
Return the time information.
Definition: BTime.cpp:72
int operator<=(const BTime &time) const
Definition: BTime.h:45
int operator==(const BTime &time) const
Definition: BTime.h:40
Definition: BTime.h:20
int operator<(const BTime &time) const
Definition: BTime.h:44
int operator>=(const BTime &time) const
Definition: BTime.h:43