1 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #include <glibmm/date.h>
4 #include <glibmm/private/date_p.h>
9 /* Copyright (C) 2002 The gtkmm Development Team
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.
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.
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.
26 #include <glib/gmem.h>
27 #include <glib/gmessages.h>
31 #include <glibmm/convert.h>
32 #include <glibmm/utility.h>
34 #include <glibmmconfig.h>
43 g_date_clear(&gobject_, 1);
46 Date::Date(Date::Day day, Date::Month month, Date::Year year)
48 g_date_clear(&gobject_, 1);
49 g_date_set_dmy(&gobject_, day, (GDateMonth) month, year);
52 Date::Date(guint32 julian_day)
54 g_date_clear(&gobject_, 1);
55 g_date_set_julian(&gobject_, julian_day);
58 Date::Date(const GDate& castitem)
65 g_date_clear(&gobject_, 1);
68 void Date::set_parse(const Glib::ustring& str)
70 g_date_set_parse(&gobject_, str.c_str());
73 void Date::set_time(GTime time)
75 g_date_set_time(&gobject_, time);
78 void Date::set_month(Date::Month month)
80 g_date_set_month(&gobject_, (GDateMonth) month);
83 void Date::set_day(Date::Day day)
85 g_date_set_day(&gobject_, day);
88 void Date::set_year(Date::Year year)
90 g_date_set_year(&gobject_, year);
93 void Date::set_dmy(Date::Day day, Date::Month month, Date::Year year)
95 g_date_set_dmy(&gobject_, day, (GDateMonth) month, year);
98 void Date::set_julian(guint32 julian_day)
100 g_date_set_julian(&gobject_, julian_day);
103 Date& Date::add_days(int n_days)
106 g_date_add_days(&gobject_, n_days);
108 g_date_subtract_days(&gobject_, -n_days);
112 Date& Date::subtract_days(int n_days)
115 g_date_subtract_days(&gobject_, n_days);
117 g_date_add_days(&gobject_, -n_days);
121 Date& Date::add_months(int n_months)
124 g_date_add_months(&gobject_, n_months);
126 g_date_subtract_months(&gobject_, -n_months);
130 Date& Date::subtract_months(int n_months)
133 g_date_subtract_months(&gobject_, n_months);
135 g_date_add_months(&gobject_, -n_months);
139 Date& Date::add_years(int n_years)
142 g_date_add_years(&gobject_, n_years);
144 g_date_subtract_years(&gobject_, -n_years);
148 Date& Date::subtract_years(int n_years)
151 g_date_subtract_years(&gobject_, n_years);
153 g_date_add_years(&gobject_, -n_years);
157 int Date::days_between(const Date& rhs) const
159 return g_date_days_between(&gobject_, &rhs.gobject_);
162 int Date::compare(const Date& rhs) const
164 return g_date_compare(&gobject_, &rhs.gobject_);
167 Date& Date::clamp(const Date& min_date, const Date& max_date)
169 g_date_clamp(&gobject_, &min_date.gobject_, &max_date.gobject_);
173 Date& Date::clamp_min(const Date& min_date)
175 g_date_clamp(&gobject_, &min_date.gobject_, 0 /* see the C docs */);
179 Date& Date::clamp_max(const Date& max_date)
181 g_date_clamp(&gobject_, 0 /* see the C docs */, &max_date.gobject_);
185 void Date::order(Date& other)
187 g_date_order(&gobject_, &other.gobject_);
190 Date::Weekday Date::get_weekday() const
192 return (Date::Weekday) g_date_get_weekday(&gobject_);
195 Date::Month Date::get_month() const
197 return (Date::Month) g_date_get_month(&gobject_);
200 Date::Year Date::get_year() const
202 return g_date_get_year(&gobject_);
205 Date::Day Date::get_day() const
207 return g_date_get_day(&gobject_);
210 guint32 Date::get_julian() const
212 return g_date_get_julian(&gobject_);
215 unsigned int Date::get_day_of_year() const
217 return g_date_get_day_of_year(&gobject_);
220 unsigned int Date::get_monday_week_of_year() const
222 return g_date_get_monday_week_of_year(&gobject_);
225 unsigned int Date::get_sunday_week_of_year() const
227 return g_date_get_sunday_week_of_year(&gobject_);
230 bool Date::is_first_of_month() const
232 return g_date_is_first_of_month(&gobject_);
235 bool Date::is_last_of_month() const
237 return g_date_is_last_of_month(&gobject_);
241 guint8 Date::get_days_in_month(Date::Month month, Date::Year year)
243 return g_date_get_days_in_month((GDateMonth) month, year);
247 guint8 Date::get_monday_weeks_in_year(Date::Year year)
249 return g_date_get_monday_weeks_in_year(year);
253 guint8 Date::get_sunday_weeks_in_year(Date::Year year)
255 return g_date_get_sunday_weeks_in_year(year);
259 bool Date::is_leap_year(Date::Year year)
261 return g_date_is_leap_year(year);
264 Glib::ustring Date::format_string(const Glib::ustring& format) const
267 g_date_to_struct_tm(&gobject_, &tm_data);
269 const std::string locale_format = locale_from_utf8(format);
270 gsize bufsize = std::max<gsize>(2 * locale_format.size(), 128);
274 const ScopedPtr<char> buf (static_cast<char*>(g_malloc(bufsize)));
276 // Set the first byte to something other than '\0', to be able to
277 // recognize whether strftime actually failed or just returned "".
279 const gsize len = strftime(buf.get(), bufsize, locale_format.c_str(), &tm_data);
281 if(len != 0 || buf.get()[0] == '\0')
283 g_assert(len < bufsize);
284 return locale_to_utf8(std::string(buf.get(), len));
287 while((bufsize *= 2) <= 65536);
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");
292 return Glib::ustring();
295 void Date::to_struct_tm(struct tm& dest) const
297 g_date_to_struct_tm(&gobject_, &dest);
300 bool Date::valid() const
302 return g_date_valid(&gobject_);
306 bool Date::valid_day(Date::Day day)
308 return g_date_valid_day(day);
312 bool Date::valid_month(Date::Month month)
314 return g_date_valid_month((GDateMonth) month);
318 bool Date::valid_year(Date::Year year)
320 return g_date_valid_year(year);
324 bool Date::valid_weekday(Date::Weekday weekday)
326 return g_date_valid_weekday((GDateWeekday) weekday);
330 bool Date::valid_julian(guint32 julian_day)
332 return g_date_valid_julian(julian_day);
336 bool Date::valid_dmy(Date::Day day, Date::Month month, Date::Year year)
338 return g_date_valid_dmy(day, (GDateMonth) month, year);
346 } // anonymous namespace