Beamlib 3.1.1
This is the Beam C++ class library.
Loading...
Searching...
No Matches
BDate.h
Go to the documentation of this file.
1/*******************************************************************************
2 * BDate.h Date class
3 * T.Barnaby, BEAM Ltd, 2009-08-14
4 * Copyright (c) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5 *******************************************************************************
6 *
7 * For license see LICENSE.txt at the root of the beamlib source tree.
8 */
9#ifndef BDate_H
10#define BDate_H 1
11
12#include <stdint.h>
13#include <BError.h>
14
16class BDate {
17public:
18 BDate(int year = 0, int month = 1, int day = 1);
19 BDate(BString str);
20 ~BDate();
21
22 void clear();
23 void setFirst();
24 void setLast();
25
26 void set(time_t time);
27 void set(int year = 0, int month = 1, int day = 1);
28 void setYDay(int year = 0, int yday = 0);
29 void setNow();
30
31 int year();
32 int yday();
33 int month();
34 int day();
35
36 void getDate(int& year, int& mon, int& day);
37
41
42 int isSet(){ return oyear != 0; }
43 int compare(const BDate& date) const;
44
45 operator BString(){ return getString(); }
46
47 int operator==(const BDate& date) const { return (compare(date) == 0); }
48 int operator!=(const BDate& date) const { return (compare(date) != 0); }
49 int operator>(const BDate& date) const { return (compare(date) > 0); }
50 int operator>=(const BDate& date) const { return (compare(date) >= 0); }
51 int operator<(const BDate& date) const { return (compare(date) < 0); }
52 int operator<=(const BDate& date) const { return (compare(date) <= 0); }
53
54 static int isLeap(int year);
55 static int daysInMonth(int year, int month);
56
57public:
58 uint16_t oyear;
59 uint16_t oyday;
60};
61
62// String conversion functions
63void toBString(BDate& v, BString& s);
64void fromBString(BString& s, BDate& v);
65
66#endif
void fromBString(BString &s, BDate &v)
Definition: BDate.cpp:224
void toBString(BDate &v, BString &s)
Definition: BDate.cpp:220
BUInt32 format
Definition: BFirmware.h:5
This class store a UTC calendar date as a year and a year's day.
Definition: BDate.h:16
int operator>(const BDate &date) const
Definition: BDate.h:49
int compare(const BDate &date) const
Compare two dates.
Definition: BDate.cpp:194
int operator<(const BDate &date) const
Definition: BDate.h:51
void setNow()
Set the timeStamp to now.
Definition: BDate.cpp:70
int year()
Definition: BDate.cpp:81
int isSet()
Check if the date has been set.
Definition: BDate.h:42
BString getString()
Get the time as an ISO date/time string.
Definition: BDate.cpp:106
static int daysInMonth(int year, int month)
Definition: BDate.cpp:213
int yday()
Definition: BDate.cpp:102
BString getStringFormatted(BString format)
Gets the time in a string form as per the format. Format syntax as per strftime()
Definition: BDate.cpp:119
~BDate()
Definition: BDate.cpp:35
int operator!=(const BDate &date) const
Definition: BDate.h:48
void getDate(int &year, int &mon, int &day)
Definition: BDate.cpp:188
void clear()
Clear the date/time.
Definition: BDate.cpp:38
uint16_t oyear
Year (0 .. 65535)
Definition: BDate.h:58
int operator<=(const BDate &date) const
Definition: BDate.h:52
int month()
Definition: BDate.cpp:85
void setYDay(int year=0, int yday=0)
Definition: BDate.cpp:51
BError setString(BString str)
Set the time from an ISO date/time.
Definition: BDate.cpp:142
int operator==(const BDate &date) const
Definition: BDate.h:47
void setLast()
Set the last date available.
Definition: BDate.cpp:47
void set(time_t time)
Set time using Unix time (seconds from 1970-01-01)
Definition: BDate.cpp:56
uint16_t oyday
Day in year (0 .. 365)
Definition: BDate.h:59
static int isLeap(int year)
Definition: BDate.cpp:209
void setFirst()
Set the first date available.
Definition: BDate.cpp:43
int day()
Definition: BDate.cpp:92
int operator>=(const BDate &date) const
Definition: BDate.h:50
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