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