~ubuntu-branches/ubuntu/vivid/ardour/vivid-proposed

« back to all changes in this revision

Viewing changes to libs/glibmm2/glibmm/date.h

  • Committer: Package Import Robot
  • Author(s): Felipe Sateler, Jaromír Mikeš, Felipe Sateler
  • Date: 2014-05-22 14:39:25 UTC
  • mfrom: (29 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: package-import@ubuntu.com-20140522143925-vwqfo9287pmkrroe
Tags: 1:2.8.16+git20131003-3
* Team upload

[ Jaromír Mikeš ]
* Add -dbg package

[ Felipe Sateler ]
* Upload to experimental

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c++ -*-
 
2
// Generated by gtkmmproc -- DO NOT MODIFY!
 
3
#ifndef _GLIBMM_DATE_H
 
4
#define _GLIBMM_DATE_H
 
5
 
 
6
 
 
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
 
 
27
#include <glibmm/ustring.h>
 
28
 
 
29
#include <glib/gdate.h>
 
30
#include <glib/gtypes.h>
 
31
 
 
32
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
33
extern "C" { struct tm; }
 
34
#endif
 
35
 
 
36
 
 
37
namespace Glib
 
38
{
 
39
 
 
40
/** Julian calendar date.
 
41
 */
 
42
class Date
 
43
{
 
44
public:
 
45
  typedef guint8  Day;
 
46
  typedef guint16 Year;
 
47
 
 
48
  /** @addtogroup glibmmEnums Enums and Flags */
 
49
 
 
50
/**
 
51
 * @ingroup glibmmEnums
 
52
 */
 
53
enum Month
 
54
{
 
55
  BAD_MONTH,
 
56
  JANUARY,
 
57
  FEBRUARY,
 
58
  MARCH,
 
59
  APRIL,
 
60
  MAY,
 
61
  JUNE,
 
62
  JULY,
 
63
  AUGUST,
 
64
  SEPTEMBER,
 
65
  OCTOBER,
 
66
  NOVEMBER,
 
67
  DECEMBER
 
68
};
 
69
 
 
70
 
 
71
  /**
 
72
 * @ingroup glibmmEnums
 
73
 */
 
74
enum Weekday
 
75
{
 
76
  BAD_WEEKDAY,
 
77
  MONDAY,
 
78
  TUESDAY,
 
79
  WEDNESDAY,
 
80
  THURSDAY,
 
81
  FRIDAY,
 
82
  SATURDAY,
 
83
  SUNDAY
 
84
};
 
85
 
 
86
 
 
87
  /**
 
88
 * @ingroup glibmmEnums
 
89
 */
 
90
enum DMY
 
91
{
 
92
  DAY,
 
93
  MONTH,
 
94
  YEAR
 
95
};
 
96
 
 
97
 
 
98
  static const Day     BAD_DAY    = 0;
 
99
  static const Year    BAD_YEAR   = 0;
 
100
  static const guint32 BAD_JULIAN = 0;
 
101
 
 
102
  Date();
 
103
  Date(Day day, Month month, Year year);
 
104
  explicit Date(guint32 julian_day);
 
105
 
 
106
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
107
  explicit Date(const GDate& castitem);
 
108
#endif
 
109
 
 
110
  void clear();
 
111
  /** Clear the date. The cleared dates will not represent an existing date, but will not contain garbage.
 
112
   * @param month Month to set.
 
113
   */
 
114
 
 
115
  /** Parses a user-inputted string str, and try to figure out what date it represents, taking the current locale into account. If the string is successfully parsed, the date will be valid after the call. Otherwise, it will be invalid.   
 
116
   * This function is not appropriate for file formats and the like; it isn't very precise, and its exact behavior varies with the locale. It's intended to be a heuristic routine that guesses what the user means by a given string (and it does work pretty well in that capacity).   
 
117
   * @param str String to parse.
 
118
   */
 
119
  void set_parse (const Glib::ustring& str);
 
120
 
 
121
  //TODO: Add set_time_current() - see the docs comment below.?
 
122
  /** Sets the value of a date from a GTime (time_t) value. 
 
123
   * To set the value of a date to the current day, you could write:
 
124
   *
 
125
   *set_time(time(NULL));
 
126
   *
 
127
   * @param time GTime value to set.
 
128
   */
 
129
  void set_time(GTime time);
 
130
 
 
131
  /** Sets the month of the year. If the resulting day-month-year triplet is invalid, the date will be invalid.
 
132
   * @param month Month to set.
 
133
   */
 
134
  void set_month(Month month);
 
135
 
 
136
  /** Sets the day of the month. If the resulting day-month-year triplet is invalid, the date will be invalid.
 
137
   * @param day Day to set.
 
138
   */
 
139
  void set_day(Day day);
 
140
 
 
141
  /** Sets the year. If the resulting day-month-year triplet is invalid, the date will be invalid.
 
142
   * @param year Year to set.
 
143
   */
 
144
  void set_year(Year year);
 
145
 
 
146
  /** Sets the value of a day, month, and year.. If the resulting day-month-year triplet is invalid, the date will be invalid.
 
147
   * @param day Day to set.
 
148
   * @param month Month to set.
 
149
   * @param year Year to set.
 
150
   */
 
151
  void set_dmy(Day day, Month month, Year year);
 
152
 
 
153
  /** Sets the value of a GDate from a Julian day number.
 
154
   * @param julian_day Julian day to set.
 
155
   */
 
156
   void set_julian(guint32 julian_day);
 
157
 
 
158
  //TODO: Why return Date& (which is always *this) from these methods?
 
159
  //Isn't it enough to also change the current instance?
 
160
  //Maybe we need a copy constructor too.
 
161
  //murrayc
 
162
  
 
163
  /** Add a number of days to a Date.
 
164
   * @param n_days Days to add.
 
165
   * @return Resulting Date
 
166
   */
 
167
  Date& add_days(int n_days);
 
168
 
 
169
  /** Subtract n_days to a Date.
 
170
   * @param n_days Days to subtract.
 
171
   * @return Resulting Date
 
172
   */
 
173
  Date& subtract_days(int n_days);
 
174
 
 
175
  /** Add n_months to a Date.
 
176
   * @param n_months Months to add.
 
177
   * @return Resulting Date
 
178
   */
 
179
  Date& add_months(int n_months);
 
180
 
 
181
  /** Subtract n_months to a Date.
 
182
   * @param n_months Months to subtract.
 
183
   * @return Resulting Date
 
184
   */
 
185
  Date& subtract_months(int n_months);
 
186
 
 
187
  /** Add n_days to a Date.
 
188
   * @param n_years Years to add.
 
189
   * @return Resulting Date
 
190
   */
 
191
  Date& add_years(int n_years);
 
192
 
 
193
  /** Subtract n_years to a Date.
 
194
   * @param n_years Years to subtract.
 
195
   * @return Resulting Date
 
196
   */
 
197
  Date& subtract_years(int n_years);
 
198
 
 
199
  /** Calculate days between two dates.
 
200
   * @param rhs Date.
 
201
   * @return Numbers of days.
 
202
   */
 
203
  int days_between(const Date& rhs) const;
 
204
 
 
205
  /** Compare two dates.
 
206
   * @param rhs Date to compare.
 
207
   * @return Result of comparition.
 
208
   */
 
209
  int compare(const Date& rhs) const;
 
210
 
 
211
  /** If date is prior to min_date, sets date equal to min_date. 
 
212
   * If date falls after max_date, sets date equal to max_date. All dates must be valid.
 
213
   * See also clamp_min() and clamp_max(). 
 
214
   * @param min_date Date minimum value.
 
215
   * @param max_date Date maximum value.
 
216
   * @return Date in interval.
 
217
   */
 
218
  Date& clamp(const Date& min_date, const Date& max_date);
 
219
 
 
220
  /** If date is prior to min_date, sets date equal to min_date.
 
221
   * See also clamp(), and clamp_max().
 
222
   * @param min_date Date minimum value.
 
223
   * @return Date in interval.
 
224
   */
 
225
  Date& clamp_min(const Date& min_date);
 
226
 
 
227
  /** If date falls after max_date, sets date equal to max_date.
 
228
   * See also clamp(), and clamp_min().
 
229
   * @param max_date Date maximum value.
 
230
   * @return Date in interval.
 
231
   */
 
232
  Date& clamp_max(const Date& max_date);
 
233
  
 
234
  /** Checks if date is less than or equal to other date, and swap the values if this is not the case.
 
235
   * @param other Date ro compare.
 
236
   * @return Date.
 
237
   */
 
238
  void order(Date& other);
 
239
 
 
240
  /** Returns the day of the week for a Date. The date must be valid.
 
241
   * @return Day of the week as a Date::Weekday.
 
242
   */
 
243
  Weekday get_weekday() const;
 
244
 
 
245
  /** Returns the month of the year. The date must be valid.
 
246
   * @return Month of the year as a Date::Month. 
 
247
   */
 
248
  Month        get_month()               const;
 
249
 
 
250
  /** Returns the year of a Date. The date must be valid.
 
251
   * @return Year in which the date falls.
 
252
   */
 
253
  Year         get_year()                const;
 
254
 
 
255
  /** Returns the day of the month. The date must be valid.
 
256
   * @return Day of the month..
 
257
   */
 
258
  Day          get_day()                 const;
 
259
 
 
260
  /** Returns the Julian day or "serial number" of the Date. 
 
261
   * The Julian day is simply the number of days since January 1, Year 1; 
 
262
   * i.e., January 1, Year 1 is Julian day 1; January 2, Year 1 is Julian day 2, etc. 
 
263
   * The date must be valid.
 
264
   * @return Julian day.
 
265
   */
 
266
  guint32      get_julian()              const;
 
267
 
 
268
  /** Returns the day of the year, where Jan 1 is the first day of the year.
 
269
   * The date must be valid.
 
270
   * @return Julian day.
 
271
   */
 
272
  unsigned int get_day_of_year()         const;
 
273
 
 
274
  /** Returns the week of the year, where weeks are understood to start on Monday. 
 
275
   * If the date is before the first Monday of the year, return 0. 
 
276
   * The date must be valid.
 
277
   * @return Week of the year.
 
278
   */
 
279
  unsigned int get_monday_week_of_year() const;
 
280
 
 
281
  /** Returns the week of the year during which this date falls, if weeks are understood to being on Sunday. 
 
282
   * Can return 0 if the day is before the first Sunday of the year.
 
283
   * The date must be valid.
 
284
   * @return Week of the year.
 
285
   */
 
286
  unsigned int get_sunday_week_of_year() const;
 
287
 
 
288
  /** Returns true if the date is on the first of a month. 
 
289
   * The date must be valid.
 
290
   * @return true if the date is the first of the month. 
 
291
   */
 
292
  bool         is_first_of_month()       const;
 
293
 
 
294
  /** Returns true if the date is the last day of the month.
 
295
   * The date must be valid.
 
296
   * @return true if the date is the last day of the month.
 
297
   */
 
298
  bool         is_last_of_month()        const;
 
299
 
 
300
  /** Returns the number of days in a month, taking leap years into account.
 
301
   * @param month Month.
 
302
   * @param year Year.
 
303
   * @return Number of days in month during the year.
 
304
   */
 
305
  static guint8 get_days_in_month(Month month, Year year);
 
306
 
 
307
  /** Returns the number of weeks in the year, where weeks are taken to start on Monday. Will be 52 or 53. 
 
308
   * (Years always have 52 7-day periods, plus 1 or 2 extra days depending on whether it's a leap year. This function is basically telling you how many Mondays are in the year, i.e. there are 53 Mondays if one of the extra days happens to be a Monday.)
 
309
   * @param year Year to count weeks in.
 
310
   * @return Number of weeks.
 
311
   */
 
312
  static guint8 get_monday_weeks_in_year(Year year);
 
313
 
 
314
  /** Returns the number of weeks in the year, where weeks are taken to start on Sunday. Will be 52 or 53. 
 
315
   * (Years always have 52 7-day periods, plus 1 or 2 extra days depending on whether it's a leap year. This function is basically telling you how many Sundays are in the year, i.e. there are 53 Sundays if one of the extra days happens to be a Sunday.)
 
316
   * @param year Year to count weeks in.
 
317
   * @return Number of weeks.
 
318
   */
 
319
  static guint8 get_sunday_weeks_in_year(Year year);
 
320
 
 
321
  /** Returns true if the year is a leap year.
 
322
   * @param year Year to check.
 
323
   * @return true if the year is a leap year.
 
324
   */
 
325
  static bool   is_leap_year(Year year);
 
326
 
 
327
  /** Convert date to string.
 
328
   * @param format A format string as used by @c strftime(), in UTF-8
 
329
   * encoding.  Only date formats are allowed, the result of time formats
 
330
   * is undefined.
 
331
   * @return The formatted date string.
 
332
   * @throw Glib::ConvertError
 
333
   */
 
334
  Glib::ustring format_string(const Glib::ustring& format) const;
 
335
 
 
336
  /** Fills in the date-related bits of a struct tm using the date value. Initializes the non-date parts with something sane but meaningless.
 
337
   * @param dest Struct tm to fill.
 
338
   */
 
339
  void to_struct_tm(struct tm& dest) const;
 
340
 
 
341
  /** Returns true if the Date represents an existing day. 
 
342
   * @return true if the date is valid.
 
343
   */
 
344
  bool valid() const;
 
345
 
 
346
  /** Returns true if the day of the month is valid (a day is valid if it's between 1 and 31 inclusive).
 
347
   * @param day Day to check.
 
348
   * @return true if the day is valid.
 
349
   */
 
350
  static bool valid_day(Day day);
 
351
 
 
352
  /** Returns true if the month value is valid. The 12 Date::Month enumeration values are the only valid months.
 
353
   * @param month Month to check.
 
354
   * @return true if the month is valid.
 
355
   */
 
356
  static bool valid_month(Month month);
 
357
 
 
358
 
 
359
  /** Returns true if the year is valid. 
 
360
   * Any year greater than 0 is valid, though there is a 16-bit limit to what Date will understand.
 
361
   * @param year Year to check.
 
362
   * @return true if the year is valid.
 
363
   */
 
364
  static bool valid_year(Year year);
 
365
 
 
366
  /** Returns true if the weekday is valid. 
 
367
   * The 7 Date::Weekday enumeration values are the only valid.
 
368
   * @param weekday Weekday to check.
 
369
   * @return true if the weekday is valid.
 
370
   */
 
371
  static bool valid_weekday(Weekday weekday);
 
372
 
 
373
  /** Returns true if the Julian day is valid. 
 
374
   * Anything greater than zero is basically a valid Julian, though there is a 32-bit limit.
 
375
   * @param julian_day Julian day to check.
 
376
   * @return true if the Julian day is valid.
 
377
   */
 
378
  static bool valid_julian(guint32 julian_day);
 
379
 
 
380
 
 
381
  /** Returns true if the day-month-year triplet forms a valid, existing day in the range of days Date understands (Year 1 or later, no more than a few thousand years in the future).
 
382
   * @param day Day to check.
 
383
   * @param month Month to check.
 
384
   * @param year Year to check.
 
385
   * @return true if the date is a valid one. 
 
386
   */
 
387
  static bool valid_dmy(Day day, Month month, Year year);
 
388
 
 
389
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
390
  GDate*       gobj()       { return &gobject_; }
 
391
  const GDate* gobj() const { return &gobject_; }
 
392
#endif
 
393
 
 
394
private:
 
395
  GDate gobject_;
 
396
};
 
397
 
 
398
 
 
399
/** @relates Glib::Date */
 
400
inline bool operator==(const Date& lhs, const Date& rhs)
 
401
  { return (lhs.compare(rhs) == 0); }
 
402
 
 
403
/** @relates Glib::Date */
 
404
inline bool operator!=(const Date& lhs, const Date& rhs)
 
405
  { return (lhs.compare(rhs) != 0); }
 
406
 
 
407
/** @relates Glib::Date */
 
408
inline bool operator<(const Date& lhs, const Date& rhs)
 
409
  { return (lhs.compare(rhs) < 0); }
 
410
 
 
411
/** @relates Glib::Date */
 
412
inline bool operator>(const Date& lhs, const Date& rhs)
 
413
  { return (lhs.compare(rhs) > 0); }
 
414
 
 
415
/** @relates Glib::Date */
 
416
inline bool operator<=(const Date& lhs, const Date& rhs)
 
417
  { return (lhs.compare(rhs) <= 0); }
 
418
 
 
419
/** @relates Glib::Date */
 
420
inline bool operator>=(const Date& lhs, const Date& rhs)
 
421
  { return (lhs.compare(rhs) >= 0); }
 
422
 
 
423
} // namespace Glib
 
424
 
 
425
 
 
426
#endif /* _GLIBMM_DATE_H */
 
427