1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
30 GDate *d = g_new0 (GDate, 1); /* happily, 0 is the invalid flag for everything. */
36 g_date_new_dmy (GDateDay day, GDateMonth m, GDateYear y)
39 g_return_val_if_fail (g_date_valid_dmy (day, m, y), NULL);
50 g_assert (g_date_valid (d));
56 g_date_new_julian (guint32 j)
59 g_return_val_if_fail (g_date_valid_julian (j), NULL);
68 g_assert (g_date_valid (d));
74 g_date_free (GDate *d)
76 g_return_if_fail (d != NULL);
82 g_date_valid (GDate *d)
84 g_return_val_if_fail (d != NULL, FALSE);
86 return (d->julian || d->dmy);
89 static const guint8 days_in_months[2][13] =
90 { /* error, jan feb mar apr may jun jul aug sep oct nov dec */
91 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
92 { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } /* leap year */
95 static const guint16 days_in_year[2][14] =
96 { /* 0, jan feb mar apr may jun jul aug sep oct nov dec */
97 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
98 { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
102 g_date_valid_month (GDateMonth m)
104 return ( (m > G_DATE_BAD_MONTH) && (m < 13) );
108 g_date_valid_year (GDateYear y)
110 return ( y > G_DATE_BAD_YEAR );
114 g_date_valid_day (GDateDay d)
116 return ( (d > G_DATE_BAD_DAY) && (d < 32) );
120 g_date_valid_weekday (GDateWeekday w)
122 return ( (w > G_DATE_BAD_WEEKDAY) && (w < 8) );
126 g_date_valid_julian (guint32 j)
128 return (j > G_DATE_BAD_JULIAN);
132 g_date_valid_dmy (GDateDay d,
136 return ( (m > G_DATE_BAD_MONTH) &&
138 (d > G_DATE_BAD_DAY) &&
139 (y > G_DATE_BAD_YEAR) && /* must check before using g_date_is_leap_year */
140 (d <= (g_date_is_leap_year (y) ?
141 days_in_months[1][m] : days_in_months[0][m])) );
145 /* "Julian days" just means an absolute number of days, where Day 1 ==
149 g_date_update_julian (GDate *d)
154 g_return_if_fail (d != NULL);
155 g_return_if_fail (d->dmy);
156 g_return_if_fail (!d->julian);
157 g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
159 /* What we actually do is: multiply years * 365 days in the year,
160 * add the number of years divided by 4, subtract the number of
161 * years divided by 100 and add the number of years divided by 400,
162 * which accounts for leap year stuff. Code from Steffen Beyer's
166 year = d->year - 1; /* we know d->year > 0 since it's valid */
168 d->julian_days = year * 365U;
169 d->julian_days += (year >>= 2); /* divide by 4 and add */
170 d->julian_days -= (year /= 25); /* divides original # years by 100 */
171 d->julian_days += year >> 2; /* divides by 4, which divides original by 400 */
173 index = g_date_is_leap_year (d->year) ? 1 : 0;
175 d->julian_days += days_in_year[index][d->month] + d->day;
177 g_return_if_fail (g_date_valid_julian (d->julian_days));
183 g_date_update_dmy (GDate *d)
189 guint32 A, B, C, D, E, M;
191 g_return_if_fail (d != NULL);
192 g_return_if_fail (d->julian);
193 g_return_if_fail (!d->dmy);
194 g_return_if_fail (g_date_valid_julian (d->julian_days));
196 /* Formula taken from the Calendar FAQ; the formula was for the
197 * Julian Period which starts on 1 January 4713 BC, so we add
198 * 1,721,425 to the number of days before doing the formula.
200 * I'm sure this can be simplified for our 1 January 1 AD period
201 * start, but I can't figure out how to unpack the formula.
204 A = d->julian_days + 1721425 + 32045;
205 B = ( 4 *(A + 36524) )/ 146097 - 1;
206 C = A - (146097 * B)/4;
207 D = ( 4 * (C + 365) ) / 1461 - 1;
208 E = C - ((1461*D) / 4);
209 M = (5 * (E - 1) + 2)/153;
211 m = M + 3 - (12*(M/10));
212 day = E - (153*M + 2)/5;
213 y = 100 * B + D - 4800 + (M/10);
215 #ifdef G_ENABLE_DEBUG
216 if (!g_date_valid_dmy (day, m, y))
218 g_warning ("\nOOPS julian: %u computed dmy: %u %u %u\n",
219 d->julian_days, day, m, y);
231 g_date_weekday (GDate *d)
233 g_return_val_if_fail (d != NULL, G_DATE_BAD_WEEKDAY);
234 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_WEEKDAY);
238 g_date_update_julian (d);
240 g_return_val_if_fail (d->julian, G_DATE_BAD_WEEKDAY);
242 return ((d->julian_days - 1) % 7) + 1;
246 g_date_month (GDate *d)
248 g_return_val_if_fail (d != NULL, G_DATE_BAD_MONTH);
249 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_MONTH);
253 g_date_update_dmy (d);
255 g_return_val_if_fail (d->dmy, G_DATE_BAD_MONTH);
261 g_date_year (GDate *d)
263 g_return_val_if_fail (d != NULL, G_DATE_BAD_YEAR);
264 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_YEAR);
268 g_date_update_dmy (d);
270 g_return_val_if_fail (d->dmy, G_DATE_BAD_YEAR);
276 g_date_day (GDate *d)
278 g_return_val_if_fail (d != NULL, G_DATE_BAD_DAY);
279 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_DAY);
283 g_date_update_dmy (d);
285 g_return_val_if_fail (d->dmy, G_DATE_BAD_DAY);
291 g_date_julian (GDate *d)
293 g_return_val_if_fail (d != NULL, G_DATE_BAD_JULIAN);
294 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_JULIAN);
298 g_date_update_julian (d);
300 g_return_val_if_fail (d->julian, G_DATE_BAD_JULIAN);
302 return d->julian_days;
306 g_date_day_of_year (GDate *d)
310 g_return_val_if_fail (d != NULL, 0);
311 g_return_val_if_fail (g_date_valid (d), 0);
315 g_date_update_dmy (d);
317 g_return_val_if_fail (d->dmy, 0);
319 index = g_date_is_leap_year (d->year) ? 1 : 0;
321 return (days_in_year[index][d->month] + d->day);
325 g_date_monday_week_of_year (GDate *d)
331 g_return_val_if_fail (d != NULL, 0);
332 g_return_val_if_fail (g_date_valid (d), 0);
336 g_date_update_dmy (d);
338 g_return_val_if_fail (d->dmy, 0);
340 g_date_clear (&first, 1);
342 g_date_set_dmy (&first, 1, 1, d->year);
344 wd = g_date_weekday (&first) - 1; /* make Monday day 0 */
345 day = g_date_day_of_year (d) - 1;
347 return ((day + wd)/7U + (wd == 0 ? 1 : 0));
351 g_date_sunday_week_of_year (GDate *d)
357 g_return_val_if_fail (d != NULL, 0);
358 g_return_val_if_fail (g_date_valid (d), 0);
362 g_date_update_dmy (d);
364 g_return_val_if_fail (d->dmy, 0);
366 g_date_clear (&first, 1);
368 g_date_set_dmy (&first, 1, 1, d->year);
370 wd = g_date_weekday (&first);
371 if (wd == 7) wd = 0; /* make Sunday day 0 */
372 day = g_date_day_of_year (d) - 1;
374 return ((day + wd)/7U + (wd == 0 ? 1 : 0));
378 g_date_clear (GDate *d, guint ndates)
380 g_return_if_fail (d != NULL);
381 g_return_if_fail (ndates != 0);
383 memset (d, 0x0, ndates*sizeof (GDate));
386 /* These are for the parser, output to the user should use *
387 * g_date_strftime () - this creates more never-freed memory to annoy
388 * all those memory debugger users. :-)
391 static gchar *long_month_names[13] =
393 "Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
396 static gchar *short_month_names[13] =
398 "Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
401 /* This tells us if we need to update the parse info */
402 static gchar *current_locale = NULL;
404 /* order of these in the current locale */
405 static GDateDMY dmy_order[3] =
407 G_DATE_DAY, G_DATE_MONTH, G_DATE_YEAR
410 /* Where to chop two-digit years: i.e., for the 1930 default, numbers
411 * 29 and below are counted as in the year 2000, numbers 30 and above
412 * are counted as in the year 1900.
415 static GDateYear twodigit_start_year = 1930;
417 /* It is impossible to enter a year between 1 AD and 99 AD with this
420 static gboolean using_twodigit_years = FALSE;
422 struct _GDateParseTokens {
428 typedef struct _GDateParseTokens GDateParseTokens;
433 g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
435 gchar num[4][NUM_LEN+1];
439 /* We count 4, but store 3; so we can give an error
442 num[0][0] = num[1][0] = num[2][0] = num[3][0] = '\0';
446 while (*s && pt->num_ints < 4)
450 while (*s && isdigit (*s) && i <= NUM_LEN)
452 num[pt->num_ints][i] = *s;
459 num[pt->num_ints][i] = '\0';
463 if (*s == '\0') break;
468 pt->n[0] = pt->num_ints > 0 ? atoi (num[0]) : 0;
469 pt->n[1] = pt->num_ints > 1 ? atoi (num[1]) : 0;
470 pt->n[2] = pt->num_ints > 2 ? atoi (num[2]) : 0;
472 pt->month = G_DATE_BAD_MONTH;
474 if (pt->num_ints < 3)
479 strncpy (lcstr, str, 127);
484 if (long_month_names[i] != NULL)
486 const gchar *found = strstr (lcstr, long_month_names[i]);
495 if (short_month_names[i] != NULL)
497 const gchar *found = strstr (lcstr, short_month_names[i]);
512 g_date_prepare_to_parse (const gchar *str, GDateParseTokens *pt)
514 const gchar *locale = setlocale (LC_TIME, NULL);
515 gboolean recompute_localeinfo = FALSE;
518 g_return_if_fail (locale != NULL); /* should not happen */
520 g_date_clear (&d, 1); /* clear for scratch use */
522 if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) )
524 recompute_localeinfo = TRUE; /* Uh, there used to be a reason for the temporary */
527 if (recompute_localeinfo)
530 GDateParseTokens testpt;
533 g_free (current_locale); /* still works if current_locale == NULL */
535 current_locale = g_strdup (locale);
539 g_date_set_dmy (&d, 1, i, 1);
541 g_return_if_fail (g_date_valid (&d));
543 g_date_strftime (buf, 127, "%b", &d);
544 g_free (short_month_names[i]);
546 short_month_names[i] = g_strdup (buf);
550 g_date_strftime (buf, 127, "%B", &d);
551 g_free (long_month_names[i]);
553 long_month_names[i] = g_strdup (buf);
558 /* Determine DMY order */
560 g_date_set_dmy (&d, 4, 7, 1776); /* had to pick a random day */
562 g_date_strftime (buf, 127, "%x", &d);
564 g_date_fill_parse_tokens (buf, &testpt);
567 while (i < testpt.num_ints)
572 dmy_order[i] = G_DATE_MONTH;
575 dmy_order[i] = G_DATE_DAY;
578 using_twodigit_years = TRUE; /* FALL THRU */
580 dmy_order[i] = G_DATE_YEAR;
583 /* leave it unchanged */
589 #ifdef G_ENABLE_DEBUG
590 g_message ("**GDate prepared a new set of locale-specific parse rules.");
594 g_message (" %s %s", long_month_names[i], short_month_names[i]);
597 if (using_twodigit_years)
599 g_message ("**Using twodigit years with cutoff year: %u", twodigit_start_year);
606 switch (dmy_order[i])
609 strings[i] = "Month";
623 g_message ("**Order: %s, %s, %s", strings[0], strings[1], strings[2]);
624 g_message ("**Sample date in this locale: `%s'", buf);
629 g_date_fill_parse_tokens (str, pt);
633 g_date_set_parse (GDate *d,
637 guint m = G_DATE_BAD_MONTH, day = G_DATE_BAD_DAY, y = G_DATE_BAD_YEAR;
639 g_return_if_fail (d != NULL);
644 g_date_prepare_to_parse (str, &pt);
646 #ifdef G_ENABLE_DEBUG
647 g_message ("Found %d ints, `%d' `%d' `%d' and written out month %d",
648 pt.num_ints, pt.n[0], pt.n[1], pt.n[2], pt.month);
652 if (pt.num_ints == 4) return; /* presumably a typo; bail out. */
659 g_assert (pt.num_ints < 4); /* i.e., it is 2 or 3 */
661 while (i < pt.num_ints && j < 3)
663 switch (dmy_order[j])
667 if (pt.num_ints == 2 && pt.month != G_DATE_BAD_MONTH)
670 ++j; /* skip months, but don't skip this number */
679 if (pt.num_ints == 2 && pt.month == G_DATE_BAD_MONTH)
682 ++j; /* skip days, since we may have month/year */
692 if (using_twodigit_years && y < 100)
694 guint two = twodigit_start_year % 100;
695 guint century = (twodigit_start_year / 100) * 100;
713 if (pt.num_ints == 3 && !g_date_valid_dmy (day, m, y))
720 if (using_twodigit_years && y < 100)
721 y = G_DATE_BAD_YEAR; /* avoids ambiguity */
724 else if (pt.num_ints == 1)
726 if (pt.month != G_DATE_BAD_MONTH)
728 /* Month name and year? */
735 /* Try yyyymmdd and yymmdd */
737 m = (pt.n[0]/100) % 100;
741 /* FIXME move this into a separate function */
742 if (using_twodigit_years && y < 100)
744 guint two = twodigit_start_year % 100;
745 guint century = (twodigit_start_year / 100) * 100;
755 /* See if we got anything valid out of all this. */
756 /* y < 8000 is to catch 19998 style typos; the library is OK up to 65535 or so */
757 if (y < 8000 && g_date_valid_dmy (day, m, y))
764 #ifdef G_ENABLE_DEBUG
766 g_message ("Rejected DMY %u %u %u", day, m, y);
771 g_date_set_time (GDate *d,
777 g_return_if_fail (d != NULL);
785 d->month = tm->tm_mon + 1;
786 d->day = tm->tm_mday;
787 d->year = tm->tm_year + 1900;
789 g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
800 g_date_set_month (GDate *d,
803 g_return_if_fail (d != NULL);
804 g_return_if_fail (g_date_valid_month (m));
806 if (d->julian && !d->dmy) g_date_update_dmy(d);
811 if (g_date_valid_dmy (d->day, d->month, d->year))
818 g_date_set_day (GDate *d,
821 g_return_if_fail (d != NULL);
822 g_return_if_fail (g_date_valid_day (day));
824 if (d->julian && !d->dmy) g_date_update_dmy(d);
829 if (g_date_valid_dmy (d->day, d->month, d->year))
836 g_date_set_year (GDate *d,
839 g_return_if_fail (d != NULL);
840 g_return_if_fail (g_date_valid_year (y));
842 if (d->julian && !d->dmy) g_date_update_dmy(d);
847 if (g_date_valid_dmy (d->day, d->month, d->year))
854 g_date_set_dmy (GDate *d,
859 g_return_if_fail (d != NULL);
860 g_return_if_fail (g_date_valid_dmy (day, m, y));
872 g_date_set_julian (GDate *d, guint32 j)
874 g_return_if_fail (d != NULL);
875 g_return_if_fail (g_date_valid_julian (j));
884 g_date_is_first_of_month (GDate *d)
886 g_return_val_if_fail (d != NULL, FALSE);
887 g_return_val_if_fail (g_date_valid (d), FALSE);
891 g_date_update_dmy (d);
893 g_return_val_if_fail (d->dmy, FALSE);
895 if (d->day == 1) return TRUE;
900 g_date_is_last_of_month (GDate *d)
904 g_return_val_if_fail (d != NULL, FALSE);
905 g_return_val_if_fail (g_date_valid (d), FALSE);
909 g_date_update_dmy (d);
911 g_return_val_if_fail (d->dmy, FALSE);
913 index = g_date_is_leap_year (d->year) ? 1 : 0;
915 if (d->day == days_in_months[index][d->month]) return TRUE;
920 g_date_add_days (GDate *d, guint ndays)
922 g_return_if_fail (d != NULL);
923 g_return_if_fail (g_date_valid (d));
927 g_date_update_julian (d);
929 g_return_if_fail (d->julian);
931 d->julian_days += ndays;
936 g_date_subtract_days (GDate *d, guint ndays)
938 g_return_if_fail (d != NULL);
939 g_return_if_fail (g_date_valid (d));
943 g_date_update_julian (d);
945 g_return_if_fail (d->julian);
946 g_return_if_fail (d->julian_days > ndays);
948 d->julian_days -= ndays;
953 g_date_add_months (GDate *d,
959 g_return_if_fail (d != NULL);
960 g_return_if_fail (g_date_valid (d));
964 g_date_update_dmy (d);
966 g_return_if_fail (d->dmy);
968 nmonths += d->month - 1;
973 d->month = months + 1;
976 index = g_date_is_leap_year (d->year) ? 1 : 0;
978 if (d->day > days_in_months[index][d->month])
979 d->day = days_in_months[index][d->month];
983 g_return_if_fail (g_date_valid (d));
987 g_date_subtract_months (GDate *d,
993 g_return_if_fail (d != NULL);
994 g_return_if_fail (g_date_valid (d));
998 g_date_update_dmy (d);
1000 g_return_if_fail (d->dmy);
1003 months = nmonths%12;
1005 g_return_if_fail (d->year > years);
1009 if (d->month > months) d->month -= months;
1013 d->month = 12 - months;
1017 index = g_date_is_leap_year (d->year) ? 1 : 0;
1019 if (d->day > days_in_months[index][d->month])
1020 d->day = days_in_months[index][d->month];
1024 g_return_if_fail (g_date_valid (d));
1028 g_date_add_years (GDate *d,
1031 g_return_if_fail (d != NULL);
1032 g_return_if_fail (g_date_valid (d));
1036 g_date_update_dmy (d);
1038 g_return_if_fail (d->dmy);
1042 if (d->month == 2 && d->day == 29)
1044 if (!g_date_is_leap_year (d->year))
1054 g_date_subtract_years (GDate *d,
1057 g_return_if_fail (d != NULL);
1058 g_return_if_fail (g_date_valid (d));
1062 g_date_update_dmy (d);
1064 g_return_if_fail (d->dmy);
1065 g_return_if_fail (d->year > nyears);
1069 if (d->month == 2 && d->day == 29)
1071 if (!g_date_is_leap_year (d->year))
1082 g_date_is_leap_year (GDateYear year)
1084 g_return_val_if_fail (g_date_valid_year (year), FALSE);
1086 return ( (((year % 4) == 0) && ((year % 100) != 0)) ||
1087 (year % 400) == 0 );
1091 g_date_days_in_month (GDateMonth month,
1096 g_return_val_if_fail (g_date_valid_year (year), 0);
1097 g_return_val_if_fail (g_date_valid_month (month), 0);
1099 index = g_date_is_leap_year (year) ? 1 : 0;
1101 return days_in_months[index][month];
1105 g_date_monday_weeks_in_year (GDateYear year)
1109 g_return_val_if_fail (g_date_valid_year (year), 0);
1111 g_date_clear (&d, 1);
1112 g_date_set_dmy (&d, 1, 1, year);
1113 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1114 g_date_set_dmy (&d, 31, 12, year);
1115 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1116 if (g_date_is_leap_year (year))
1118 g_date_set_dmy (&d, 2, 1, year);
1119 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1120 g_date_set_dmy (&d, 30, 12, year);
1121 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1127 g_date_sunday_weeks_in_year (GDateYear year)
1131 g_return_val_if_fail (g_date_valid_year (year), 0);
1133 g_date_clear (&d, 1);
1134 g_date_set_dmy (&d, 1, 1, year);
1135 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1136 g_date_set_dmy (&d, 31, 12, year);
1137 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1138 if (g_date_is_leap_year (year))
1140 g_date_set_dmy (&d, 2, 1, year);
1141 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1142 g_date_set_dmy (&d, 30, 12, year);
1143 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1149 g_date_compare (GDate *lhs,
1152 g_return_val_if_fail (lhs != NULL, 0);
1153 g_return_val_if_fail (rhs != NULL, 0);
1154 g_return_val_if_fail (g_date_valid (lhs), 0);
1155 g_return_val_if_fail (g_date_valid (rhs), 0);
1157 /* Remember the self-comparison case! I think it works right now. */
1162 if (lhs->julian && rhs->julian)
1164 if (lhs->julian_days < rhs->julian_days) return -1;
1165 else if (lhs->julian_days > rhs->julian_days) return 1;
1168 else if (lhs->dmy && rhs->dmy)
1170 if (lhs->year < rhs->year) return -1;
1171 else if (lhs->year > rhs->year) return 1;
1174 if (lhs->month < rhs->month) return -1;
1175 else if (lhs->month > rhs->month) return 1;
1178 if (lhs->day < rhs->day) return -1;
1179 else if (lhs->day > rhs->day) return 1;
1188 if (!lhs->julian) g_date_update_julian (lhs);
1189 if (!rhs->julian) g_date_update_julian (rhs);
1190 g_return_val_if_fail (lhs->julian, 0);
1191 g_return_val_if_fail (rhs->julian, 0);
1195 return 0; /* warnings */
1200 g_date_to_struct_tm (GDate *d,
1205 g_return_if_fail (d != NULL);
1206 g_return_if_fail (g_date_valid (d));
1207 g_return_if_fail (tm != NULL);
1211 g_date_update_dmy (d);
1213 g_return_if_fail (d->dmy);
1215 /* zero all the irrelevant fields to be sure they're valid */
1217 /* On Linux and maybe other systems, there are weird non-POSIX
1218 * fields on the end of struct tm that choke strftime if they
1219 * contain garbage. So we need to 0 the entire struct, not just the
1220 * fields we know to exist.
1223 memset (tm, 0x0, sizeof (struct tm));
1225 tm->tm_mday = d->day;
1226 tm->tm_mon = d->month - 1; /* 0-11 goes in tm */
1227 tm->tm_year = ((int)d->year) - 1900; /* X/Open says tm_year can be negative */
1229 day = g_date_weekday (d);
1230 if (day == 7) day = 0; /* struct tm wants days since Sunday, so Sunday is 0 */
1232 tm->tm_wday = (int)day;
1234 tm->tm_yday = g_date_day_of_year (d) - 1; /* 0 to 365 */
1235 tm->tm_isdst = -1; /* -1 means "information not available" */
1239 g_date_strftime (gchar *s,
1241 const gchar *format,
1247 g_return_val_if_fail (d != NULL, 0);
1248 g_return_val_if_fail (g_date_valid (d), 0);
1249 g_return_val_if_fail (slen > 0, 0);
1250 g_return_val_if_fail (format != 0, 0);
1251 g_return_val_if_fail (s != 0, 0);
1253 g_date_to_struct_tm (d, &tm);
1255 retval = strftime (s, slen, format, &tm);
1258 /* If retval == 0, the contents of s are undefined. We define