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  * Conversion parameters:
26  * inFile  = gstreamer-GstDateTime.html
27  * outPack = gstreamer
28  * outFile = DateTime
29  * strct   = GstDateTime
30  * realStrct=
31  * ctorStrct=
32  * clss    = DateTime
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gst_date_time_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- gst_date_time_new_now_utc
45  * 	- gst_date_time_new_now_local_time
46  * 	- gst_date_time_new_from_unix_epoch_utc
47  * 	- gst_date_time_new_from_unix_epoch_local_time
48  * omit signals:
49  * imports:
50  * 	- glib.Str
51  * 	- gstreamer.DateTime
52  * structWrap:
53  * 	- GstDateTime* -> DateTime
54  * module aliases:
55  * local aliases:
56  * overrides:
57  */
58 
59 module gstreamer.DateTime;
60 
61 public  import gstreamerc.gstreamertypes;
62 
63 private import gstreamerc.gstreamer;
64 private import glib.ConstructionException;
65 private import gobject.ObjectG;
66 
67 
68 private import glib.Str;
69 private import gstreamer.DateTime;
70 
71 
72 
73 
74 /**
75  * Struct to store date, time and timezone information altogether.
76  * GstDateTime is refcounted and immutable.
77  *
78  * Date information is handled using the proleptic Gregorian calendar.
79  *
80  * Provides basic creation functions and accessor functions to its fields.
81  */
82 public class DateTime
83 {
84 	
85 	/** the main Gtk struct */
86 	protected GstDateTime* gstDateTime;
87 	
88 	
89 	public GstDateTime* getDateTimeStruct()
90 	{
91 		return gstDateTime;
92 	}
93 	
94 	
95 	/** the main Gtk struct as a void* */
96 	protected void* getStruct()
97 	{
98 		return cast(void*)gstDateTime;
99 	}
100 	
101 	/**
102 	 * Sets our main struct and passes it to the parent class
103 	 */
104 	public this (GstDateTime* gstDateTime)
105 	{
106 		this.gstDateTime = gstDateTime;
107 	}
108 	
109 	/**
110 	 * Creates a new GstDateTime representing the current date and time.
111 	 *
112 	 * Params:
113 	 *     utc  = If true use utc else use the local timezone.
114 	 * Throws: ConstructionException GTK+ fails to create the object.
115 	 */
116 	public this (bool utc)
117 	{
118 		GstDateTime* p;
119 		
120 		if ( utc )
121 		{
122 			p = gst_date_time_new_now_utc();
123 		}
124 		else
125 		{
126 			p = gst_date_time_new_now_local_time();
127 		}
128 		
129 		if(p is null)
130 		{
131 			throw new ConstructionException("null returned by gst_date_time_new_now_local_time()");
132 		}
133 		this(cast(GstDateTime*) p);
134 	}
135 	
136 	/**
137 	 * Creates a new GstDateTime using the time since Jan 1, 1970 specified by
138 	 * secs.
139 	 *
140 	 * Params:
141 	 *     secs = Seconds from the Unix epoch
142 	 *     utc  = If true use utc else use the local timezone.
143 	 * Throws: ConstructionException GTK+ fails to create the object.
144 	 */
145 	public this (long secs, bool utc)
146 	{
147 		GstDateTime* p;
148 		
149 		if ( utc )
150 		{
151 			p = gst_date_time_new_from_unix_epoch_utc(secs);
152 		}
153 		else
154 		{
155 			p = gst_date_time_new_from_unix_epoch_local_time(secs);
156 		}
157 		
158 		if(p is null)
159 		{
160 			throw new ConstructionException("null returned by gst_date_time_new_from_unix_epoch_local_time(secs)");
161 		}
162 		this(cast(GstDateTime*) p);
163 	}
164 	
165 	/**
166 	 */
167 	
168 	/**
169 	 * Returns the day of the month of this GstDateTime.
170 	 * Call gst_date_time_has_day before, to avoid warnings.
171 	 * Returns: The day of this GstDateTime
172 	 */
173 	public int getDay()
174 	{
175 		// gint gst_date_time_get_day (const GstDateTime *datetime);
176 		return gst_date_time_get_day(gstDateTime);
177 	}
178 	
179 	/**
180 	 * Returns the month of this GstDateTime. January is 1, February is 2, etc..
181 	 * Call gst_date_time_has_month before, to avoid warnings.
182 	 * Returns: The month of this GstDateTime
183 	 */
184 	public int getMonth()
185 	{
186 		// gint gst_date_time_get_month (const GstDateTime *datetime);
187 		return gst_date_time_get_month(gstDateTime);
188 	}
189 	
190 	/**
191 	 * Retrieves the hour of the day represented by datetime in the gregorian
192 	 * calendar. The return is in the range of 0 to 23.
193 	 * Call gst_date_time_has_haur before, to avoid warnings.
194 	 * Returns: the hour of the day
195 	 */
196 	public int getHour()
197 	{
198 		// gint gst_date_time_get_hour (const GstDateTime *datetime);
199 		return gst_date_time_get_hour(gstDateTime);
200 	}
201 	
202 	/**
203 	 * Retrieves the fractional part of the seconds in microseconds represented by
204 	 * datetime in the gregorian calendar.
205 	 * Returns: the microsecond of the second
206 	 */
207 	public int getMicrosecond()
208 	{
209 		// gint gst_date_time_get_microsecond (const GstDateTime *datetime);
210 		return gst_date_time_get_microsecond(gstDateTime);
211 	}
212 	
213 	/**
214 	 * Retrieves the minute of the hour represented by datetime in the gregorian
215 	 * calendar.
216 	 * Call gst_date_time_has_minute before, to avoid warnings.
217 	 * Returns: the minute of the hour
218 	 */
219 	public int getMinute()
220 	{
221 		// gint gst_date_time_get_minute (const GstDateTime *datetime);
222 		return gst_date_time_get_minute(gstDateTime);
223 	}
224 	
225 	/**
226 	 * Retrieves the offset from UTC in hours that the timezone specified
227 	 * by datetime represents. Timezones ahead (to the east) of UTC have positive
228 	 * values, timezones before (to the west) of UTC have negative values.
229 	 * If datetime represents UTC time, then the offset is zero.
230 	 * Returns: the offset from UTC in hours
231 	 */
232 	public float getTimeZoneOffset()
233 	{
234 		// gfloat gst_date_time_get_time_zone_offset (const GstDateTime *datetime);
235 		return gst_date_time_get_time_zone_offset(gstDateTime);
236 	}
237 	
238 	/**
239 	 * Retrieves the second of the minute represented by datetime in the gregorian
240 	 * calendar.
241 	 * Call gst_date_time_has_second before, to avoid warnings.
242 	 * Returns: the second represented by datetime
243 	 */
244 	public int getSecond()
245 	{
246 		// gint gst_date_time_get_second (const GstDateTime *datetime);
247 		return gst_date_time_get_second(gstDateTime);
248 	}
249 	
250 	/**
251 	 * Returns the year of this GstDateTime
252 	 * Call gst_date_time_has_year before, to avoid warnings.
253 	 * Returns: The year of this GstDateTime
254 	 */
255 	public int getYear()
256 	{
257 		// gint gst_date_time_get_year (const GstDateTime *datetime);
258 		return gst_date_time_get_year(gstDateTime);
259 	}
260 	
261 	/**
262 	 * Creates a new GstDateTime using the date and times in the gregorian calendar
263 	 * in the supplied timezone.
264 	 * year should be from 1 to 9999, month should be from 1 to 12, day from
265 	 * 1 to 31, hour from 0 to 23, minutes and seconds from 0 to 59.
266 	 * Note that tzoffset is a float and was chosen so for being able to handle
267 	 * some fractional timezones, while it still keeps the readability of
268 	 * represeting it in hours for most timezones.
269 	 * If value is -1 then all over value will be ignored. For example
270 	 * if month == -1, then GstDateTime will created only for year. If
271 	 * day == -1, then GstDateTime will created for year and month and
272 	 * so on.
273 	 * Free-function: gst_date_time_unref
274 	 * Params:
275 	 * tzoffset = Offset from UTC in hours.
276 	 * year = the gregorian year
277 	 * month = the gregorian month
278 	 * day = the day of the gregorian month
279 	 * hour = the hour of the day
280 	 * minute = the minute of the hour
281 	 * seconds = the second of the minute
282 	 * Throws: ConstructionException GTK+ fails to create the object.
283 	 */
284 	public this (float tzoffset, int year, int month, int day, int hour, int minute, double seconds)
285 	{
286 		// GstDateTime * gst_date_time_new (gfloat tzoffset,  gint year,  gint month,  gint day,  gint hour,  gint minute,  gdouble seconds);
287 		auto p = gst_date_time_new(tzoffset, year, month, day, hour, minute, seconds);
288 		if(p is null)
289 		{
290 			throw new ConstructionException("null returned by gst_date_time_new(tzoffset, year, month, day, hour, minute, seconds)");
291 		}
292 		this(cast(GstDateTime*) p);
293 	}
294 	
295 	/**
296 	 * Creates a new GstDateTime using the date and times in the gregorian calendar
297 	 * in the local timezone.
298 	 * year should be from 1 to 9999, month should be from 1 to 12, day from
299 	 * 1 to 31.
300 	 * If value is -1 then all over value will be ignored. For example
301 	 * if month == -1, then GstDateTime will created only for year. If
302 	 * day == -1, then GstDateTime will created for year and month and
303 	 * so on.
304 	 * Free-function: gst_date_time_unref
305 	 * Params:
306 	 * year = the gregorian year
307 	 * month = the gregorian month
308 	 * day = the day of the gregorian month
309 	 * Throws: ConstructionException GTK+ fails to create the object.
310 	 */
311 	public this (int year, int month, int day)
312 	{
313 		// GstDateTime * gst_date_time_new_ymd (gint year,  gint month,  gint day);
314 		auto p = gst_date_time_new_ymd(year, month, day);
315 		if(p is null)
316 		{
317 			throw new ConstructionException("null returned by gst_date_time_new_ymd(year, month, day)");
318 		}
319 		this(cast(GstDateTime*) p);
320 	}
321 	
322 	/**
323 	 * Creates a new GstDateTime using the date and times in the gregorian calendar
324 	 * in the local timezone.
325 	 * year should be from 1 to 9999, month should be from 1 to 12.
326 	 * If value is -1 then all over value will be ignored. For example
327 	 * if month == -1, then GstDateTime will created only for year.
328 	 * Free-function: gst_date_time_unref
329 	 * Params:
330 	 * year = the gregorian year
331 	 * month = the gregorian month
332 	 * Throws: ConstructionException GTK+ fails to create the object.
333 	 */
334 	public this (int year, int month)
335 	{
336 		// GstDateTime * gst_date_time_new_ym (gint year,  gint month);
337 		auto p = gst_date_time_new_ym(year, month);
338 		if(p is null)
339 		{
340 			throw new ConstructionException("null returned by gst_date_time_new_ym(year, month)");
341 		}
342 		this(cast(GstDateTime*) p);
343 	}
344 	
345 	/**
346 	 * Creates a new GstDateTime using the date and times in the gregorian calendar
347 	 * in the local timezone.
348 	 * year should be from 1 to 9999.
349 	 * Free-function: gst_date_time_unref
350 	 * Params:
351 	 * year = the gregorian year
352 	 * Throws: ConstructionException GTK+ fails to create the object.
353 	 */
354 	public this (int year)
355 	{
356 		// GstDateTime * gst_date_time_new_y (gint year);
357 		auto p = gst_date_time_new_y(year);
358 		if(p is null)
359 		{
360 			throw new ConstructionException("null returned by gst_date_time_new_y(year)");
361 		}
362 		this(cast(GstDateTime*) p);
363 	}
364 	
365 	/**
366 	 * Creates a new GstDateTime using the date and times in the gregorian calendar
367 	 * in the local timezone.
368 	 * year should be from 1 to 9999, month should be from 1 to 12, day from
369 	 * 1 to 31, hour from 0 to 23, minutes and seconds from 0 to 59.
370 	 * If month is -1, then the GstDateTime created will only contain year,
371 	 * and all other fields will be considered not set.
372 	 * If day is -1, then the GstDateTime created will only contain year and
373 	 * month and all other fields will be considered not set.
374 	 * If hour is -1, then the GstDateTime created will only contain year and
375 	 * month and day, and the time fields will be considered not set. In this
376 	 * case minute and seconds should also be -1.
377 	 * Free-function: gst_date_time_unref
378 	 * Params:
379 	 * year = the gregorian year
380 	 * month = the gregorian month, or -1
381 	 * day = the day of the gregorian month, or -1
382 	 * hour = the hour of the day, or -1
383 	 * minute = the minute of the hour, or -1
384 	 * seconds = the second of the minute, or -1
385 	 * Throws: ConstructionException GTK+ fails to create the object.
386 	 */
387 	public this (int year, int month, int day, int hour, int minute, double seconds)
388 	{
389 		// GstDateTime * gst_date_time_new_local_time (gint year,  gint month,  gint day,  gint hour,  gint minute,  gdouble seconds);
390 		auto p = gst_date_time_new_local_time(year, month, day, hour, minute, seconds);
391 		if(p is null)
392 		{
393 			throw new ConstructionException("null returned by gst_date_time_new_local_time(year, month, day, hour, minute, seconds)");
394 		}
395 		this(cast(GstDateTime*) p);
396 	}
397 	
398 	/**
399 	 * Atomically increments the reference count of datetime by one.
400 	 * Returns: the reference datetime. [transfer full]
401 	 */
402 	public DateTime doref()
403 	{
404 		// GstDateTime * gst_date_time_ref (GstDateTime *datetime);
405 		auto p = gst_date_time_ref(gstDateTime);
406 		
407 		if(p is null)
408 		{
409 			return null;
410 		}
411 		
412 		return ObjectG.getDObject!(DateTime)(cast(GstDateTime*) p);
413 	}
414 	
415 	/**
416 	 * Atomically decrements the reference count of datetime by one. When the
417 	 * reference count reaches zero, the structure is freed.
418 	 */
419 	public void unref()
420 	{
421 		// void gst_date_time_unref (GstDateTime *datetime);
422 		gst_date_time_unref(gstDateTime);
423 	}
424 	
425 	/**
426 	 * Returns: TRUE if datetime's day field is set, otherwise FALSE
427 	 */
428 	public int hasDay()
429 	{
430 		// gboolean gst_date_time_has_day (const GstDateTime *datetime);
431 		return gst_date_time_has_day(gstDateTime);
432 	}
433 	
434 	/**
435 	 * Returns: TRUE if datetime's month field is set, otherwise FALSE
436 	 */
437 	public int hasMonth()
438 	{
439 		// gboolean gst_date_time_has_month (const GstDateTime *datetime);
440 		return gst_date_time_has_month(gstDateTime);
441 	}
442 	
443 	/**
444 	 * Returns: TRUE if datetime's second field is set, otherwise FALSE
445 	 */
446 	public int hasSecond()
447 	{
448 		// gboolean gst_date_time_has_second (const GstDateTime *datetime);
449 		return gst_date_time_has_second(gstDateTime);
450 	}
451 	
452 	/**
453 	 * Returns: TRUE if datetime's hour and minute fields are set, otherwise FALSE
454 	 */
455 	public int hasTime()
456 	{
457 		// gboolean gst_date_time_has_time (const GstDateTime *datetime);
458 		return gst_date_time_has_time(gstDateTime);
459 	}
460 	
461 	/**
462 	 * Returns: TRUE if datetime's year field is set (which should always be the case), otherwise FALSE
463 	 */
464 	public int hasYear()
465 	{
466 		// gboolean gst_date_time_has_year (const GstDateTime *datetime);
467 		return gst_date_time_has_year(gstDateTime);
468 	}
469 	
470 	/**
471 	 * Tries to parse common variants of ISO-8601 datetime strings into a
472 	 * GstDateTime.
473 	 * Free-function: gst_date_time_unref
474 	 * Params:
475 	 * string = ISO 8601-formatted datetime string.
476 	 * Throws: ConstructionException GTK+ fails to create the object.
477 	 */
478 	public this (string string)
479 	{
480 		// GstDateTime * gst_date_time_new_from_iso8601_string  (const gchar *string);
481 		auto p = gst_date_time_new_from_iso8601_string(Str.toStringz(string));
482 		if(p is null)
483 		{
484 			throw new ConstructionException("null returned by gst_date_time_new_from_iso8601_string(Str.toStringz(string))");
485 		}
486 		this(cast(GstDateTime*) p);
487 	}
488 	
489 	/**
490 	 * Create a minimal string compatible with ISO-8601. Possible output formats
491 	 * are (for example): 2012, 2012-06, 2012-06-23, 2012-06-23T23:30Z,
492 	 * 2012-06-23T23:30+0100, 2012-06-23T23:30:59Z, 2012-06-23T23:30:59+0100
493 	 * Returns: a newly allocated string formatted according to ISO 8601 and only including the datetime fields that are valid, or NULL in case there was an error. The string should be freed with g_free().
494 	 */
495 	public string toIso8601_String()
496 	{
497 		// gchar * gst_date_time_to_iso8601_string (GstDateTime *datetime);
498 		return Str.toString(gst_date_time_to_iso8601_string(gstDateTime));
499 	}
500 	
501 	/**
502 	 * Creates a new GstDateTime from a GDateTime object.
503 	 * Free-function: gst_date_time_unref
504 	 * Params:
505 	 * dt = the GDateTime. The new GstDateTime takes ownership. [transfer full]
506 	 * Throws: ConstructionException GTK+ fails to create the object.
507 	 */
508 	public this (GDateTime* dt)
509 	{
510 		// GstDateTime * gst_date_time_new_from_g_date_time (GDateTime *dt);
511 		auto p = gst_date_time_new_from_g_date_time(dt);
512 		if(p is null)
513 		{
514 			throw new ConstructionException("null returned by gst_date_time_new_from_g_date_time(dt)");
515 		}
516 		this(cast(GstDateTime*) p);
517 	}
518 	
519 	/**
520 	 * Creates a new GDateTime from a fully defined GstDateTime object.
521 	 * Free-function: g_date_time_unref
522 	 * Returns: a newly created GDateTime, or NULL on error. [transfer full]
523 	 */
524 	public GDateTime* toGDateTime()
525 	{
526 		// GDateTime * gst_date_time_to_g_date_time (GstDateTime *datetime);
527 		return gst_date_time_to_g_date_time(gstDateTime);
528 	}
529 }