Build: enhance docker use, reducing build options, cleanup
[marnav.git] / src / marnav / nmea / date.hpp
blobbfe426109db9bdeb1a50236d16f1b679e9cf11b3
1 #ifndef MARNAV__NMEA__DATE__HPP
2 #define MARNAV__NMEA__DATE__HPP
4 #include <string>
6 namespace marnav
8 namespace nmea
11 /// Enumeration of all months of a year.
12 enum class month : uint32_t {
13 january = 1,
14 february,
15 march,
16 april,
17 may,
18 june,
19 july,
20 august,
21 september,
22 october,
23 november,
24 december
27 /// This class represents a date, suitable to be used in NMEA sentences.
28 ///
29 class date
31 public:
32 date();
33 date(uint32_t y, month m, uint32_t d);
35 /// Returns the year component.
36 uint32_t year() const noexcept;
38 /// Returns the month component.
39 month mon() const noexcept;
41 /// Returns the day component.
42 uint32_t day() const noexcept;
44 friend bool operator==(const date & a, const date & b) noexcept;
46 /// Parses the date within the specified string.
47 /// The date to be parsed must be in the form: "DDMMYY"
48 static date parse(const std::string & str);
50 /// Returns true if the specified year is a leap year. This function
51 /// does not work for dates before 17?? (only for julian calendar).
52 ///
53 /// Every fourth year is a leap year except for every 100 years,
54 /// except every 400 years.
55 static constexpr bool is_leap_year(uint32_t year) noexcept
57 return ((year % 4) == 0) && (((year % 100) != 0) || ((year % 400) == 0));
60 private:
61 bool check() const noexcept;
63 uint32_t y_; // year
64 month m_;
65 uint32_t d_; // day: 1..31
68 bool operator==(const date & a, const date & b) noexcept;
69 std::string to_string(const date & d);
73 #endif