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