1 #ifndef MARNAV__NMEA__DATE__HPP
2 #define MARNAV__NMEA__DATE__HPP
11 /// Enumeration of all months of a year.
12 enum class month
: uint32_t {
27 /// This class represents a date, suitable to be used in NMEA sentences.
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).
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));
61 bool check() const noexcept
;
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
);