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