hlcc 2.0.0-beta2+pre1
Loading...
Searching...
No Matches
greg_date.hpp
Go to the documentation of this file.
1#ifndef GREG_DATE_HPP___
2#define GREG_DATE_HPP___
3
4/* Copyright (c) 2002,2003, 2020 CrystalClear Software, Inc.
5 * Use, modification and distribution is subject to the
6 * Boost Software License, Version 1.0. (See accompanying
7 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 * Author: Jeff Garland
9 * $Date$
10 */
11
12/*
13 * GCH
14 * Eclipse CDT indexer/parser has problems with this include.
15 * We cheat it by having this patched version found
16 * in the include path of the indexer before the real one
17 */
18#ifndef __CDT_PARSER__
19
20#include <boost/throw_exception.hpp>
21#include <boost/date_time/compiler_config.hpp>
22#include <boost/date_time/date.hpp>
23#include <boost/date_time/special_defs.hpp>
24#include <boost/date_time/gregorian/greg_calendar.hpp>
25#include <boost/date_time/gregorian/greg_duration.hpp>
26
27namespace boost {
28namespace gregorian {
29
30 //bring special enum values into the namespace
31 using date_time::special_values;
32 using date_time::not_special;
33 using date_time::neg_infin;
34 using date_time::pos_infin;
35 using date_time::not_a_date_time;
36 using date_time::max_date_time;
37 using date_time::min_date_time;
38
40
46 class BOOST_SYMBOL_VISIBLE date : public date_time::date<date, gregorian_calendar, date_duration>
47 {
48 public:
49 typedef gregorian_calendar::year_type year_type;
50 typedef gregorian_calendar::month_type month_type;
51 typedef gregorian_calendar::day_type day_type;
52 typedef gregorian_calendar::day_of_year_type day_of_year_type;
53 typedef gregorian_calendar::ymd_type ymd_type;
54 typedef gregorian_calendar::date_rep_type date_rep_type;
55 typedef gregorian_calendar::date_int_type date_int_type;
56 typedef date_duration duration_type;
57#if !defined(DATE_TIME_NO_DEFAULT_CONSTRUCTOR)
59 BOOST_CXX14_CONSTEXPR date():
60 date_time::date<date, gregorian_calendar, date_duration>(date_rep_type::from_special(not_a_date_time))
61 {}
62#endif // DATE_TIME_NO_DEFAULT_CONSTRUCTOR
64 BOOST_CXX14_CONSTEXPR date(year_type y, month_type m, day_type d)
65 : date_time::date<date, gregorian_calendar, date_duration>(y, m, d)
66 {
67 if (gregorian_calendar::end_of_month_day(y, m) < d) {
68 boost::throw_exception(bad_day_of_month(std::string("Day of month is not valid for year")));
69 }
70 }
72 BOOST_CXX14_CONSTEXPR explicit date(const ymd_type& ymd)
73 : date_time::date<date, gregorian_calendar, date_duration>(ymd)
74 {}
76 BOOST_CXX14_CONSTEXPR explicit date(const date_int_type& rhs):
77 date_time::date<date,gregorian_calendar, date_duration>(rhs)
78 {}
80 BOOST_CXX14_CONSTEXPR explicit date(date_rep_type rhs):
81 date_time::date<date,gregorian_calendar, date_duration>(rhs)
82 {}
84 BOOST_CXX14_CONSTEXPR explicit date(special_values sv):
85 date_time::date<date, gregorian_calendar, date_duration>(date_rep_type::from_special(sv))
86 {
87 if (sv == min_date_time)
88 {
89 *this = date(1400, 1, 1);
90 }
91 if (sv == max_date_time)
92 {
93 *this = date(9999, 12, 31);
94 }
95
96 }
98 BOOST_CXX14_CONSTEXPR date_int_type julian_day() const
99 {
100 ymd_type ymd = year_month_day();
101 return gregorian_calendar::julian_day_number(ymd);
102 }
104 BOOST_CXX14_CONSTEXPR day_of_year_type day_of_year() const
105 {
106 date start_of_year(year(), 1, 1);
107 unsigned short doy = static_cast<unsigned short>((*this-start_of_year).days() + 1);
108 return day_of_year_type(doy);
109 }
111 BOOST_CXX14_CONSTEXPR date_int_type modjulian_day() const
112 {
113 ymd_type ymd = year_month_day();
114 return gregorian_calendar::modjulian_day_number(ymd);
115 }
117 BOOST_CXX14_CONSTEXPR int week_number() const
118 {
119 ymd_type ymd = year_month_day();
120 return gregorian_calendar::week_number(ymd);
121 }
123 BOOST_CXX14_CONSTEXPR date_int_type day_number() const
124 {
125 return days_;
126 }
128 BOOST_CXX14_CONSTEXPR date end_of_month() const
129 {
130 ymd_type ymd = year_month_day();
131 unsigned short eom_day = gregorian_calendar::end_of_month_day(ymd.year, ymd.month);
132 return date(ymd.year, ymd.month, eom_day);
133 }
134
135 friend BOOST_CXX14_CONSTEXPR
136 bool operator==(const date& lhs, const date& rhs);
137
138 private:
139
140 };
141
142 inline BOOST_CXX14_CONSTEXPR
143 bool operator==(const date& lhs, const date& rhs)
144 {
145 return lhs.days_ == rhs.days_;
146 }
147
148
149} } //namespace gregorian
150
151#endif // ifndef __CDT_PARSER__
152
153#endif
A date type based on gregorian_calendar.
Definition: greg_date.hpp:47
BOOST_CXX14_CONSTEXPR date end_of_month() const
Return the last day of the current month.
Definition: greg_date.hpp:128
gregorian_calendar::year_type year_type
Definition: greg_date.hpp:49
gregorian_calendar::day_of_year_type day_of_year_type
Definition: greg_date.hpp:52
BOOST_CXX14_CONSTEXPR date_int_type day_number() const
Return the day number from the calendar.
Definition: greg_date.hpp:123
BOOST_CXX14_CONSTEXPR int week_number() const
Return the iso 8601 week number 1..53.
Definition: greg_date.hpp:117
gregorian_calendar::date_int_type date_int_type
Definition: greg_date.hpp:55
BOOST_CXX14_CONSTEXPR date(special_values sv)
Constructor for infinities, not a date, max and min date.
Definition: greg_date.hpp:84
BOOST_CXX14_CONSTEXPR date()
Default constructor constructs with not_a_date_time.
Definition: greg_date.hpp:59
date_duration duration_type
Definition: greg_date.hpp:56
BOOST_CXX14_CONSTEXPR date_int_type modjulian_day() const
Return the Modified Julian Day number for the date.
Definition: greg_date.hpp:111
BOOST_CXX14_CONSTEXPR date(const ymd_type &ymd)
Constructor from a ymd_type structure.
Definition: greg_date.hpp:72
gregorian_calendar::ymd_type ymd_type
Definition: greg_date.hpp:53
gregorian_calendar::day_type day_type
Definition: greg_date.hpp:51
BOOST_CXX14_CONSTEXPR date_int_type julian_day() const
Return the Julian Day number for the date.
Definition: greg_date.hpp:98
gregorian_calendar::date_rep_type date_rep_type
Definition: greg_date.hpp:54
BOOST_CXX14_CONSTEXPR date(const date_int_type &rhs)
Needed copy constructor.
Definition: greg_date.hpp:76
gregorian_calendar::month_type month_type
Definition: greg_date.hpp:50
BOOST_CXX14_CONSTEXPR date(date_rep_type rhs)
Needed copy constructor.
Definition: greg_date.hpp:80
BOOST_CXX14_CONSTEXPR day_of_year_type day_of_year() const
Return the day of year 1..365 or 1..366 (for leap year)
Definition: greg_date.hpp:104
BOOST_CXX14_CONSTEXPR bool operator==(const date &lhs, const date &rhs)
Definition: greg_date.hpp:143
Definition: greg_date.hpp:27