Beamlib 3.3.2
This is the Beam C++ class library.
Loading...
Searching...
No Matches
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) 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 */
20#ifndef BTime_h
21#define BTime_h
22
23#include <BTypes.h>
24#include <BError.h>
25#include <BString.h>
26
27class BTime {
28public:
29 BTime(BUInt32 t = 0);
30
31 void set(BUInt32 seconds);
32 void set(BUInt year, BUInt month, BUInt day, BUInt hour = 0, BUInt minute = 0, BUInt second = 0);
33 void setYearDay(BUInt year, BUInt yearDay, BUInt hour = 0, BUInt minute = 0, BUInt second = 0);
34
35 void getDate(BUInt& year, BUInt& month, BUInt& day) const;
36 void getTime(BUInt& hour, BUInt& minute, BUInt& second) const;
37 BUInt32 getSeconds() const;
38
39 int isSet() const{ return otime != 0; }
40 int isLeapYear();
41 void addSeconds(int seconds);
42
43 BString getString(BString format = "iso") const;
44 BError setString(const BString dateTime);
45
46 BTime utcToLocal() const;
47 BTime localToUtc() const;
48 BString getStringLocal(BString format = "iso") const;
49 BError setStringLocal(const BString dateTime);
50
51 // Operator functions
52 int operator==(const BTime& time) const { return (otime == time.otime); }
53 int operator!=(const BTime& time) const { return (otime != time.otime); }
54 int operator>(const BTime& time) const { return (otime > time.otime); }
55 int operator>=(const BTime& time) const { return (otime >= time.otime); }
56 int operator<(const BTime& time) const { return (otime < time.otime); }
57 int operator<=(const BTime& time) const { return (otime <= time.otime); }
58 BTime operator+(int seconds) const { return BTime(getSeconds() + seconds); }
59 BTime& operator+=(int seconds){ addSeconds(seconds); return *this; }
60
61private:
62 BUInt32 otime;
63};
64
65#endif
double getTime()
Definition: BDebug.cpp:103
BUInt32 format
Definition: BFirmware.h:5
BUInt32 BUInt
Definition: BTypes.h:33
uint32_t BUInt32
Definition: BTypes.h:24
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
Implements a simple date/time class. Stores the date/time as a number of seconds since Unix epoch 197...
Definition: BTime.h:27
BTime localToUtc() const
Converts a local time to UTC time.
Definition: BTime.cpp:205
BTime operator+(int seconds) const
Definition: BTime.h:58
BTime utcToLocal() const
Converts a UTC time to a local time.
Definition: BTime.cpp:197
BError setStringLocal(const BString dateTime)
Sets the date/time from string format.
Definition: BTime.cpp:218
BString getString(BString format="iso") const
Gets the date/time in string format.
Definition: BTime.cpp:104
int isLeapYear()
Returns if a leap year.
Definition: BTime.cpp:97
BError setString(const BString dateTime)
Sets the date/time from string format.
Definition: BTime.cpp:139
void getDate(BUInt &year, BUInt &month, BUInt &day) const
Retun the date information.
Definition: BTime.cpp:59
int operator>=(const BTime &time) const
Definition: BTime.h:55
void addSeconds(int seconds)
Add the given number of seconds.
Definition: BTime.cpp:93
void set(BUInt32 seconds)
Set the date and time.
Definition: BTime.cpp:32
BString getStringLocal(BString format="iso") const
Gets the date/time in string format.
Definition: BTime.cpp:214
BTime & operator+=(int seconds)
Definition: BTime.h:59
int operator<(const BTime &time) const
Definition: BTime.h:56
void setYearDay(BUInt year, BUInt yearDay, BUInt hour=0, BUInt minute=0, BUInt second=0)
Set the date and time.
Definition: BTime.cpp:48
int isSet() const
Check if set.
Definition: BTime.h:39
int operator<=(const BTime &time) const
Definition: BTime.h:57
int operator!=(const BTime &time) const
Definition: BTime.h:53
BUInt32 getSeconds() const
Return the number of seconds.
Definition: BTime.cpp:89
int operator==(const BTime &time) const
Definition: BTime.h:52
int operator>(const BTime &time) const
Definition: BTime.h:54