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