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