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 glib.DateTime; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.TimeVal; 30 private import glib.TimeZone; 31 private import gtkc.Loader; 32 private import gtkc.glib; 33 public import gtkc.glibtypes; 34 private import gtkc.paths; 35 36 37 /** 38 * `GDateTime` is an opaque structure whose members 39 * cannot be accessed directly. 40 * 41 * Since: 2.26 42 */ 43 public class DateTime 44 { 45 /** the main Gtk struct */ 46 protected GDateTime* gDateTime; 47 48 /** Get the main Gtk struct */ 49 public GDateTime* getDateTimeStruct() 50 { 51 return gDateTime; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected void* getStruct() 56 { 57 return cast(void*)gDateTime; 58 } 59 60 /** 61 * Sets our main struct and passes it to the parent class. 62 */ 63 public this (GDateTime* gDateTime) 64 { 65 this.gDateTime = gDateTime; 66 } 67 68 /** 69 * Creates a DateTime corresponding to the given Unix time t 70 * Unix time is the number of seconds that have elapsed since 1970-01-01 71 * 00:00:00 UTC, regardless of the local time offset. 72 * 73 * This call can fail (ConstructionException) if t represents a time outside 74 * of the supported range of GDateTime. 75 * You should release the return value by calling unref() 76 * when you are done with it 77 * 78 * Params: 79 * t = the Unix time 80 * utc = If true use utc else use the local timezone. 81 * 82 * Throws: ConstructionException GTK+ fails to create the object. 83 * 84 * Since: 2.26 85 */ 86 public this (long t, bool utc = true) 87 { 88 GDateTime* p; 89 90 if ( utc ) 91 { 92 p = g_date_time_new_from_unix_utc(t); 93 } 94 else 95 { 96 p = g_date_time_new_from_unix_local(t); 97 } 98 99 if(p is null) 100 { 101 throw new ConstructionException("null returned by g_date_time_new_from_unix_local(t)"); 102 } 103 this(cast(GDateTime*) p); 104 } 105 106 /** 107 * Creates a DateTime corresponding to the given TimeVal tv. 108 * The time contained in a TimeVal is always stored in the form of 109 * seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the 110 * local time offset. 111 * 112 * This call can fail (ConstructionException) if tv represents a time outside 113 * of the supported range of DateTime. 114 * You should release the return value by calling unref() 115 * when you are done with it. 116 * 117 * Params: 118 * tv = a GTimeVal 119 * utc = If true use utc else use the local timezone. 120 * 121 * Throws: ConstructionException GTK+ fails to create the object. 122 * 123 * Since: 2.26 124 */ 125 public this (ref GTimeVal tv, bool utc = true) 126 { 127 GDateTime* p; 128 129 if ( utc ) 130 { 131 p = g_date_time_new_from_timeval_utc(&tv); 132 } 133 else 134 { 135 p = g_date_time_new_from_timeval_local(&tv); 136 } 137 138 if(p is null) 139 { 140 throw new ConstructionException("null returned by g_date_time_new_from_timeval_local((tv is null) ? null : tv.getTimeValStruct())"); 141 } 142 this(cast(GDateTime*) p); 143 } 144 145 ~this () 146 { 147 if ( Linker.isLoaded(LIBRARY.GLIB) && gDateTime !is null ) 148 { 149 g_date_time_unref(gDateTime); 150 } 151 } 152 153 /** */ 154 override bool opEquals(Object rhs) 155 { 156 DateTime date = cast(DateTime)rhs; 157 158 if ( date is null ) 159 return false; 160 161 return equal(this, date) != 0; 162 } 163 164 /** */ 165 override int opCmp(Object rhs) 166 { 167 DateTime date = cast(DateTime)rhs; 168 169 if ( date is null ) 170 return int.min; 171 172 return compare(this, date); 173 } 174 175 /** */ 176 override nothrow @trusted hash_t toHash() 177 { 178 return hash(); 179 } 180 181 /** 182 * Hashes datetime into a guint, suitable for use within GHashTable. 183 * Since 2.26 184 * Params: 185 * datetime = a GDateTime 186 * Returns: a guint containing the hash 187 */ 188 public nothrow @trusted uint hash() 189 { 190 try 191 { 192 return g_date_time_hash(gDateTime); 193 } 194 catch(Exception e) 195 { 196 return 0; 197 } 198 } 199 200 /** 201 */ 202 203 /** 204 * Creates a new #GDateTime corresponding to the given date and time in 205 * the time zone @tz. 206 * 207 * The @year must be between 1 and 9999, @month between 1 and 12 and @day 208 * between 1 and 28, 29, 30 or 31 depending on the month and the year. 209 * 210 * @hour must be between 0 and 23 and @minute must be between 0 and 59. 211 * 212 * @seconds must be at least 0.0 and must be strictly less than 60.0. 213 * It will be rounded down to the nearest microsecond. 214 * 215 * If the given time is not representable in the given time zone (for 216 * example, 02:30 on March 14th 2010 in Toronto, due to daylight savings 217 * time) then the time will be rounded up to the nearest existing time 218 * (in this case, 03:00). If this matters to you then you should verify 219 * the return value for containing the same as the numbers you gave. 220 * 221 * In the case that the given time is ambiguous in the given time zone 222 * (for example, 01:30 on November 7th 2010 in Toronto, due to daylight 223 * savings time) then the time falling within standard (ie: 224 * non-daylight) time is taken. 225 * 226 * It not considered a programmer error for the values to this function 227 * to be out of range, but in the case that they are, the function will 228 * return %NULL. 229 * 230 * You should release the return value by calling g_date_time_unref() 231 * when you are done with it. 232 * 233 * Params: 234 * tz = a #GTimeZone 235 * year = the year component of the date 236 * month = the month component of the date 237 * day = the day component of the date 238 * hour = the hour component of the date 239 * minute = the minute component of the date 240 * seconds = the number of seconds past the minute 241 * 242 * Return: a new #GDateTime, or %NULL 243 * 244 * Since: 2.26 245 * 246 * Throws: ConstructionException GTK+ fails to create the object. 247 */ 248 public this(TimeZone tz, int year, int month, int day, int hour, int minute, double seconds) 249 { 250 auto p = g_date_time_new((tz is null) ? null : tz.getTimeZoneStruct(), year, month, day, hour, minute, seconds); 251 252 if(p is null) 253 { 254 throw new ConstructionException("null returned by new"); 255 } 256 257 this(cast(GDateTime*) p); 258 } 259 260 /** 261 * Creates a #GDateTime corresponding to this exact instant in the given 262 * time zone @tz. The time is as accurate as the system allows, to a 263 * maximum accuracy of 1 microsecond. 264 * 265 * This function will always succeed unless the system clock is set to 266 * truly insane values (or unless GLib is still being used after the 267 * year 9999). 268 * 269 * You should release the return value by calling g_date_time_unref() 270 * when you are done with it. 271 * 272 * Params: 273 * tz = a #GTimeZone 274 * 275 * Return: a new #GDateTime, or %NULL 276 * 277 * Since: 2.26 278 * 279 * Throws: ConstructionException GTK+ fails to create the object. 280 */ 281 public this(TimeZone tz) 282 { 283 auto p = g_date_time_new_now((tz is null) ? null : tz.getTimeZoneStruct()); 284 285 if(p is null) 286 { 287 throw new ConstructionException("null returned by new_now"); 288 } 289 290 this(cast(GDateTime*) p); 291 } 292 293 /** 294 * Creates a copy of @datetime and adds the specified timespan to the copy. 295 * 296 * Params: 297 * timespan = a #GTimeSpan 298 * 299 * Return: the newly created #GDateTime which should be freed with 300 * g_date_time_unref(). 301 * 302 * Since: 2.26 303 */ 304 public DateTime add(GTimeSpan timespan) 305 { 306 auto p = g_date_time_add(gDateTime, timespan); 307 308 if(p is null) 309 { 310 return null; 311 } 312 313 return new DateTime(cast(GDateTime*) p); 314 } 315 316 /** 317 * Creates a copy of @datetime and adds the specified number of days to the 318 * copy. Add negative values to subtract days. 319 * 320 * Params: 321 * days = the number of days 322 * 323 * Return: the newly created #GDateTime which should be freed with 324 * g_date_time_unref(). 325 * 326 * Since: 2.26 327 */ 328 public DateTime addDays(int days) 329 { 330 auto p = g_date_time_add_days(gDateTime, days); 331 332 if(p is null) 333 { 334 return null; 335 } 336 337 return new DateTime(cast(GDateTime*) p); 338 } 339 340 /** 341 * Creates a new #GDateTime adding the specified values to the current date and 342 * time in @datetime. Add negative values to subtract. 343 * 344 * Params: 345 * years = the number of years to add 346 * months = the number of months to add 347 * days = the number of days to add 348 * hours = the number of hours to add 349 * minutes = the number of minutes to add 350 * seconds = the number of seconds to add 351 * 352 * Return: the newly created #GDateTime that should be freed with 353 * g_date_time_unref(). 354 * 355 * Since: 2.26 356 */ 357 public DateTime addFull(int years, int months, int days, int hours, int minutes, double seconds) 358 { 359 auto p = g_date_time_add_full(gDateTime, years, months, days, hours, minutes, seconds); 360 361 if(p is null) 362 { 363 return null; 364 } 365 366 return new DateTime(cast(GDateTime*) p); 367 } 368 369 /** 370 * Creates a copy of @datetime and adds the specified number of hours. 371 * Add negative values to subtract hours. 372 * 373 * Params: 374 * hours = the number of hours to add 375 * 376 * Return: the newly created #GDateTime which should be freed with 377 * g_date_time_unref(). 378 * 379 * Since: 2.26 380 */ 381 public DateTime addHours(int hours) 382 { 383 auto p = g_date_time_add_hours(gDateTime, hours); 384 385 if(p is null) 386 { 387 return null; 388 } 389 390 return new DateTime(cast(GDateTime*) p); 391 } 392 393 /** 394 * Creates a copy of @datetime adding the specified number of minutes. 395 * Add negative values to subtract minutes. 396 * 397 * Params: 398 * minutes = the number of minutes to add 399 * 400 * Return: the newly created #GDateTime which should be freed with 401 * g_date_time_unref(). 402 * 403 * Since: 2.26 404 */ 405 public DateTime addMinutes(int minutes) 406 { 407 auto p = g_date_time_add_minutes(gDateTime, minutes); 408 409 if(p is null) 410 { 411 return null; 412 } 413 414 return new DateTime(cast(GDateTime*) p); 415 } 416 417 /** 418 * Creates a copy of @datetime and adds the specified number of months to the 419 * copy. Add negative values to subtract months. 420 * 421 * Params: 422 * months = the number of months 423 * 424 * Return: the newly created #GDateTime which should be freed with 425 * g_date_time_unref(). 426 * 427 * Since: 2.26 428 */ 429 public DateTime addMonths(int months) 430 { 431 auto p = g_date_time_add_months(gDateTime, months); 432 433 if(p is null) 434 { 435 return null; 436 } 437 438 return new DateTime(cast(GDateTime*) p); 439 } 440 441 /** 442 * Creates a copy of @datetime and adds the specified number of seconds. 443 * Add negative values to subtract seconds. 444 * 445 * Params: 446 * seconds = the number of seconds to add 447 * 448 * Return: the newly created #GDateTime which should be freed with 449 * g_date_time_unref(). 450 * 451 * Since: 2.26 452 */ 453 public DateTime addSeconds(double seconds) 454 { 455 auto p = g_date_time_add_seconds(gDateTime, seconds); 456 457 if(p is null) 458 { 459 return null; 460 } 461 462 return new DateTime(cast(GDateTime*) p); 463 } 464 465 /** 466 * Creates a copy of @datetime and adds the specified number of weeks to the 467 * copy. Add negative values to subtract weeks. 468 * 469 * Params: 470 * weeks = the number of weeks 471 * 472 * Return: the newly created #GDateTime which should be freed with 473 * g_date_time_unref(). 474 * 475 * Since: 2.26 476 */ 477 public DateTime addWeeks(int weeks) 478 { 479 auto p = g_date_time_add_weeks(gDateTime, weeks); 480 481 if(p is null) 482 { 483 return null; 484 } 485 486 return new DateTime(cast(GDateTime*) p); 487 } 488 489 /** 490 * Creates a copy of @datetime and adds the specified number of years to the 491 * copy. Add negative values to subtract years. 492 * 493 * Params: 494 * years = the number of years 495 * 496 * Return: the newly created #GDateTime which should be freed with 497 * g_date_time_unref(). 498 * 499 * Since: 2.26 500 */ 501 public DateTime addYears(int years) 502 { 503 auto p = g_date_time_add_years(gDateTime, years); 504 505 if(p is null) 506 { 507 return null; 508 } 509 510 return new DateTime(cast(GDateTime*) p); 511 } 512 513 /** 514 * Calculates the difference in time between @end and @begin. The 515 * #GTimeSpan that is returned is effectively @end - @begin (ie: 516 * positive if the first parameter is larger). 517 * 518 * Params: 519 * begin = a #GDateTime 520 * 521 * Return: the difference between the two #GDateTime, as a time 522 * span expressed in microseconds. 523 * 524 * Since: 2.26 525 */ 526 public GTimeSpan difference(DateTime begin) 527 { 528 return g_date_time_difference(gDateTime, (begin is null) ? null : begin.getDateTimeStruct()); 529 } 530 531 /** 532 * Creates a newly allocated string representing the requested @format. 533 * 534 * The format strings understood by this function are a subset of the 535 * strftime() format language as specified by C99. The \%D, \%U and \%W 536 * conversions are not supported, nor is the 'E' modifier. The GNU 537 * extensions \%k, \%l, \%s and \%P are supported, however, as are the 538 * '0', '_' and '-' modifiers. 539 * 540 * In contrast to strftime(), this function always produces a UTF-8 541 * string, regardless of the current locale. Note that the rendering of 542 * many formats is locale-dependent and may not match the strftime() 543 * output exactly. 544 * 545 * The following format specifiers are supported: 546 * 547 * - \%a: the abbreviated weekday name according to the current locale 548 * - \%A: the full weekday name according to the current locale 549 * - \%b: the abbreviated month name according to the current locale 550 * - \%B: the full month name according to the current locale 551 * - \%c: the preferred date and time rpresentation for the current locale 552 * - \%C: the century number (year/100) as a 2-digit integer (00-99) 553 * - \%d: the day of the month as a decimal number (range 01 to 31) 554 * - \%e: the day of the month as a decimal number (range 1 to 31) 555 * - \%F: equivalent to `%Y-%m-%d` (the ISO 8601 date format) 556 * - \%g: the last two digits of the ISO 8601 week-based year as a 557 * decimal number (00-99). This works well with \%V and \%u. 558 * - \%G: the ISO 8601 week-based year as a decimal number. This works 559 * well with \%V and \%u. 560 * - \%h: equivalent to \%b 561 * - \%H: the hour as a decimal number using a 24-hour clock (range 00 to 23) 562 * - \%I: the hour as a decimal number using a 12-hour clock (range 01 to 12) 563 * - \%j: the day of the year as a decimal number (range 001 to 366) 564 * - \%k: the hour (24-hour clock) as a decimal number (range 0 to 23); 565 * single digits are preceded by a blank 566 * - \%l: the hour (12-hour clock) as a decimal number (range 1 to 12); 567 * single digits are preceded by a blank 568 * - \%m: the month as a decimal number (range 01 to 12) 569 * - \%M: the minute as a decimal number (range 00 to 59) 570 * - \%p: either "AM" or "PM" according to the given time value, or the 571 * corresponding strings for the current locale. Noon is treated as 572 * "PM" and midnight as "AM". 573 * - \%P: like \%p but lowercase: "am" or "pm" or a corresponding string for 574 * the current locale 575 * - \%r: the time in a.m. or p.m. notation 576 * - \%R: the time in 24-hour notation (\%H:\%M) 577 * - \%s: the number of seconds since the Epoch, that is, since 1970-01-01 578 * 00:00:00 UTC 579 * - \%S: the second as a decimal number (range 00 to 60) 580 * - \%t: a tab character 581 * - \%T: the time in 24-hour notation with seconds (\%H:\%M:\%S) 582 * - \%u: the ISO 8601 standard day of the week as a decimal, range 1 to 7, 583 * Monday being 1. This works well with \%G and \%V. 584 * - \%V: the ISO 8601 standard week number of the current year as a decimal 585 * number, range 01 to 53, where week 1 is the first week that has at 586 * least 4 days in the new year. See g_date_time_get_week_of_year(). 587 * This works well with \%G and \%u. 588 * - \%w: the day of the week as a decimal, range 0 to 6, Sunday being 0. 589 * This is not the ISO 8601 standard format -- use \%u instead. 590 * - \%x: the preferred date representation for the current locale without 591 * the time 592 * - \%X: the preferred time representation for the current locale without 593 * the date 594 * - \%y: the year as a decimal number without the century 595 * - \%Y: the year as a decimal number including the century 596 * - \%z: the time zone as an offset from UTC (+hhmm) 597 * - \%:z: the time zone as an offset from UTC (+hh:mm). 598 * This is a gnulib strftime() extension. Since: 2.38 599 * - \%::z: the time zone as an offset from UTC (+hh:mm:ss). This is a 600 * gnulib strftime() extension. Since: 2.38 601 * - \%:::z: the time zone as an offset from UTC, with : to necessary 602 * precision (e.g., -04, +05:30). This is a gnulib strftime() extension. Since: 2.38 603 * - \%Z: the time zone or name or abbreviation 604 * - \%\%: a literal \% character 605 * 606 * Some conversion specifications can be modified by preceding the 607 * conversion specifier by one or more modifier characters. The 608 * following modifiers are supported for many of the numeric 609 * conversions: 610 * 611 * - O: Use alternative numeric symbols, if the current locale supports those. 612 * - _: Pad a numeric result with spaces. This overrides the default padding 613 * for the specifier. 614 * - -: Do not pad a numeric result. This overrides the default padding 615 * for the specifier. 616 * - 0: Pad a numeric result with zeros. This overrides the default padding 617 * for the specifier. 618 * 619 * Params: 620 * format = a valid UTF-8 string, containing the format for the 621 * #GDateTime 622 * 623 * Return: a newly allocated string formatted to the requested format 624 * or %NULL in the case that there was an error. The string 625 * should be freed with g_free(). 626 * 627 * Since: 2.26 628 */ 629 public string format(string format) 630 { 631 return Str.toString(g_date_time_format(gDateTime, Str.toStringz(format))); 632 } 633 634 /** 635 * Retrieves the day of the month represented by @datetime in the gregorian 636 * calendar. 637 * 638 * Return: the day of the month 639 * 640 * Since: 2.26 641 */ 642 public int getDayOfMonth() 643 { 644 return g_date_time_get_day_of_month(gDateTime); 645 } 646 647 /** 648 * Retrieves the ISO 8601 day of the week on which @datetime falls (1 is 649 * Monday, 2 is Tuesday... 7 is Sunday). 650 * 651 * Return: the day of the week 652 * 653 * Since: 2.26 654 */ 655 public int getDayOfWeek() 656 { 657 return g_date_time_get_day_of_week(gDateTime); 658 } 659 660 /** 661 * Retrieves the day of the year represented by @datetime in the Gregorian 662 * calendar. 663 * 664 * Return: the day of the year 665 * 666 * Since: 2.26 667 */ 668 public int getDayOfYear() 669 { 670 return g_date_time_get_day_of_year(gDateTime); 671 } 672 673 /** 674 * Retrieves the hour of the day represented by @datetime 675 * 676 * Return: the hour of the day 677 * 678 * Since: 2.26 679 */ 680 public int getHour() 681 { 682 return g_date_time_get_hour(gDateTime); 683 } 684 685 /** 686 * Retrieves the microsecond of the date represented by @datetime 687 * 688 * Return: the microsecond of the second 689 * 690 * Since: 2.26 691 */ 692 public int getMicrosecond() 693 { 694 return g_date_time_get_microsecond(gDateTime); 695 } 696 697 /** 698 * Retrieves the minute of the hour represented by @datetime 699 * 700 * Return: the minute of the hour 701 * 702 * Since: 2.26 703 */ 704 public int getMinute() 705 { 706 return g_date_time_get_minute(gDateTime); 707 } 708 709 /** 710 * Retrieves the month of the year represented by @datetime in the Gregorian 711 * calendar. 712 * 713 * Return: the month represented by @datetime 714 * 715 * Since: 2.26 716 */ 717 public int getMonth() 718 { 719 return g_date_time_get_month(gDateTime); 720 } 721 722 /** 723 * Retrieves the second of the minute represented by @datetime 724 * 725 * Return: the second represented by @datetime 726 * 727 * Since: 2.26 728 */ 729 public int getSecond() 730 { 731 return g_date_time_get_second(gDateTime); 732 } 733 734 /** 735 * Retrieves the number of seconds since the start of the last minute, 736 * including the fractional part. 737 * 738 * Return: the number of seconds 739 * 740 * Since: 2.26 741 */ 742 public double getSeconds() 743 { 744 return g_date_time_get_seconds(gDateTime); 745 } 746 747 /** 748 * Determines the time zone abbreviation to be used at the time and in 749 * the time zone of @datetime. 750 * 751 * For example, in Toronto this is currently "EST" during the winter 752 * months and "EDT" during the summer months when daylight savings 753 * time is in effect. 754 * 755 * Return: the time zone abbreviation. The returned 756 * string is owned by the #GDateTime and it should not be 757 * modified or freed 758 * 759 * Since: 2.26 760 */ 761 public string getTimezoneAbbreviation() 762 { 763 return Str.toString(g_date_time_get_timezone_abbreviation(gDateTime)); 764 } 765 766 /** 767 * Determines the offset to UTC in effect at the time and in the time 768 * zone of @datetime. 769 * 770 * The offset is the number of microseconds that you add to UTC time to 771 * arrive at local time for the time zone (ie: negative numbers for time 772 * zones west of GMT, positive numbers for east). 773 * 774 * If @datetime represents UTC time, then the offset is always zero. 775 * 776 * Return: the number of microseconds that should be added to UTC to 777 * get the local time 778 * 779 * Since: 2.26 780 */ 781 public GTimeSpan getUtcOffset() 782 { 783 return g_date_time_get_utc_offset(gDateTime); 784 } 785 786 /** 787 * Returns the ISO 8601 week-numbering year in which the week containing 788 * @datetime falls. 789 * 790 * This function, taken together with g_date_time_get_week_of_year() and 791 * g_date_time_get_day_of_week() can be used to determine the full ISO 792 * week date on which @datetime falls. 793 * 794 * This is usually equal to the normal Gregorian year (as returned by 795 * g_date_time_get_year()), except as detailed below: 796 * 797 * For Thursday, the week-numbering year is always equal to the usual 798 * calendar year. For other days, the number is such that every day 799 * within a complete week (Monday to Sunday) is contained within the 800 * same week-numbering year. 801 * 802 * For Monday, Tuesday and Wednesday occurring near the end of the year, 803 * this may mean that the week-numbering year is one greater than the 804 * calendar year (so that these days have the same week-numbering year 805 * as the Thursday occurring early in the next year). 806 * 807 * For Friday, Saturday and Sunday occurring near the start of the year, 808 * this may mean that the week-numbering year is one less than the 809 * calendar year (so that these days have the same week-numbering year 810 * as the Thursday occurring late in the previous year). 811 * 812 * An equivalent description is that the week-numbering year is equal to 813 * the calendar year containing the majority of the days in the current 814 * week (Monday to Sunday). 815 * 816 * Note that January 1 0001 in the proleptic Gregorian calendar is a 817 * Monday, so this function never returns 0. 818 * 819 * Return: the ISO 8601 week-numbering year for @datetime 820 * 821 * Since: 2.26 822 */ 823 public int getWeekNumberingYear() 824 { 825 return g_date_time_get_week_numbering_year(gDateTime); 826 } 827 828 /** 829 * Returns the ISO 8601 week number for the week containing @datetime. 830 * The ISO 8601 week number is the same for every day of the week (from 831 * Moday through Sunday). That can produce some unusual results 832 * (described below). 833 * 834 * The first week of the year is week 1. This is the week that contains 835 * the first Thursday of the year. Equivalently, this is the first week 836 * that has more than 4 of its days falling within the calendar year. 837 * 838 * The value 0 is never returned by this function. Days contained 839 * within a year but occurring before the first ISO 8601 week of that 840 * year are considered as being contained in the last week of the 841 * previous year. Similarly, the final days of a calendar year may be 842 * considered as being part of the first ISO 8601 week of the next year 843 * if 4 or more days of that week are contained within the new year. 844 * 845 * Return: the ISO 8601 week number for @datetime. 846 * 847 * Since: 2.26 848 */ 849 public int getWeekOfYear() 850 { 851 return g_date_time_get_week_of_year(gDateTime); 852 } 853 854 /** 855 * Retrieves the year represented by @datetime in the Gregorian calendar. 856 * 857 * Return: the year represented by @datetime 858 * 859 * Since: 2.26 860 */ 861 public int getYear() 862 { 863 return g_date_time_get_year(gDateTime); 864 } 865 866 /** 867 * Retrieves the Gregorian day, month, and year of a given #GDateTime. 868 * 869 * Params: 870 * year = the return location for the gregorian year, or %NULL. 871 * month = the return location for the month of the year, or %NULL. 872 * day = the return location for the day of the month, or %NULL. 873 * 874 * Since: 2.26 875 */ 876 public void getYmd(out int year, out int month, out int day) 877 { 878 g_date_time_get_ymd(gDateTime, &year, &month, &day); 879 } 880 881 /** 882 * Determines if daylight savings time is in effect at the time and in 883 * the time zone of @datetime. 884 * 885 * Return: %TRUE if daylight savings time is in effect 886 * 887 * Since: 2.26 888 */ 889 public bool isDaylightSavings() 890 { 891 return g_date_time_is_daylight_savings(gDateTime) != 0; 892 } 893 894 /** 895 * Atomically increments the reference count of @datetime by one. 896 * 897 * Return: the #GDateTime with the reference count increased 898 * 899 * Since: 2.26 900 */ 901 public DateTime doref() 902 { 903 auto p = g_date_time_ref(gDateTime); 904 905 if(p is null) 906 { 907 return null; 908 } 909 910 return new DateTime(cast(GDateTime*) p); 911 } 912 913 /** 914 * Creates a new #GDateTime corresponding to the same instant in time as 915 * @datetime, but in the local time zone. 916 * 917 * This call is equivalent to calling g_date_time_to_timezone() with the 918 * time zone returned by g_time_zone_new_local(). 919 * 920 * Return: the newly created #GDateTime 921 * 922 * Since: 2.26 923 */ 924 public DateTime toLocal() 925 { 926 auto p = g_date_time_to_local(gDateTime); 927 928 if(p is null) 929 { 930 return null; 931 } 932 933 return new DateTime(cast(GDateTime*) p); 934 } 935 936 /** 937 * Stores the instant in time that @datetime represents into @tv. 938 * 939 * The time contained in a #GTimeVal is always stored in the form of 940 * seconds elapsed since 1970-01-01 00:00:00 UTC, regardless of the time 941 * zone associated with @datetime. 942 * 943 * On systems where 'long' is 32bit (ie: all 32bit systems and all 944 * Windows systems), a #GTimeVal is incapable of storing the entire 945 * range of values that #GDateTime is capable of expressing. On those 946 * systems, this function returns %FALSE to indicate that the time is 947 * out of range. 948 * 949 * On systems where 'long' is 64bit, this function never fails. 950 * 951 * Params: 952 * tv = a #GTimeVal to modify 953 * 954 * Return: %TRUE if successful, else %FALSE 955 * 956 * Since: 2.26 957 */ 958 public bool toTimeval(TimeVal tv) 959 { 960 return g_date_time_to_timeval(gDateTime, (tv is null) ? null : tv.getTimeValStruct()) != 0; 961 } 962 963 /** 964 * Create a new #GDateTime corresponding to the same instant in time as 965 * @datetime, but in the time zone @tz. 966 * 967 * This call can fail in the case that the time goes out of bounds. For 968 * example, converting 0001-01-01 00:00:00 UTC to a time zone west of 969 * Greenwich will fail (due to the year 0 being out of range). 970 * 971 * You should release the return value by calling g_date_time_unref() 972 * when you are done with it. 973 * 974 * Params: 975 * tz = the new #GTimeZone 976 * 977 * Return: a new #GDateTime, or %NULL 978 * 979 * Since: 2.26 980 */ 981 public DateTime toTimezone(TimeZone tz) 982 { 983 auto p = g_date_time_to_timezone(gDateTime, (tz is null) ? null : tz.getTimeZoneStruct()); 984 985 if(p is null) 986 { 987 return null; 988 } 989 990 return new DateTime(cast(GDateTime*) p); 991 } 992 993 /** 994 * Gives the Unix time corresponding to @datetime, rounding down to the 995 * nearest second. 996 * 997 * Unix time is the number of seconds that have elapsed since 1970-01-01 998 * 00:00:00 UTC, regardless of the time zone associated with @datetime. 999 * 1000 * Return: the Unix time corresponding to @datetime 1001 * 1002 * Since: 2.26 1003 */ 1004 public long toUnix() 1005 { 1006 return g_date_time_to_unix(gDateTime); 1007 } 1008 1009 /** 1010 * Creates a new #GDateTime corresponding to the same instant in time as 1011 * @datetime, but in UTC. 1012 * 1013 * This call is equivalent to calling g_date_time_to_timezone() with the 1014 * time zone returned by g_time_zone_new_utc(). 1015 * 1016 * Return: the newly created #GDateTime 1017 * 1018 * Since: 2.26 1019 */ 1020 public DateTime toUtc() 1021 { 1022 auto p = g_date_time_to_utc(gDateTime); 1023 1024 if(p is null) 1025 { 1026 return null; 1027 } 1028 1029 return new DateTime(cast(GDateTime*) p); 1030 } 1031 1032 /** 1033 * Atomically decrements the reference count of @datetime by one. 1034 * 1035 * When the reference count reaches zero, the resources allocated by 1036 * @datetime are freed 1037 * 1038 * Since: 2.26 1039 */ 1040 public void unref() 1041 { 1042 g_date_time_unref(gDateTime); 1043 } 1044 1045 /** 1046 * A comparison function for #GDateTimes that is suitable 1047 * as a #GCompareFunc. Both #GDateTimes must be non-%NULL. 1048 * 1049 * Params: 1050 * dt1 = first #GDateTime to compare 1051 * dt2 = second #GDateTime to compare 1052 * 1053 * Return: -1, 0 or 1 if @dt1 is less than, equal to or greater 1054 * than @dt2. 1055 * 1056 * Since: 2.26 1057 */ 1058 public static int compare(DateTime dt1, DateTime dt2) 1059 { 1060 return g_date_time_compare((dt1 is null) ? null : dt1.getDateTimeStruct(), (dt2 is null) ? null : dt2.getDateTimeStruct()); 1061 } 1062 1063 /** 1064 * Checks to see if @dt1 and @dt2 are equal. 1065 * 1066 * Equal here means that they represent the same moment after converting 1067 * them to the same time zone. 1068 * 1069 * Params: 1070 * dt1 = a #GDateTime 1071 * dt2 = a #GDateTime 1072 * 1073 * Return: %TRUE if @dt1 and @dt2 are equal 1074 * 1075 * Since: 2.26 1076 */ 1077 public static bool equal(DateTime dt1, DateTime dt2) 1078 { 1079 return g_date_time_equal((dt1 is null) ? null : dt1.getDateTimeStruct(), (dt2 is null) ? null : dt2.getDateTimeStruct()) != 0; 1080 } 1081 }