1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module glib.TimeZone;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gtkc.glib;
30 public  import gtkc.glibtypes;
31 
32 
33 /**
34  * #GTimeZone is an opaque structure whose members cannot be accessed
35  * directly.
36  *
37  * Since: 2.26
38  */
39 public class TimeZone
40 {
41 	/** the main Gtk struct */
42 	protected GTimeZone* gTimeZone;
43 
44 	/** Get the main Gtk struct */
45 	public GTimeZone* getTimeZoneStruct()
46 	{
47 		return gTimeZone;
48 	}
49 
50 	/** the main Gtk struct as a void* */
51 	protected void* getStruct()
52 	{
53 		return cast(void*)gTimeZone;
54 	}
55 
56 	/**
57 	 * Sets our main struct and passes it to the parent class.
58 	 */
59 	public this (GTimeZone* gTimeZone)
60 	{
61 		this.gTimeZone = gTimeZone;
62 	}
63 
64 
65 	/**
66 	 * Creates a #GTimeZone corresponding to @identifier.
67 	 *
68 	 * @identifier can either be an RFC3339/ISO 8601 time offset or
69 	 * something that would pass as a valid value for the `TZ` environment
70 	 * variable (including %NULL).
71 	 *
72 	 * In Windows, @identifier can also be the unlocalized name of a time
73 	 * zone for standard time, for example "Pacific Standard Time".
74 	 *
75 	 * Valid RFC3339 time offsets are `"Z"` (for UTC) or
76 	 * `"±hh:mm"`.  ISO 8601 additionally specifies
77 	 * `"±hhmm"` and `"±hh"`.  Offsets are
78 	 * time values to be added to Coordinated Universal Time (UTC) to get
79 	 * the local time.
80 	 *
81 	 * In UNIX, the `TZ` environment variable typically corresponds
82 	 * to the name of a file in the zoneinfo database, or string in
83 	 * "std offset [dst [offset],start[/time],end[/time]]" (POSIX) format.
84 	 * There  are  no spaces in the specification. The name of standard
85 	 * and daylight savings time zone must be three or more alphabetic
86 	 * characters. Offsets are time values to be added to local time to
87 	 * get Coordinated Universal Time (UTC) and should be
88 	 * `"[±]hh[[:]mm[:ss]]"`.  Dates are either
89 	 * `"Jn"` (Julian day with n between 1 and 365, leap
90 	 * years not counted), `"n"` (zero-based Julian day
91 	 * with n between 0 and 365) or `"Mm.w.d"` (day d
92 	 * (0 <= d <= 6) of week w (1 <= w <= 5) of month m (1 <= m <= 12), day
93 	 * 0 is a Sunday).  Times are in local wall clock time, the default is
94 	 * 02:00:00.
95 	 *
96 	 * In Windows, the "tzn[+|–]hh[:mm[:ss]][dzn]" format is used, but also
97 	 * accepts POSIX format.  The Windows format uses US rules for all time
98 	 * zones; daylight savings time is 60 minutes behind the standard time
99 	 * with date and time of change taken from Pacific Standard Time.
100 	 * Offsets are time values to be added to the local time to get
101 	 * Coordinated Universal Time (UTC).
102 	 *
103 	 * g_time_zone_new_local() calls this function with the value of the
104 	 * `TZ` environment variable. This function itself is independent of
105 	 * the value of `TZ`, but if @identifier is %NULL then `/etc/localtime`
106 	 * will be consulted to discover the correct time zone on UNIX and the
107 	 * registry will be consulted or GetTimeZoneInformation() will be used
108 	 * to get the local time zone on Windows.
109 	 *
110 	 * If intervals are not available, only time zone rules from `TZ`
111 	 * environment variable or other means, then they will be computed
112 	 * from year 1900 to 2037.  If the maximum year for the rules is
113 	 * available and it is greater than 2037, then it will followed
114 	 * instead.
115 	 *
116 	 * See
117 	 * [RFC3339 §5.6](http://tools.ietf.org/html/rfc3339#section-5.6)
118 	 * for a precise definition of valid RFC3339 time offsets
119 	 * (the `time-offset` expansion) and ISO 8601 for the
120 	 * full list of valid time offsets.  See
121 	 * [The GNU C Library manual](http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html)
122 	 * for an explanation of the possible
123 	 * values of the `TZ` environment variable. See
124 	 * [Microsoft Time Zone Index Values](http://msdn.microsoft.com/en-us/library/ms912391%28v=winembedded.11%29.aspx)
125 	 * for the list of time zones on Windows.
126 	 *
127 	 * You should release the return value by calling g_time_zone_unref()
128 	 * when you are done with it.
129 	 *
130 	 * Params:
131 	 *     identifier = a timezone identifier
132 	 *
133 	 * Return: the requested timezone
134 	 *
135 	 * Since: 2.26
136 	 *
137 	 * Throws: ConstructionException GTK+ fails to create the object.
138 	 */
139 	public this(string identifier)
140 	{
141 		auto p = g_time_zone_new(Str.toStringz(identifier));
142 		
143 		if(p is null)
144 		{
145 			throw new ConstructionException("null returned by new");
146 		}
147 		
148 		this(cast(GTimeZone*) p);
149 	}
150 
151 	/**
152 	 * Finds an interval within @tz that corresponds to the given @time_,
153 	 * possibly adjusting @time_ if required to fit into an interval.
154 	 * The meaning of @time_ depends on @type.
155 	 *
156 	 * This function is similar to g_time_zone_find_interval(), with the
157 	 * difference that it always succeeds (by making the adjustments
158 	 * described below).
159 	 *
160 	 * In any of the cases where g_time_zone_find_interval() succeeds then
161 	 * this function returns the same value, without modifying @time_.
162 	 *
163 	 * This function may, however, modify @time_ in order to deal with
164 	 * non-existent times.  If the non-existent local @time_ of 02:30 were
165 	 * requested on March 14th 2010 in Toronto then this function would
166 	 * adjust @time_ to be 03:00 and return the interval containing the
167 	 * adjusted time.
168 	 *
169 	 * Params:
170 	 *     type = the #GTimeType of @time_
171 	 *     time = a pointer to a number of seconds since January 1, 1970
172 	 *
173 	 * Return: the interval containing @time_, never -1
174 	 *
175 	 * Since: 2.26
176 	 */
177 	public int adjustTime(GTimeType type, long* time)
178 	{
179 		return g_time_zone_adjust_time(gTimeZone, type, time);
180 	}
181 
182 	/**
183 	 * Finds an the interval within @tz that corresponds to the given @time_.
184 	 * The meaning of @time_ depends on @type.
185 	 *
186 	 * If @type is %G_TIME_TYPE_UNIVERSAL then this function will always
187 	 * succeed (since universal time is monotonic and continuous).
188 	 *
189 	 * Otherwise @time_ is treated as local time.  The distinction between
190 	 * %G_TIME_TYPE_STANDARD and %G_TIME_TYPE_DAYLIGHT is ignored except in
191 	 * the case that the given @time_ is ambiguous.  In Toronto, for example,
192 	 * 01:30 on November 7th 2010 occurred twice (once inside of daylight
193 	 * savings time and the next, an hour later, outside of daylight savings
194 	 * time).  In this case, the different value of @type would result in a
195 	 * different interval being returned.
196 	 *
197 	 * It is still possible for this function to fail.  In Toronto, for
198 	 * example, 02:00 on March 14th 2010 does not exist (due to the leap
199 	 * forward to begin daylight savings time).  -1 is returned in that
200 	 * case.
201 	 *
202 	 * Params:
203 	 *     type = the #GTimeType of @time_
204 	 *     time = a number of seconds since January 1, 1970
205 	 *
206 	 * Return: the interval containing @time_, or -1 in case of failure
207 	 *
208 	 * Since: 2.26
209 	 */
210 	public int findInterval(GTimeType type, long time)
211 	{
212 		return g_time_zone_find_interval(gTimeZone, type, time);
213 	}
214 
215 	/**
216 	 * Determines the time zone abbreviation to be used during a particular
217 	 * @interval of time in the time zone @tz.
218 	 *
219 	 * For example, in Toronto this is currently "EST" during the winter
220 	 * months and "EDT" during the summer months when daylight savings time
221 	 * is in effect.
222 	 *
223 	 * Params:
224 	 *     interval = an interval within the timezone
225 	 *
226 	 * Return: the time zone abbreviation, which belongs to @tz
227 	 *
228 	 * Since: 2.26
229 	 */
230 	public string getAbbreviation(int interval)
231 	{
232 		return Str.toString(g_time_zone_get_abbreviation(gTimeZone, interval));
233 	}
234 
235 	/**
236 	 * Determines the offset to UTC in effect during a particular @interval
237 	 * of time in the time zone @tz.
238 	 *
239 	 * The offset is the number of seconds that you add to UTC time to
240 	 * arrive at local time for @tz (ie: negative numbers for time zones
241 	 * west of GMT, positive numbers for east).
242 	 *
243 	 * Params:
244 	 *     interval = an interval within the timezone
245 	 *
246 	 * Return: the number of seconds that should be added to UTC to get the
247 	 *     local time in @tz
248 	 *
249 	 * Since: 2.26
250 	 */
251 	public int getOffset(int interval)
252 	{
253 		return g_time_zone_get_offset(gTimeZone, interval);
254 	}
255 
256 	/**
257 	 * Determines if daylight savings time is in effect during a particular
258 	 * @interval of time in the time zone @tz.
259 	 *
260 	 * Params:
261 	 *     interval = an interval within the timezone
262 	 *
263 	 * Return: %TRUE if daylight savings time is in effect
264 	 *
265 	 * Since: 2.26
266 	 */
267 	public bool isDst(int interval)
268 	{
269 		return g_time_zone_is_dst(gTimeZone, interval) != 0;
270 	}
271 
272 	/**
273 	 * Increases the reference count on @tz.
274 	 *
275 	 * Return: a new reference to @tz.
276 	 *
277 	 * Since: 2.26
278 	 */
279 	public TimeZone doref()
280 	{
281 		auto p = g_time_zone_ref(gTimeZone);
282 		
283 		if(p is null)
284 		{
285 			return null;
286 		}
287 		
288 		return new TimeZone(cast(GTimeZone*) p);
289 	}
290 
291 	/**
292 	 * Decreases the reference count on @tz.
293 	 *
294 	 * Since: 2.26
295 	 */
296 	public void unref()
297 	{
298 		g_time_zone_unref(gTimeZone);
299 	}
300 }