advance compilation to include plugin_ui.cc
[ardour.git] / libs / glibmm2 / glibmm / date.cc
1 // Generated by gtkmmproc -- DO NOT MODIFY!
2
3 #include <glibmm/date.h>
4 #include <glibmm/private/date_p.h>
5
6 // -*- c++ -*-
7 /* $Id$ */
8
9 /* Copyright (C) 2002 The gtkmm Development Team
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public
22  * License along with this library; if not, write to the Free
23  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #include <glib/gmem.h>
27 #include <glib/gmessages.h>
28
29 #include <ctime>
30 #include <algorithm>
31 #include <glibmm/convert.h>
32 #include <glibmm/utility.h>
33
34 #include <glibmmconfig.h>
35 GLIBMM_USING_STD(max)
36
37
38 namespace Glib
39 {
40
41 Date::Date()
42 {
43   g_date_clear(&gobject_, 1);
44 }
45
46 Date::Date(Date::Day day, Date::Month month, Date::Year year)
47 {
48   g_date_clear(&gobject_, 1);
49   g_date_set_dmy(&gobject_, day, (GDateMonth) month, year);
50 }
51
52 Date::Date(guint32 julian_day)
53 {
54   g_date_clear(&gobject_, 1);
55   g_date_set_julian(&gobject_, julian_day);
56 }
57
58 Date::Date(const GDate& castitem)
59 :
60   gobject_ (castitem)
61 {}
62
63 void Date::clear()
64 {
65   g_date_clear(&gobject_, 1);
66 }
67
68 void Date::set_parse(const Glib::ustring& str)
69 {
70   g_date_set_parse(&gobject_, str.c_str());
71 }
72
73 void Date::set_time(GTime time)
74 {
75   g_date_set_time(&gobject_, time);
76 }
77
78 void Date::set_month(Date::Month month)
79 {
80   g_date_set_month(&gobject_, (GDateMonth) month);
81 }
82
83 void Date::set_day(Date::Day day)
84 {
85   g_date_set_day(&gobject_, day);
86 }
87
88 void Date::set_year(Date::Year year)
89 {
90   g_date_set_year(&gobject_, year);
91 }
92
93 void Date::set_dmy(Date::Day day, Date::Month month, Date::Year year)
94 {
95   g_date_set_dmy(&gobject_, day, (GDateMonth) month, year);
96 }
97
98 void Date::set_julian(guint32 julian_day)
99 {
100   g_date_set_julian(&gobject_, julian_day);
101 }
102
103 Date& Date::add_days(int n_days)
104 {
105   if(n_days >= 0)
106     g_date_add_days(&gobject_, n_days);
107   else
108     g_date_subtract_days(&gobject_, -n_days);
109   return *this;
110 }
111
112 Date& Date::subtract_days(int n_days)
113 {
114   if(n_days >= 0)
115     g_date_subtract_days(&gobject_, n_days);
116   else
117     g_date_add_days(&gobject_, -n_days);
118   return *this;
119 }
120
121 Date& Date::add_months(int n_months)
122 {
123   if(n_months >= 0)
124     g_date_add_months(&gobject_, n_months);
125   else
126     g_date_subtract_months(&gobject_, -n_months);
127   return *this;
128 }
129
130 Date& Date::subtract_months(int n_months)
131 {
132   if(n_months >= 0)
133     g_date_subtract_months(&gobject_, n_months);
134   else
135     g_date_add_months(&gobject_, -n_months);
136   return *this;
137 }
138
139 Date& Date::add_years(int n_years)
140 {
141   if(n_years >= 0)
142     g_date_add_years(&gobject_, n_years);
143   else
144     g_date_subtract_years(&gobject_, -n_years);
145   return *this;
146 }
147
148 Date& Date::subtract_years(int n_years)
149 {
150   if(n_years >= 0)
151     g_date_subtract_years(&gobject_, n_years);
152   else
153     g_date_add_years(&gobject_, -n_years);
154   return *this;
155 }
156
157 int Date::days_between(const Date& rhs) const
158 {
159   return g_date_days_between(&gobject_, &rhs.gobject_);
160 }
161
162 int Date::compare(const Date& rhs) const
163 {
164   return g_date_compare(&gobject_, &rhs.gobject_);
165 }
166
167 Date& Date::clamp(const Date& min_date, const Date& max_date)
168 {
169   g_date_clamp(&gobject_, &min_date.gobject_, &max_date.gobject_);
170   return *this;
171 }
172
173 Date& Date::clamp_min(const Date& min_date)
174 {
175   g_date_clamp(&gobject_, &min_date.gobject_, 0 /* see the C docs */);
176   return *this;
177 }
178
179 Date& Date::clamp_max(const Date& max_date)
180 {
181   g_date_clamp(&gobject_, 0 /* see the C docs */, &max_date.gobject_);
182   return *this;
183 }
184
185 void Date::order(Date& other)
186 {
187   g_date_order(&gobject_, &other.gobject_);
188 }
189
190 Date::Weekday Date::get_weekday() const
191 {
192   return (Date::Weekday) g_date_get_weekday(&gobject_);
193 }
194
195 Date::Month Date::get_month() const
196 {
197   return (Date::Month) g_date_get_month(&gobject_);
198 }
199
200 Date::Year Date::get_year() const
201 {
202   return g_date_get_year(&gobject_);
203 }
204
205 Date::Day Date::get_day() const
206 {
207   return g_date_get_day(&gobject_);
208 }
209
210 guint32 Date::get_julian() const
211 {
212   return g_date_get_julian(&gobject_);
213 }
214
215 unsigned int Date::get_day_of_year() const
216 {
217   return g_date_get_day_of_year(&gobject_);
218 }
219
220 unsigned int Date::get_monday_week_of_year() const
221 {
222   return g_date_get_monday_week_of_year(&gobject_);
223 }
224
225 unsigned int Date::get_sunday_week_of_year() const
226 {
227   return g_date_get_sunday_week_of_year(&gobject_);
228 }
229
230 bool Date::is_first_of_month() const
231 {
232   return g_date_is_first_of_month(&gobject_);
233 }
234
235 bool Date::is_last_of_month() const
236 {
237   return g_date_is_last_of_month(&gobject_);
238 }
239
240 //static
241 guint8 Date::get_days_in_month(Date::Month month, Date::Year year)
242 {
243   return g_date_get_days_in_month((GDateMonth) month, year);
244 }
245
246 //static
247 guint8 Date::get_monday_weeks_in_year(Date::Year year)
248 {
249   return g_date_get_monday_weeks_in_year(year);
250 }
251
252 //static
253 guint8 Date::get_sunday_weeks_in_year(Date::Year year)
254 {
255   return g_date_get_sunday_weeks_in_year(year);
256 }
257
258 //static
259 bool Date::is_leap_year(Date::Year year)
260 {
261   return g_date_is_leap_year(year);
262 }
263
264 Glib::ustring Date::format_string(const Glib::ustring& format) const
265 {
266   struct tm tm_data;
267   g_date_to_struct_tm(&gobject_, &tm_data);
268
269   const std::string locale_format = locale_from_utf8(format);
270   gsize bufsize = std::max<gsize>(2 * locale_format.size(), 128);
271
272   do
273   {
274     const ScopedPtr<char> buf (static_cast<char*>(g_malloc(bufsize)));
275
276     // Set the first byte to something other than '\0', to be able to
277     // recognize whether strftime actually failed or just returned "".
278     buf.get()[0] = '\1';
279     const gsize len = strftime(buf.get(), bufsize, locale_format.c_str(), &tm_data);
280
281     if(len != 0 || buf.get()[0] == '\0')
282     {
283       g_assert(len < bufsize);
284       return locale_to_utf8(std::string(buf.get(), len));
285     }
286   }
287   while((bufsize *= 2) <= 65536);
288
289   // This error is quite unlikely (unless strftime is buggy).
290   g_warning("Glib::Date::format_string(): maximum size of strftime buffer exceeded, giving up");
291
292   return Glib::ustring();
293 }
294
295 void Date::to_struct_tm(struct tm& dest) const
296 {
297   g_date_to_struct_tm(&gobject_, &dest);
298 }
299
300 bool Date::valid() const
301 {
302   return g_date_valid(&gobject_);
303 }
304
305 //static
306 bool Date::valid_day(Date::Day day)
307 {
308   return g_date_valid_day(day);
309 }
310
311 //static
312 bool Date::valid_month(Date::Month month)
313 {
314   return g_date_valid_month((GDateMonth) month);
315 }
316
317 //static
318 bool Date::valid_year(Date::Year year)
319 {
320   return g_date_valid_year(year);
321 }
322
323 //static
324 bool Date::valid_weekday(Date::Weekday weekday)
325 {
326   return g_date_valid_weekday((GDateWeekday) weekday);
327 }
328
329 //static
330 bool Date::valid_julian(guint32 julian_day)
331 {
332   return g_date_valid_julian(julian_day);
333 }
334
335 //static
336 bool Date::valid_dmy(Date::Day day, Date::Month month, Date::Year year)
337 {
338   return g_date_valid_dmy(day, (GDateMonth) month, year);
339 }
340
341 } // namespace Glib
342
343
344 namespace
345 {
346 } // anonymous namespace
347
348