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