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 glib.c.functions;
30 public  import glib.c.types;
31 public  import gtkc.glibtypes;
32 private import gtkd.Loader;
33 
34 
35 /**
36  * #GTimeZone is an opaque structure whose members cannot be accessed
37  * directly.
38  *
39  * Since: 2.26
40  */
41 public class TimeZone
42 {
43 	/** the main Gtk struct */
44 	protected GTimeZone* gTimeZone;
45 	protected bool ownedRef;
46 
47 	/** Get the main Gtk struct */
48 	public GTimeZone* getTimeZoneStruct(bool transferOwnership = false)
49 	{
50 		if (transferOwnership)
51 			ownedRef = false;
52 		return gTimeZone;
53 	}
54 
55 	/** the main Gtk struct as a void* */
56 	protected void* getStruct()
57 	{
58 		return cast(void*)gTimeZone;
59 	}
60 
61 	/**
62 	 * Sets our main struct and passes it to the parent class.
63 	 */
64 	public this (GTimeZone* gTimeZone, bool ownedRef = false)
65 	{
66 		this.gTimeZone = gTimeZone;
67 		this.ownedRef = ownedRef;
68 	}
69 
70 	~this ()
71 	{
72 		if ( Linker.isLoaded(LIBRARY_GLIB) && ownedRef )
73 			g_time_zone_unref(gTimeZone);
74 	}
75 
76 
77 	/**
78 	 * Creates a #GTimeZone corresponding to @identifier.
79 	 *
80 	 * @identifier can either be an RFC3339/ISO 8601 time offset or
81 	 * something that would pass as a valid value for the `TZ` environment
82 	 * variable (including %NULL).
83 	 *
84 	 * In Windows, @identifier can also be the unlocalized name of a time
85 	 * zone for standard time, for example "Pacific Standard Time".
86 	 *
87 	 * Valid RFC3339 time offsets are `"Z"` (for UTC) or
88 	 * `"±hh:mm"`.  ISO 8601 additionally specifies
89 	 * `"±hhmm"` and `"±hh"`.  Offsets are
90 	 * time values to be added to Coordinated Universal Time (UTC) to get
91 	 * the local time.
92 	 *
93 	 * In UNIX, the `TZ` environment variable typically corresponds
94 	 * to the name of a file in the zoneinfo database, an absolute path to a file
95 	 * somewhere else, or a string in
96 	 * "std offset [dst [offset],start[/time],end[/time]]" (POSIX) format.
97 	 * There  are  no spaces in the specification. The name of standard
98 	 * and daylight savings time zone must be three or more alphabetic
99 	 * characters. Offsets are time values to be added to local time to
100 	 * get Coordinated Universal Time (UTC) and should be
101 	 * `"[±]hh[[:]mm[:ss]]"`.  Dates are either
102 	 * `"Jn"` (Julian day with n between 1 and 365, leap
103 	 * years not counted), `"n"` (zero-based Julian day
104 	 * with n between 0 and 365) or `"Mm.w.d"` (day d
105 	 * (0 <= d <= 6) of week w (1 <= w <= 5) of month m (1 <= m <= 12), day
106 	 * 0 is a Sunday).  Times are in local wall clock time, the default is
107 	 * 02:00:00.
108 	 *
109 	 * In Windows, the "tzn[+|–]hh[:mm[:ss]][dzn]" format is used, but also
110 	 * accepts POSIX format.  The Windows format uses US rules for all time
111 	 * zones; daylight savings time is 60 minutes behind the standard time
112 	 * with date and time of change taken from Pacific Standard Time.
113 	 * Offsets are time values to be added to the local time to get
114 	 * Coordinated Universal Time (UTC).
115 	 *
116 	 * g_time_zone_new_local() calls this function with the value of the
117 	 * `TZ` environment variable. This function itself is independent of
118 	 * the value of `TZ`, but if @identifier is %NULL then `/etc/localtime`
119 	 * will be consulted to discover the correct time zone on UNIX and the
120 	 * registry will be consulted or GetTimeZoneInformation() will be used
121 	 * to get the local time zone on Windows.
122 	 *
123 	 * If intervals are not available, only time zone rules from `TZ`
124 	 * environment variable or other means, then they will be computed
125 	 * from year 1900 to 2037.  If the maximum year for the rules is
126 	 * available and it is greater than 2037, then it will followed
127 	 * instead.
128 	 *
129 	 * See
130 	 * [RFC3339 §5.6](http://tools.ietf.org/html/rfc3339#section-5.6)
131 	 * for a precise definition of valid RFC3339 time offsets
132 	 * (the `time-offset` expansion) and ISO 8601 for the
133 	 * full list of valid time offsets.  See
134 	 * [The GNU C Library manual](http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html)
135 	 * for an explanation of the possible
136 	 * values of the `TZ` environment variable. See
137 	 * [Microsoft Time Zone Index Values](http://msdn.microsoft.com/en-us/library/ms912391%28v=winembedded.11%29.aspx)
138 	 * for the list of time zones on Windows.
139 	 *
140 	 * You should release the return value by calling g_time_zone_unref()
141 	 * when you are done with it.
142 	 *
143 	 * Params:
144 	 *     identifier = a timezone identifier
145 	 *
146 	 * Returns: the requested timezone
147 	 *
148 	 * Since: 2.26
149 	 *
150 	 * Throws: ConstructionException GTK+ fails to create the object.
151 	 */
152 	public this(string identifier)
153 	{
154 		auto __p = g_time_zone_new(Str.toStringz(identifier));
155 
156 		if(__p is null)
157 		{
158 			throw new ConstructionException("null returned by new");
159 		}
160 
161 		this(cast(GTimeZone*) __p);
162 	}
163 
164 	/**
165 	 * Creates a #GTimeZone corresponding to the given constant offset from UTC,
166 	 * in seconds.
167 	 *
168 	 * This is equivalent to calling g_time_zone_new() with a string in the form
169 	 * `[+|-]hh[:mm[:ss]]`.
170 	 *
171 	 * Params:
172 	 *     seconds = offset to UTC, in seconds
173 	 *
174 	 * Returns: a timezone at the given offset from UTC
175 	 *
176 	 * Since: 2.58
177 	 *
178 	 * Throws: ConstructionException GTK+ fails to create the object.
179 	 */
180 	public this(int seconds)
181 	{
182 		auto __p = g_time_zone_new_offset(seconds);
183 
184 		if(__p is null)
185 		{
186 			throw new ConstructionException("null returned by new_offset");
187 		}
188 
189 		this(cast(GTimeZone*) __p);
190 	}
191 
192 	/**
193 	 * Finds an interval within @tz that corresponds to the given @time_,
194 	 * possibly adjusting @time_ if required to fit into an interval.
195 	 * The meaning of @time_ depends on @type.
196 	 *
197 	 * This function is similar to g_time_zone_find_interval(), with the
198 	 * difference that it always succeeds (by making the adjustments
199 	 * described below).
200 	 *
201 	 * In any of the cases where g_time_zone_find_interval() succeeds then
202 	 * this function returns the same value, without modifying @time_.
203 	 *
204 	 * This function may, however, modify @time_ in order to deal with
205 	 * non-existent times.  If the non-existent local @time_ of 02:30 were
206 	 * requested on March 14th 2010 in Toronto then this function would
207 	 * adjust @time_ to be 03:00 and return the interval containing the
208 	 * adjusted time.
209 	 *
210 	 * Params:
211 	 *     type = the #GTimeType of @time_
212 	 *     time = a pointer to a number of seconds since January 1, 1970
213 	 *
214 	 * Returns: the interval containing @time_, never -1
215 	 *
216 	 * Since: 2.26
217 	 */
218 	public int adjustTime(GTimeType type, long* time)
219 	{
220 		return g_time_zone_adjust_time(gTimeZone, type, time);
221 	}
222 
223 	/**
224 	 * Finds an interval within @tz that corresponds to the given @time_.
225 	 * The meaning of @time_ depends on @type.
226 	 *
227 	 * If @type is %G_TIME_TYPE_UNIVERSAL then this function will always
228 	 * succeed (since universal time is monotonic and continuous).
229 	 *
230 	 * Otherwise @time_ is treated as local time.  The distinction between
231 	 * %G_TIME_TYPE_STANDARD and %G_TIME_TYPE_DAYLIGHT is ignored except in
232 	 * the case that the given @time_ is ambiguous.  In Toronto, for example,
233 	 * 01:30 on November 7th 2010 occurred twice (once inside of daylight
234 	 * savings time and the next, an hour later, outside of daylight savings
235 	 * time).  In this case, the different value of @type would result in a
236 	 * different interval being returned.
237 	 *
238 	 * It is still possible for this function to fail.  In Toronto, for
239 	 * example, 02:00 on March 14th 2010 does not exist (due to the leap
240 	 * forward to begin daylight savings time).  -1 is returned in that
241 	 * case.
242 	 *
243 	 * Params:
244 	 *     type = the #GTimeType of @time_
245 	 *     time = a number of seconds since January 1, 1970
246 	 *
247 	 * Returns: the interval containing @time_, or -1 in case of failure
248 	 *
249 	 * Since: 2.26
250 	 */
251 	public int findInterval(GTimeType type, long time)
252 	{
253 		return g_time_zone_find_interval(gTimeZone, type, time);
254 	}
255 
256 	/**
257 	 * Determines the time zone abbreviation to be used during a particular
258 	 * @interval of time in the time zone @tz.
259 	 *
260 	 * For example, in Toronto this is currently "EST" during the winter
261 	 * months and "EDT" during the summer months when daylight savings time
262 	 * is in effect.
263 	 *
264 	 * Params:
265 	 *     interval = an interval within the timezone
266 	 *
267 	 * Returns: the time zone abbreviation, which belongs to @tz
268 	 *
269 	 * Since: 2.26
270 	 */
271 	public string getAbbreviation(int interval)
272 	{
273 		return Str.toString(g_time_zone_get_abbreviation(gTimeZone, interval));
274 	}
275 
276 	/**
277 	 * Get the identifier of this #GTimeZone, as passed to g_time_zone_new().
278 	 * If the identifier passed at construction time was not recognised, `UTC` will
279 	 * be returned. If it was %NULL, the identifier of the local timezone at
280 	 * construction time will be returned.
281 	 *
282 	 * The identifier will be returned in the same format as provided at
283 	 * construction time: if provided as a time offset, that will be returned by
284 	 * this function.
285 	 *
286 	 * Returns: identifier for this timezone
287 	 *
288 	 * Since: 2.58
289 	 */
290 	public string getIdentifier()
291 	{
292 		return Str.toString(g_time_zone_get_identifier(gTimeZone));
293 	}
294 
295 	/**
296 	 * Determines the offset to UTC in effect during a particular @interval
297 	 * of time in the time zone @tz.
298 	 *
299 	 * The offset is the number of seconds that you add to UTC time to
300 	 * arrive at local time for @tz (ie: negative numbers for time zones
301 	 * west of GMT, positive numbers for east).
302 	 *
303 	 * Params:
304 	 *     interval = an interval within the timezone
305 	 *
306 	 * Returns: the number of seconds that should be added to UTC to get the
307 	 *     local time in @tz
308 	 *
309 	 * Since: 2.26
310 	 */
311 	public int getOffset(int interval)
312 	{
313 		return g_time_zone_get_offset(gTimeZone, interval);
314 	}
315 
316 	/**
317 	 * Determines if daylight savings time is in effect during a particular
318 	 * @interval of time in the time zone @tz.
319 	 *
320 	 * Params:
321 	 *     interval = an interval within the timezone
322 	 *
323 	 * Returns: %TRUE if daylight savings time is in effect
324 	 *
325 	 * Since: 2.26
326 	 */
327 	public bool isDst(int interval)
328 	{
329 		return g_time_zone_is_dst(gTimeZone, interval) != 0;
330 	}
331 
332 	alias doref = ref_;
333 	/**
334 	 * Increases the reference count on @tz.
335 	 *
336 	 * Returns: a new reference to @tz.
337 	 *
338 	 * Since: 2.26
339 	 */
340 	public TimeZone ref_()
341 	{
342 		auto __p = g_time_zone_ref(gTimeZone);
343 
344 		if(__p is null)
345 		{
346 			return null;
347 		}
348 
349 		return new TimeZone(cast(GTimeZone*) __p, true);
350 	}
351 
352 	/**
353 	 * Decreases the reference count on @tz.
354 	 *
355 	 * Since: 2.26
356 	 */
357 	public void unref()
358 	{
359 		g_time_zone_unref(gTimeZone);
360 	}
361 }