2 * This file is part of duit.
4 * duit 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 2.1 of the License, or
7 * (at your option) any later version.
9 * duit 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.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = glib-Date-and-Time-Functions.html
52 private import glib
.glibtypes
;
54 private import lib
.glib
;
56 private import glib
.Str
;
60 * The GDate data structure represents a day between January 1, Year 1,
61 * and sometime a few thousand years in the future (right now it will go
62 * to the year 65535 or so, but g_date_set_parse() only parses up to the
63 * year 8000 or so - just count on "a few thousand"). GDate is meant to
64 * represent everyday dates, not astronomical dates or historical dates
65 * or ISO timestamps or the like. It extrapolates the current Gregorian
66 * calendar forward and backward in time; there is no attempt to change
67 * the calendar to match time periods or locations. GDate does not store
68 * time information; it represents a day.
69 * The GDate implementation has several nice features; it is only a
70 * 64-bit struct, so storing large numbers of dates is very efficient. It
71 * can keep both a Julian and day-month-year representation of the date,
72 * since some calculations are much easier with one representation or the
73 * other. A Julian representation is simply a count of days since some
74 * fixed day in the past; for GDate the fixed day is January 1, 1 AD.
75 * ("Julian" dates in the GDate API aren't really Julian dates in the
76 * technical sense; technically, Julian dates count from the start of the
77 * Julian period, Jan 1, 4713 BC).
78 * GDate is simple to use. First you need a "blank" date; you can get a
79 * dynamically allocated date from g_date_new(), or you can declare an
80 * automatic variable or array and initialize it to a sane state by
81 * calling g_date_clear(). A cleared date is sane; it's safe to call
82 * g_date_set_dmy() and the other mutator functions to initialize the
83 * value of a cleared date. However, a cleared date is initially
84 * invalid, meaning that it doesn't represent a day
85 * that exists. It is undefined to call any of the date calculation
86 * routines on an invalid date. If you obtain a date from a user or other
87 * unpredictable source, you should check its validity with the
88 * g_date_valid() predicate. g_date_valid() is also used to check for
89 * errors with g_date_set_parse() and other functions that can
90 * fail. Dates can be invalidated by calling g_date_clear() again.
91 * It is very important to use the API to access the GDate
92 * struct. Often only the day-month-year or only the Julian
93 * representation is valid. Sometimes neither is valid. Use the API.
94 * GLib doesn't contain any time-manipulation functions; however, there
95 * is a GTime typedef and a GTimeVal struct which represents a more
96 * precise time (with microseconds). You can request the current time as
97 * a GTimeVal with g_get_current_time().
102 /** the main Gtk struct */
103 protected GDate
* gDate
;
106 public GDate
* getDateStruct()
112 /** the main Gtk struct as a void* */
113 protected void* getStruct()
115 return cast(void*)gDate
;
119 * Sets our main struct and passes it to the parent class
121 public this (GDate
* gDate
)
132 * Equivalent to the UNIX gettimeofday() function, but portable.
134 * GTimeVal structure in which to store current time.
136 public static void gGetCurrentTime(GTimeVal
* result
)
138 // void g_get_current_time (GTimeVal *result);
139 g_get_current_time(result
);
143 * Pauses the current thread for the given number of microseconds. There
144 * are 1 million microseconds per second (represented by the
145 * G_USEC_PER_SEC macro). g_usleep() may have limited precision,
146 * depending on hardware and operating system; don't rely on the exact
147 * length of the sleep.
149 * number of microseconds to pause.
151 public static void gUsleep(uint microseconds
)
153 // void g_usleep (gulong microseconds);
154 g_usleep(microseconds
);
158 * Adds the given number of microseconds to time_. microseconds can
159 * also be negative to decrease the value of time_.
163 * number of microseconds to add to time
165 public static void gTimeValAdd(GTimeVal
* time
, int microseconds
)
167 // void g_time_val_add (GTimeVal *time_, glong microseconds);
168 g_time_val_add(time
, microseconds
);
172 * Converts a string containing an ISO 8601 encoded date and time
173 * to a GTimeVal and puts it into time_.
175 * a ISO 8601 encoded date string
179 * TRUE if the conversion was successful.
182 public static int gTimeValFromIso8601(char[] isoDate
, GTimeVal
* time
)
184 // gboolean g_time_val_from_iso8601 (const gchar *iso_date, GTimeVal *time_);
185 return g_time_val_from_iso8601(Str
.toStringz(isoDate
), time
);
189 * Converts time_ into a ISO 8601 encoded string, relative to the
190 * Coordinated Universal Time (UTC).
194 * a newly allocated string containing a ISO 8601 date
197 public static char[] gTimeValToIso8601(GTimeVal
* time
)
199 // gchar* g_time_val_to_iso8601 (GTimeVal *time_);
200 return Str
.toString(g_time_val_to_iso8601(time
) );
214 * Allocates a GDate and initializes it to a sane state. The new date will
215 * be cleared (as if you'd called g_date_clear()) but invalid (it won't
216 * represent an existing day). Free the return value with g_date_free().
218 * a newly-allocated GDate.
222 // GDate* g_date_new (void);
223 this(cast(GDate
*)g_date_new() );
227 * Like g_date_new(), but also sets the value of the date. Assuming the
228 * day-month-year triplet you pass in represents an existing day, the
229 * returned date will be valid.
237 * a newly-allocated GDate initialized with day, month, and year.
239 public this (GDateDay day
, GDateMonth month
, GDateYear year
)
241 // GDate* g_date_new_dmy (GDateDay day, GDateMonth month, GDateYear year);
242 this(cast(GDate
*)g_date_new_dmy(day
, month
, year
) );
246 * Like g_date_new(), but also sets the value of the date. Assuming the
247 * Julian day number you pass in is valid (greater than 0, less than an
248 * unreasonably large number), the returned date will be valid.
250 * days since January 1, Year 1.
252 * a newly-allocated GDate initialized with julian_day.
254 public this (uint julianDay
)
256 // GDate* g_date_new_julian (guint32 julian_day);
257 this(cast(GDate
*)g_date_new_julian(julianDay
) );
261 * Initializes one or more GDate structs to a sane but invalid
262 * state. The cleared dates will not represent an existing date, but will
263 * not contain garbage. Useful to init a date declared on the stack.
264 * Validity can be tested with g_date_valid().
266 * pointer to one or more dates to clear.
268 * number of dates to clear.
270 public void clear(uint nDates
)
272 // void g_date_clear (GDate *date, guint n_dates);
273 g_date_clear(gDate
, nDates
);
277 * Frees a GDate returned from g_date_new().
283 // void g_date_free (GDate *date);
288 * Sets the day of the month for a GDate. If the resulting day-month-year
289 * triplet is invalid, the date will be invalid.
295 public void setDay(GDateDay day
)
297 // void g_date_set_day (GDate *date, GDateDay day);
298 g_date_set_day(gDate
, day
);
302 * Sets the month of the year for a GDate. If the resulting
303 * day-month-year triplet is invalid, the date will be invalid.
309 public void setMonth(GDateMonth month
)
311 // void g_date_set_month (GDate *date, GDateMonth month);
312 g_date_set_month(gDate
, month
);
316 * Sets the year for a GDate. If the resulting day-month-year triplet is
317 * invalid, the date will be invalid.
323 public void setYear(GDateYear year
)
325 // void g_date_set_year (GDate *date, GDateYear year);
326 g_date_set_year(gDate
, year
);
330 * Sets the value of a GDate from a day, month, and year. The day-month-year
331 * triplet must be valid; if you aren't sure it is, call g_date_valid_dmy() to
332 * check before you set it.
342 public void setDmy(GDateDay day
, GDateMonth month
, GDateYear y
)
344 // void g_date_set_dmy (GDate *date, GDateDay day, GDateMonth month, GDateYear y);
345 g_date_set_dmy(gDate
, day
, month
, y
);
349 * Sets the value of a GDate from a Julian day number.
353 * Julian day number (days since January 1, Year 1).
355 public void setJulian(uint julianDate
)
357 // void g_date_set_julian (GDate *date, guint32 julian_date);
358 g_date_set_julian(gDate
, julianDate
);
363 * g_date_set_time is deprecated and should not be used in newly-written code.
364 * Sets the value of a date from a GTime value.
365 * Deprecated:2.10: Use g_date_set_time_t() instead.
369 * GTime value to set.
371 public void setTime(GTime time
)
373 // void g_date_set_time (GDate *date, GTime time_);
374 g_date_set_time(gDate
, time
);
378 * Sets the value of a date from a time_t value.
379 * To set the value of a date to the current day, you could write:
380 * g_date_set_time_t (date, time (NULL));
384 * time_t value to set
387 public void setTimeT(uint timet
)
389 // void g_date_set_time_t (GDate *date, time_t timet);
390 g_date_set_time_t(gDate
, timet
);
394 * Sets the value of a date from a GTimeVal value. Note that the
395 * tv_usec member is ignored, because GDate can't make use of the
396 * additional precision.
400 * GTimeVal value to set
403 public void setTimeVal(GTimeVal
* timeval
)
405 // void g_date_set_time_val (GDate *date, GTimeVal *timeval);
406 g_date_set_time_val(gDate
, timeval
);
410 * Parses a user-inputted string str, and try to figure out what date it
411 * represents, taking the current locale into account. If the string is
412 * successfully parsed, the date will be valid after the call. Otherwise,
413 * it will be invalid. You should check using g_date_valid() to see
414 * whether the parsing succeeded.
415 * This function is not appropriate for file formats and the like; it
416 * isn't very precise, and its exact behavior varies with the
417 * locale. It's intended to be a heuristic routine that guesses what the
418 * user means by a given string (and it does work pretty well in that
421 * a GDate to fill in.
425 public void setParse(char[] str)
427 // void g_date_set_parse (GDate *date, const gchar *str);
428 g_date_set_parse(gDate
, Str
.toStringz(str));
432 * Increments a date some number of days. To move forward by weeks, add
433 * weeks*7 days. The date must be valid.
435 * a GDate to increment.
437 * number of days to move the date forward.
439 public void addDays(uint nDays
)
441 // void g_date_add_days (GDate *date, guint n_days);
442 g_date_add_days(gDate
, nDays
);
446 * Moves a date some number of days into the past. To move by weeks, just
447 * move by weeks*7 days. The date must be valid.
449 * a GDate to decrement.
451 * number of days to move.
453 public void subtractDays(uint nDays
)
455 // void g_date_subtract_days (GDate *date, guint n_days);
456 g_date_subtract_days(gDate
, nDays
);
460 * Increments a date by some number of months. If the day of the month is
461 * greater than 28, this routine may change the day of the month (because
462 * the destination month may not have the current day in it). The date
465 * a GDate to increment.
467 * number of months to move forward.
469 public void addMonths(uint nMonths
)
471 // void g_date_add_months (GDate *date, guint n_months);
472 g_date_add_months(gDate
, nMonths
);
476 * Moves a date some number of months into the past. If the current day of
477 * the month doesn't exist in the destination month, the day of the month
478 * may change. The date must be valid.
480 * a GDate to decrement.
482 * number of months to move.
484 public void subtractMonths(uint nMonths
)
486 // void g_date_subtract_months (GDate *date, guint n_months);
487 g_date_subtract_months(gDate
, nMonths
);
491 * Increments a date by some number of years. If the date is February 29,
492 * and the destination year is not a leap year, the date will be changed
493 * to February 28. The date must be valid.
495 * a GDate to increment.
497 * number of years to move forward.
499 public void addYears(uint nYears
)
501 // void g_date_add_years (GDate *date, guint n_years);
502 g_date_add_years(gDate
, nYears
);
506 * Moves a date some number of years into the past. If the current day
507 * doesn't exist in the destination year (i.e. it's February 29 and you
508 * move to a non-leap-year) then the day is changed to February 29. The date
511 * a GDate to decrement.
513 * number of years to move.
515 public void subtractYears(uint nYears
)
517 // void g_date_subtract_years (GDate *date, guint n_years);
518 g_date_subtract_years(gDate
, nYears
);
522 * Computes the number of days between two dates.
523 * If date2 is prior to date1, the returned value is negative.
524 * Both dates must be valid.
530 * the number of days between date1 and date2.
532 public int daysBetween(Date date2
)
534 // gint g_date_days_between (const GDate *date1, const GDate *date2);
535 return g_date_days_between(gDate
, (date2
is null) ?
null : date2
.getDateStruct());
539 * qsort()-style comparsion function for dates. Both
540 * dates must be valid.
542 * first date to compare.
544 * second date to compare.
546 * 0 for equal, less than zero if lhs is less than rhs,
547 * greater than zero if lhs is greater than rhs.
549 public int compare(Date rhs
)
551 // gint g_date_compare (const GDate *lhs, const GDate *rhs);
552 return g_date_compare(gDate
, (rhs
is null) ?
null : rhs
.getDateStruct());
556 * If date is prior to min_date, sets date equal to min_date.
557 * If date falls after max_date, sets date equal to max_date.
558 * Either min_date and max_date may be NULL. All non-NULL dates
563 * minimum accepted value for date.
565 * maximum accepted value for date.
567 public void clamp(Date minDate
, Date maxDate
)
569 // void g_date_clamp (GDate *date, const GDate *min_date, const GDate *max_date);
570 g_date_clamp(gDate
, (minDate
is null) ?
null : minDate
.getDateStruct(), (maxDate
is null) ?
null : maxDate
.getDateStruct());
574 * Checks if date1 is less than or equal to date2,
575 * and swap the values if this is not the case.
581 public void order(Date date2
)
583 // void g_date_order (GDate *date1, GDate *date2);
584 g_date_order(gDate
, (date2
is null) ?
null : date2
.getDateStruct());
588 * Returns the day of the month. The date must be valid.
590 * a GDate to extract the day of the month from.
594 public GDateDay
getDay()
596 // GDateDay g_date_get_day (const GDate *date);
597 return g_date_get_day(gDate
);
601 * Returns the month of the year. The date must be valid.
603 * a GDate to get the month from.
605 * month of the year as a GDateMonth.
607 public GDateMonth
getMonth()
609 // GDateMonth g_date_get_month (const GDate *date);
610 return g_date_get_month(gDate
);
614 * Returns the year of a GDate. The date must be valid.
618 * year in which the date falls.
620 public GDateYear
getYear()
622 // GDateYear g_date_get_year (const GDate *date);
623 return g_date_get_year(gDate
);
627 * Returns the Julian day or "serial number" of the GDate. The
628 * Julian day is simply the number of days since January 1, Year 1; i.e.,
629 * January 1, Year 1 is Julian day 1; January 2, Year 1 is Julian day 2,
630 * etc. The date must be valid.
632 * a GDate to extract the Julian day from.
636 public uint getJulian()
638 // guint32 g_date_get_julian (const GDate *date);
639 return g_date_get_julian(gDate
);
643 * Returns the day of the week for a GDate. The date must be valid.
647 * day of the week as a GDateWeekday.
649 public GDateWeekday
getWeekday()
651 // GDateWeekday g_date_get_weekday (const GDate *date);
652 return g_date_get_weekday(gDate
);
656 * Returns the day of the year, where Jan 1 is the first day of the
657 * year. The date must be valid.
659 * a GDate to extract day of year from.
663 public uint getDayOfYear()
665 // guint g_date_get_day_of_year (const GDate *date);
666 return g_date_get_day_of_year(gDate
);
670 * Returns the number of days in a month, taking leap years into account.
676 * number of days in month during the year.
678 public static byte getDaysInMonth(GDateMonth month
, GDateYear year
)
680 // guint8 g_date_get_days_in_month (GDateMonth month, GDateYear year);
681 return g_date_get_days_in_month(month
, year
);
685 * Returns TRUE if the date is on the first of a month. The date must be valid.
689 * TRUE if the date is the first of the month.
691 public int isFirstOfMonth()
693 // gboolean g_date_is_first_of_month (const GDate *date);
694 return g_date_is_first_of_month(gDate
);
698 * Returns TRUE if the date is the last day of the month. The date must be valid.
702 * TRUE if the date is the last day of the month.
704 public int isLastOfMonth()
706 // gboolean g_date_is_last_of_month (const GDate *date);
707 return g_date_is_last_of_month(gDate
);
711 * Returns TRUE if the year is a leap year.
715 * TRUE if the year is a leap year.
717 public static int isLeapYear(GDateYear year
)
719 // gboolean g_date_is_leap_year (GDateYear year);
720 return g_date_is_leap_year(year
);
724 * Returns the week of the year, where weeks are understood to start on
725 * Monday. If the date is before the first Monday of the year, return
726 * 0. The date must be valid.
732 public uint getMondayWeekOfYear()
734 // guint g_date_get_monday_week_of_year (const GDate *date);
735 return g_date_get_monday_week_of_year(gDate
);
739 * Returns the number of weeks in the year, where weeks are taken to start
740 * on Monday. Will be 52 or 53. The date must be valid. (Years always have 52
741 * 7-day periods, plus 1 or 2 extra days depending on whether it's a leap
742 * year. This function is basically telling you how many Mondays are in
743 * the year, i.e. there are 53 Mondays if one of the extra days happens
748 * number of Mondays in the year.
750 public static byte getMondayWeeksInYear(GDateYear year
)
752 // guint8 g_date_get_monday_weeks_in_year (GDateYear year);
753 return g_date_get_monday_weeks_in_year(year
);
757 * Returns the week of the year during which this date falls, if weeks
758 * are understood to being on Sunday. The date must be valid. Can return 0 if
759 * the day is before the first Sunday of the year.
765 public uint getSundayWeekOfYear()
767 // guint g_date_get_sunday_week_of_year (const GDate *date);
768 return g_date_get_sunday_week_of_year(gDate
);
772 * Returns the number of weeks in the year, where weeks are taken to start
773 * on Sunday. Will be 52 or 53. The date must be valid. (Years always have 52
774 * 7-day periods, plus 1 or 2 extra days depending on whether it's a leap
775 * year. This function is basically telling you how many Sundays are in
776 * the year, i.e. there are 53 Sundays if one of the extra days happens
779 * year to count weeks in.
783 public static byte getSundayWeeksInYear(GDateYear year
)
785 // guint8 g_date_get_sunday_weeks_in_year (GDateYear year);
786 return g_date_get_sunday_weeks_in_year(year
);
790 * Returns the week of the year, where weeks are interpreted according
795 * ISO 8601 week number of the year.
798 public uint getIso8601_WeekOfYear()
800 // guint g_date_get_iso8601_week_of_year (const GDate *date);
801 return g_date_get_iso8601_week_of_year(gDate
);
805 * Generates a printed representation of the date, in a locale-specific
806 * way. Works just like the platform's C library
807 * strftime() function, but only accepts
808 * date-related formats; time-related formats give undefined
809 * results. Date must be valid. Unlike strftime()
810 * (which uses the locale encoding), works on a UTF-8 format string and
811 * stores a UTF-8 result.
812 * This function does not provide any conversion specifiers in addition
813 * to those implemented by the platform's C library. For example, don't
814 * expect that using g_date_strftime() would make
815 * the F provided by the C99 strftime() work on
816 * Windows where the C library only complies to C89.
818 * destination buffer.
826 * number of characters written to the buffer, or 0 the buffer was too small.
828 public static uint strftime(char[] s
, uint slen
, char[] format
, Date date
)
830 // gsize g_date_strftime (gchar *s, gsize slen, const gchar *format, const GDate *date);
831 return g_date_strftime(Str
.toStringz(s
), slen
, Str
.toStringz(format
), (date
is null) ?
null : date
.getDateStruct());
835 * Fills in the date-related bits of a struct tm
836 * using the date value. Initializes the non-date parts with something
837 * sane but meaningless.
839 * a GDate to set the struct tm from.
843 public void toStructTm(void* tm
)
845 // void g_date_to_struct_tm (const GDate *date, struct tm *tm);
846 g_date_to_struct_tm(gDate
, tm
);
850 * Returns TRUE if the GDate represents an existing day. The date must not
851 * contain garbage; it should have been initialized with g_date_clear()
852 * if it wasn't allocated by one of the g_date_new() variants.
856 * Whether the date is valid.
860 // gboolean g_date_valid (const GDate *date);
861 return g_date_valid(gDate
);
865 * Returns TRUE if the day of the month is valid (a day is valid if it's
866 * between 1 and 31 inclusive).
870 * TRUE if the day is valid.
872 public static int validDay(GDateDay day
)
874 // gboolean g_date_valid_day (GDateDay day);
875 return g_date_valid_day(day
);
879 * Returns TRUE if the month value is valid. The 12 GDateMonth
880 * enumeration values are the only valid months.
884 * TRUE if the month is valid.
886 public static int validMonth(GDateMonth month
)
888 // gboolean g_date_valid_month (GDateMonth month);
889 return g_date_valid_month(month
);
893 * Returns TRUE if the year is valid. Any year greater than 0 is valid,
894 * though there is a 16-bit limit to what GDate will understand.
898 * TRUE if the year is valid.
900 public static int validYear(GDateYear year
)
902 // gboolean g_date_valid_year (GDateYear year);
903 return g_date_valid_year(year
);
907 * Returns TRUE if the day-month-year triplet forms a valid, existing day
908 * in the range of days GDate understands (Year 1 or later, no more than
909 * a few thousand years in the future).
917 * TRUE if the date is a valid one.
919 public static int validDmy(GDateDay day
, GDateMonth month
, GDateYear year
)
921 // gboolean g_date_valid_dmy (GDateDay day, GDateMonth month, GDateYear year);
922 return g_date_valid_dmy(day
, month
, year
);
926 * Returns TRUE if the Julian day is valid. Anything greater than zero is basically a
927 * valid Julian, though there is a 32-bit limit.
929 * Julian day to check.
931 * TRUE if the Julian day is valid.
933 public static int validJulian(uint julianDate
)
935 // gboolean g_date_valid_julian (guint32 julian_date);
936 return g_date_valid_julian(julianDate
);
940 * Returns TRUE if the weekday is valid. The 7 GDateWeekday enumeration
941 * values are the only valid weekdays.
945 * TRUE if the weekday is valid.
947 public static int validWeekday(GDateWeekday weekday
)
949 // gboolean g_date_valid_weekday (GDateWeekday weekday);
950 return g_date_valid_weekday(weekday
);