source: appstream-generator/build/girepo/glib/DateTime.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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