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