summaryrefslogtreecommitdiff
path: root/glib/src/datetime.hg
blob: 6b5c62f16e1566513f431098c8142e09ca066386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* Copyright (C) 2011 The glibmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

_DEFS(glibmm,glib)

#include <glibmmconfig.h>
#include <glibmm/refptr.h>
#include <glibmm/ustring.h>
#include <glib.h>

#ifndef DOXYGEN_SHOULD_SKIP_THIS
typedef struct _GDateTime GDateTime;
#endif

namespace Glib
{

class TimeVal;
class TimeZone;

/** A value representing an interval of time, in microseconds.  As GTimeSpan,
 * its underlying type is gint64.
 */
typedef GTimeSpan TimeSpan;

/** DateTime - A structure representing Date and Time.
 * DateTime is a structure that combines a Gregorian date and time into a
 * single structure. It provides many conversion and methods to manipulate
 * dates and times. Time precision is provided down to microseconds and the
 * time can range (proleptically) from 0001-01-01 00:00:00 to 9999-12-31
 * 23:59:59.999999. DateTime follows POSIX time in the sense that it is
 * oblivious to leap seconds.
 *
 * DateTime is an immutable object; once it has been created it cannot be
 * modified further. All modifiers will create a new DateTime. Nearly all such
 * functions can fail due to the date or time going out of range, in which case
 * <tt>0</tt> will be returned.
 *
 * DateTime is reference counted.  When the reference count drops to 0, the
 * resources allocated by the DateTime structure are released.
 *
 * Many parts of the API may produce non-obvious results. As an example, adding
 * two months to January 31st will yield March 31st whereas adding one month
 * and then one month again will yield either March 28th or March 29th. Also
 * note that adding 24 hours is not always the same as adding one day (since
 * days containing daylight savings time transitions are either 23 or 25 hours
 * in length).
 * @newin{2,30}
 */
class DateTime
{
  _CLASS_OPAQUE_COPYABLE(DateTime, GDateTime, NONE, g_date_time_ref, g_date_time_unref)
  _IGNORE(g_date_time_ref, g_date_time_unref)

public:
 _WRAP_METHOD(static DateTime create_now(const TimeZone& tz), g_date_time_new_now)
  _WRAP_METHOD(static DateTime create_now_local(), g_date_time_new_now_local)
  _WRAP_METHOD(static DateTime create_now_utc(), g_date_time_new_now_utc)

  _WRAP_METHOD(static DateTime create_now_local(gint64 t), g_date_time_new_from_unix_local)
  _WRAP_METHOD(static DateTime create_now_utc(gint64 t), g_date_time_new_from_unix_utc)

  _WRAP_METHOD(static DateTime create_now_local(const TimeVal& tv), g_date_time_new_from_timeval_local)
  _WRAP_METHOD(static DateTime create_now_utc(const TimeVal& tv), g_date_time_new_from_timeval_utc)

  _WRAP_METHOD(static DateTime create(const TimeZone& tz, int year, int month, int day, int hour, int minute, double seconds), g_date_time_new)
  _WRAP_METHOD(static DateTime create_local(int year, int month, int day, int hour, int minute, double seconds), g_date_time_new_local)
  _WRAP_METHOD(static DateTime create_utc(int year, int month, int day, int hour, int minute, double seconds), g_date_time_new_utc)

  _WRAP_METHOD(DateTime add(TimeSpan timespan) const, g_date_time_add)
  _WRAP_METHOD(DateTime add_years(int years) const, g_date_time_add_years)
  _WRAP_METHOD(DateTime add_months(int months) const, g_date_time_add_months)
  _WRAP_METHOD(DateTime add_weeks(int weeks) const, g_date_time_add_weeks)
  _WRAP_METHOD(DateTime add_days(int days) const, g_date_time_add_days)
  _WRAP_METHOD(DateTime add_hours(int hours) const, g_date_time_add_hours)
  _WRAP_METHOD(DateTime add_minutes(int minutes) const, g_date_time_add_minutes)
  _WRAP_METHOD(DateTime add_seconds(double seconds) const, g_date_time_add_seconds)
  _WRAP_METHOD(DateTime add_full(int years, int months, int days, int hours, int minutes, double seconds) const, g_date_time_add_full)
  _WRAP_METHOD(TimeSpan difference(const DateTime& other) const, g_date_time_difference)

  _WRAP_METHOD(int compare(const DateTime& other) const, g_date_time_compare)
  _WRAP_METHOD(guint hash() const, g_date_time_hash)
  _WRAP_METHOD(bool equal(const DateTime& other) const, g_date_time_equal)

  _WRAP_METHOD(void get_ymd(int& year, int& month, int& day) const, g_date_time_get_ymd)
  _WRAP_METHOD(int get_year() const, g_date_time_get_year)
  _WRAP_METHOD(int get_month() const, g_date_time_get_month)
  _WRAP_METHOD(int get_day_of_month() const, g_date_time_get_day_of_month)
  _WRAP_METHOD(int get_week_numbering_year() const, g_date_time_get_week_numbering_year)
  _WRAP_METHOD(int get_week_of_year() const, g_date_time_get_week_of_year)
  _WRAP_METHOD(int get_day_of_week() const, g_date_time_get_day_of_week)
  _WRAP_METHOD(int get_day_of_year() const, g_date_time_get_day_of_year)
  _WRAP_METHOD(int get_hour() const, g_date_time_get_hour)
  _WRAP_METHOD(int get_minute() const, g_date_time_get_minute)
  _WRAP_METHOD(int get_second() const, g_date_time_get_second)
  _WRAP_METHOD(int get_microsecond() const, g_date_time_get_microsecond)
  _WRAP_METHOD(double get_seconds() const, g_date_time_get_seconds)
  _WRAP_METHOD(gint64 to_unix() const, g_date_time_to_unix)
  _WRAP_METHOD(bool to_timeval(TimeVal& tv) const, g_date_time_to_timeval)
  _WRAP_METHOD(TimeSpan get_utc_offset() const, g_date_time_get_utc_offset)
  _WRAP_METHOD(Glib::ustring get_timezone_abbreviation() const, g_date_time_get_timezone_abbreviation)
  _WRAP_METHOD(bool is_daylight_savings() const, g_date_time_is_daylight_savings)
  _WRAP_METHOD(DateTime to_timezone(const TimeZone& tz) const, g_date_time_to_timezone)
  _WRAP_METHOD(DateTime to_local() const, g_date_time_to_local)
  _WRAP_METHOD(DateTime to_utc() const, g_date_time_to_utc)
  _WRAP_METHOD(Glib::ustring format(const Glib::ustring& format) const, g_date_time_format)
};

} // namespace Glib