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_mdy (GDateMonth m, GDateDay day, GDateYear y)
39 g_return_val_if_fail (g_date_valid_mdy (m, day, 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);
84 g_date_valid (GDate *d)
86 g_return_val_if_fail (d != NULL, FALSE);
88 if (d->julian && d->mdy)
90 return ( g_date_valid_julian (d->julian_days) &&
91 g_date_valid_mdy (d->month, d->day, d->year) );
96 return g_date_valid_mdy (d->month, d->day, d->year);
100 return g_date_valid_julian (d->julian_days);
106 static const guint8 days_in_months[2][13] =
107 { /* error, jan feb mar apr may jun jul aug sep oct nov dec */
108 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
109 { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } /* leap year */
112 static const guint16 days_in_year[2][14] =
113 { /* 0, jan feb mar apr may jun jul aug sep oct nov dec */
114 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
115 { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
119 g_date_valid_month (GDateMonth m)
121 return ( (m > G_DATE_BAD_MONTH) && (m < 13) );
125 g_date_valid_year (GDateYear y)
127 return ( y > G_DATE_BAD_YEAR );
131 g_date_valid_day (GDateDay d)
133 return ( (d > G_DATE_BAD_DAY) && (d < 32) );
137 g_date_valid_weekday (GDateWeekday w)
139 return ( (w > G_DATE_BAD_WEEKDAY) && (w < 8) );
143 g_date_valid_julian (guint32 j)
145 return (j > G_DATE_BAD_JULIAN);
149 g_date_valid_mdy (GDateMonth m,
153 return ( (m > G_DATE_BAD_MONTH) &&
155 (d > G_DATE_BAD_DAY) &&
156 (y > G_DATE_BAD_YEAR) && /* must check before using g_date_is_leap_year */
157 (d <= (g_date_is_leap_year (y) ?
158 days_in_months[1][m] : days_in_months[0][m])) );
162 /* "Julian days" just means an absolute number of days, where Day 1 ==
166 g_date_update_julian (GDate *d)
171 g_return_if_fail (d != NULL);
172 g_return_if_fail (d->mdy);
173 g_return_if_fail (!d->julian);
174 g_return_if_fail (g_date_valid_mdy (d->month, d->day, d->year));
176 /* What we actually do is: multiply years * 365 days in the year,
177 * add the number of years divided by 4, subtract the number of
178 * years divided by 100 and add the number of years divided by 400,
179 * which accounts for leap year stuff. Code from Steffen Beyer's
183 year = d->year - 1; /* we know d->year > 0 since it's valid */
185 d->julian_days = year * 365U;
186 d->julian_days += (year >>= 2); /* divide by 4 and add */
187 d->julian_days -= (year /= 25); /* divides original # years by 100 */
188 d->julian_days += year >> 2; /* divides by 4, which divides original by 400 */
190 index = g_date_is_leap_year (d->year) ? 1 : 0;
192 d->julian_days += days_in_year[index][d->month] + d->day;
194 g_return_if_fail (g_date_valid_julian (d->julian_days));
200 g_date_update_mdy (GDate *d)
206 guint32 A, B, C, D, E, M;
208 g_return_if_fail (d != NULL);
209 g_return_if_fail (d->julian);
210 g_return_if_fail (!d->mdy);
211 g_return_if_fail (g_date_valid_julian (d->julian_days));
213 /* Formula taken from the Calendar FAQ; the formula was for the
214 * Julian Period which starts on 1 January 4713 BC, so we add
215 * 1,721,425 to the number of days before doing the formula.
217 * I'm sure this can be simplified for our 1 January 1 AD period
218 * start, but I can't figure out how to unpack the formula.
221 A = d->julian_days + 1721425 + 32045;
222 B = ( 4 *(A + 36524) )/ 146097 - 1;
223 C = A - (146097 * B)/4;
224 D = ( 4 * (C + 365) ) / 1461 - 1;
225 E = C - ((1461*D) / 4);
226 M = (5 * (E - 1) + 2)/153;
228 m = M + 3 - (12*(M/10));
229 day = E - (153*M + 2)/5;
230 y = 100 * B + D - 4800 + (M/10);
232 #ifdef G_ENABLE_DEBUG
233 if (!g_date_valid_mdy (m, day, y))
235 g_warning ("\nOOPS julian: %u computed mdy: %u %u %u\n",
236 d->julian_days, m, day, y);
248 g_date_weekday (GDate *d)
250 g_return_val_if_fail (d != NULL, G_DATE_BAD_WEEKDAY);
251 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_WEEKDAY);
255 g_date_update_julian (d);
257 g_return_val_if_fail (d->julian, G_DATE_BAD_WEEKDAY);
259 return ((d->julian_days - 1) % 7) + 1;
263 g_date_month (GDate *d)
265 g_return_val_if_fail (d != NULL, G_DATE_BAD_MONTH);
266 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_MONTH);
270 g_date_update_mdy (d);
272 g_return_val_if_fail (d->mdy, G_DATE_BAD_MONTH);
278 g_date_year (GDate *d)
280 g_return_val_if_fail (d != NULL, G_DATE_BAD_YEAR);
281 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_YEAR);
285 g_date_update_mdy (d);
287 g_return_val_if_fail (d->mdy, G_DATE_BAD_YEAR);
293 g_date_day (GDate *d)
295 g_return_val_if_fail (d != NULL, G_DATE_BAD_DAY);
296 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_DAY);
300 g_date_update_mdy (d);
302 g_return_val_if_fail (d->mdy, G_DATE_BAD_DAY);
308 g_date_julian (GDate *d)
310 g_return_val_if_fail (d != NULL, G_DATE_BAD_JULIAN);
311 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_JULIAN);
315 g_date_update_julian (d);
317 g_return_val_if_fail (d->julian, G_DATE_BAD_JULIAN);
319 return d->julian_days;
323 g_date_day_of_year (GDate *d)
327 g_return_val_if_fail (d != NULL, 0);
328 g_return_val_if_fail (g_date_valid (d), 0);
332 g_date_update_mdy (d);
334 g_return_val_if_fail (d->mdy, 0);
336 index = g_date_is_leap_year (d->year) ? 1 : 0;
338 return (days_in_year[index][d->month] + d->day);
342 g_date_monday_week_of_year (GDate *d)
348 g_return_val_if_fail (d != NULL, 0);
349 g_return_val_if_fail (g_date_valid (d), 0);
353 g_date_update_mdy (d);
355 g_return_val_if_fail (d->mdy, 0);
357 g_date_clear (&first, 1);
359 g_date_set_mdy (&first, 1, 1, d->year);
361 wd = g_date_weekday (&first) - 1; /* make Monday day 0 */
362 day = g_date_day_of_year (d) - 1;
364 return ((day + wd)/7U + (wd == 0 ? 1 : 0));
368 g_date_sunday_week_of_year (GDate *d)
374 g_return_val_if_fail (d != NULL, 0);
375 g_return_val_if_fail (g_date_valid (d), 0);
379 g_date_update_mdy (d);
381 g_return_val_if_fail (d->mdy, 0);
383 g_date_clear (&first, 1);
385 g_date_set_mdy (&first, 1, 1, d->year);
387 wd = g_date_weekday (&first);
388 if (wd == 7) wd = 0; /* make Sunday day 0 */
389 day = g_date_day_of_year (d) - 1;
391 return ((day + wd)/7U + (wd == 0 ? 1 : 0));
395 g_date_clear (GDate *d, guint ndates)
397 g_return_if_fail (d != NULL);
398 g_return_if_fail (ndates != 0);
400 memset (d, 0x0, ndates*sizeof (GDate));
403 /* These are for the parser, output to the user should use *
404 * g_date_strftime () - this creates more never-freed memory to annoy
405 * all those memory debugger users. :-)
408 static gchar *long_month_names[13] =
410 "Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
413 static gchar *short_month_names[13] =
415 "Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
418 /* This tells us if we need to update the parse info */
419 static gchar *current_locale = NULL;
421 /* order of these in the current locale */
422 static GDateMDY mdy_order[3] =
424 G_DATE_MONTH, G_DATE_DAY, G_DATE_YEAR
427 /* Where to chop two-digit years: i.e., for the 1930 default, numbers
428 * 29 and below are counted as in the year 2000, numbers 30 and above
429 * are counted as in the year 1900.
432 static GDateYear twodigit_start_year = 1930;
434 /* It is impossible to enter a year between 1 AD and 99 AD with this
437 static gboolean using_twodigit_years = FALSE;
439 struct _GDateParseTokens {
445 typedef struct _GDateParseTokens GDateParseTokens;
450 g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
452 gchar num[4][NUM_LEN+1];
456 /* We count 4, but store 3; so we can give an error
459 num[0][0] = num[1][0] = num[2][0] = num[3][0] = '\0';
463 while (*s && pt->num_ints < 4)
467 while (*s && isdigit (*s) && i <= NUM_LEN)
469 num[pt->num_ints][i] = *s;
476 num[pt->num_ints][i] = '\0';
480 if (*s == '\0') break;
485 pt->n[0] = pt->num_ints > 0 ? atoi (num[0]) : 0;
486 pt->n[1] = pt->num_ints > 1 ? atoi (num[1]) : 0;
487 pt->n[2] = pt->num_ints > 2 ? atoi (num[2]) : 0;
489 pt->month = G_DATE_BAD_MONTH;
491 if (pt->num_ints < 3)
496 strncpy (lcstr, str, 127);
501 if (long_month_names[i] != NULL)
503 const gchar *found = strstr (lcstr, long_month_names[i]);
512 if (short_month_names[i] != NULL)
514 const gchar *found = strstr (lcstr, short_month_names[i]);
529 g_date_prepare_to_parse (const gchar *str, GDateParseTokens *pt)
531 const gchar *locale = setlocale (LC_TIME, NULL);
532 gboolean recompute_localeinfo = FALSE;
535 g_return_if_fail (locale != NULL); /* should not happen */
537 g_date_clear (&d, 1); /* clear for scratch use */
539 if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) )
541 recompute_localeinfo = TRUE; /* Uh, there used to be a reason for the temporary */
544 if (recompute_localeinfo)
547 GDateParseTokens testpt;
550 g_free (current_locale); /* still works if current_locale == NULL */
552 current_locale = g_strdup (locale);
556 g_date_set_mdy (&d, i, 1, 1);
558 g_return_if_fail (g_date_valid (&d));
560 g_date_strftime (buf, 127, "%b", &d);
561 g_free (short_month_names[i]);
563 short_month_names[i] = g_strdup (buf);
567 g_date_strftime (buf, 127, "%B", &d);
568 g_free (long_month_names[i]);
570 long_month_names[i] = g_strdup (buf);
575 /* Determine MDY order */
577 g_date_set_mdy (&d, 7, 4, 1776); /* had to pick a random day */
579 g_date_strftime (buf, 127, "%x", &d);
581 g_date_fill_parse_tokens (buf, &testpt);
584 while (i < testpt.num_ints)
589 mdy_order[i] = G_DATE_MONTH;
592 mdy_order[i] = G_DATE_DAY;
595 using_twodigit_years = TRUE; /* FALL THRU */
597 mdy_order[i] = G_DATE_YEAR;
600 /* leave it unchanged */
606 #ifdef G_ENABLE_DEBUG
607 g_message ("**GDate prepared a new set of locale-specific parse rules.");
611 g_message (" %s %s", long_month_names[i], short_month_names[i]);
614 if (using_twodigit_years)
616 g_message ("**Using twodigit years with cutoff year: %u", twodigit_start_year);
623 switch (mdy_order[i])
626 strings[i] = "Month";
640 g_message ("**Order: %s, %s, %s", strings[0], strings[1], strings[2]);
641 g_message ("**Sample date in this locale: `%s'", buf);
646 g_date_fill_parse_tokens (str, pt);
650 g_date_set_parse (GDate *d,
654 guint m = G_DATE_BAD_MONTH, day = G_DATE_BAD_DAY, y = G_DATE_BAD_YEAR;
656 g_return_if_fail (d != NULL);
661 g_date_prepare_to_parse (str, &pt);
663 #ifdef G_ENABLE_DEBUG
664 g_message ("Found %d ints, `%d' `%d' `%d' and written out month %d",
665 pt.num_ints, pt.n[0], pt.n[1], pt.n[2], pt.month);
669 if (pt.num_ints == 4) return; /* presumably a typo; bail out. */
676 g_assert (pt.num_ints < 4); /* i.e., it is 2 or 3 */
678 while (i < pt.num_ints && j < 3)
680 switch (mdy_order[j])
684 if (pt.num_ints == 2 && pt.month != G_DATE_BAD_MONTH)
687 ++j; /* skip months, but don't skip this number */
696 if (pt.num_ints == 2 && pt.month == G_DATE_BAD_MONTH)
699 ++j; /* skip days, since we may have month/year */
709 if (using_twodigit_years && y < 100)
711 guint two = twodigit_start_year % 100;
712 guint century = (twodigit_start_year / 100) * 100;
730 if (pt.num_ints == 3 && !g_date_valid_mdy (m, day, y))
737 if (using_twodigit_years && y < 100)
738 y = G_DATE_BAD_YEAR; /* avoids ambiguity */
741 else if (pt.num_ints == 1)
743 if (pt.month != G_DATE_BAD_MONTH)
745 /* Month name and year? */
752 /* Try yyyymmdd and yymmdd */
754 m = (pt.n[0]/100) % 100;
758 /* FIXME move this into a separate function */
759 if (using_twodigit_years && y < 100)
761 guint two = twodigit_start_year % 100;
762 guint century = (twodigit_start_year / 100) * 100;
772 /* See if we got anything valid out of all this. */
773 /* y < 8000 is to catch 19998 style typos; the library is OK up to 65535 or so */
774 if (y < 8000 && g_date_valid_mdy (m, day, y))
781 #ifdef G_ENABLE_DEBUG
783 g_message ("Rejected MDY %u %u %u", m, day, y);
788 g_date_set_time (GDate *d,
794 g_return_if_fail (d != NULL);
802 d->month = tm->tm_mon + 1;
803 d->day = tm->tm_mday;
804 d->year = tm->tm_year + 1900;
806 g_return_if_fail (g_date_valid_mdy (d->month, d->day, d->year));
817 g_date_set_month (GDate *d,
820 g_return_if_fail (d != NULL);
821 g_return_if_fail (g_date_valid_month (m));
827 if (g_date_valid_mdy (d->month, d->day, d->year))
834 g_date_set_day (GDate *d,
837 g_return_if_fail (d != NULL);
838 g_return_if_fail (g_date_valid_day (day));
844 if (g_date_valid_mdy (d->month, d->day, d->year))
851 g_date_set_year (GDate *d,
854 g_return_if_fail (d != NULL);
855 g_return_if_fail (g_date_valid_year (y));
861 if (g_date_valid_mdy (d->month, d->day, d->year))
868 g_date_set_mdy (GDate *d,
873 g_return_if_fail (d != NULL);
874 g_return_if_fail (g_date_valid_mdy (m, day, y));
886 g_date_set_julian (GDate *d, guint32 j)
888 g_return_if_fail (d != NULL);
889 g_return_if_fail (g_date_valid_julian (j));
898 g_date_is_first_of_month (GDate *d)
900 g_return_val_if_fail (d != NULL, FALSE);
901 g_return_val_if_fail (g_date_valid (d), FALSE);
905 g_date_update_mdy (d);
907 g_return_val_if_fail (d->mdy, FALSE);
909 if (d->day == 1) return TRUE;
914 g_date_is_last_of_month (GDate *d)
918 g_return_val_if_fail (d != NULL, FALSE);
919 g_return_val_if_fail (g_date_valid (d), FALSE);
923 g_date_update_mdy (d);
925 g_return_val_if_fail (d->mdy, FALSE);
927 index = g_date_is_leap_year (d->year) ? 1 : 0;
929 if (d->day == days_in_months[index][d->month]) return TRUE;
934 g_date_add_days (GDate *d, guint ndays)
936 g_return_if_fail (d != NULL);
937 g_return_if_fail (g_date_valid (d));
941 g_date_update_julian (d);
943 g_return_if_fail (d->julian);
945 d->julian_days += ndays;
950 g_date_subtract_days (GDate *d, guint ndays)
952 g_return_if_fail (d != NULL);
953 g_return_if_fail (g_date_valid (d));
957 g_date_update_julian (d);
959 g_return_if_fail (d->julian);
960 g_return_if_fail (d->julian_days > ndays);
962 d->julian_days -= ndays;
967 g_date_add_months (GDate *d,
973 g_return_if_fail (d != NULL);
974 g_return_if_fail (g_date_valid (d));
978 g_date_update_mdy (d);
980 g_return_if_fail (d->mdy);
982 nmonths += d->month - 1;
987 d->month = months + 1;
990 index = g_date_is_leap_year (d->year) ? 1 : 0;
992 if (d->day > days_in_months[index][d->month])
993 d->day = days_in_months[index][d->month];
997 g_return_if_fail (g_date_valid (d));
1001 g_date_subtract_months (GDate *d,
1004 guint years, months;
1007 g_return_if_fail (d != NULL);
1008 g_return_if_fail (g_date_valid (d));
1012 g_date_update_mdy (d);
1014 g_return_if_fail (d->mdy);
1017 months = nmonths%12;
1019 g_return_if_fail (d->year > years);
1023 if (d->month > months) d->month -= months;
1027 d->month = 12 - months;
1031 index = g_date_is_leap_year (d->year) ? 1 : 0;
1033 if (d->day > days_in_months[index][d->month])
1034 d->day = days_in_months[index][d->month];
1038 g_return_if_fail (g_date_valid (d));
1042 g_date_add_years (GDate *d,
1045 g_return_if_fail (d != NULL);
1046 g_return_if_fail (g_date_valid (d));
1050 g_date_update_mdy (d);
1052 g_return_if_fail (d->mdy);
1056 if (d->month == 2 && d->day == 29)
1058 if (!g_date_is_leap_year (d->year))
1068 g_date_subtract_years (GDate *d,
1071 g_return_if_fail (d != NULL);
1072 g_return_if_fail (g_date_valid (d));
1076 g_date_update_mdy (d);
1078 g_return_if_fail (d->mdy);
1079 g_return_if_fail (d->year > nyears);
1083 if (d->month == 2 && d->day == 29)
1085 if (!g_date_is_leap_year (d->year))
1096 g_date_is_leap_year (GDateYear year)
1098 g_return_val_if_fail (g_date_valid_year (year), FALSE);
1100 return ( (((year % 4) == 0) && ((year % 100) != 0)) ||
1101 (year % 400) == 0 );
1105 g_date_days_in_month (GDateMonth month,
1110 g_return_val_if_fail (g_date_valid_year (year), 0);
1111 g_return_val_if_fail (g_date_valid_month (month), 0);
1113 index = g_date_is_leap_year (year) ? 1 : 0;
1115 return days_in_months[index][month];
1119 g_date_monday_weeks_in_year (GDateYear year)
1123 g_return_val_if_fail (g_date_valid_year (year), 0);
1125 g_date_clear (&d, 1);
1126 g_date_set_mdy (&d, 1, 1, year);
1127 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1128 g_date_set_mdy (&d, 12, 31, year);
1129 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1130 if (g_date_is_leap_year (year))
1132 g_date_set_mdy (&d, 1, 2, year);
1133 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1134 g_date_set_mdy (&d, 12, 30, year);
1135 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1141 g_date_sunday_weeks_in_year (GDateYear year)
1145 g_return_val_if_fail (g_date_valid_year (year), 0);
1147 g_date_clear (&d, 1);
1148 g_date_set_mdy (&d, 1, 1, year);
1149 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1150 g_date_set_mdy (&d, 12, 31, year);
1151 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1152 if (g_date_is_leap_year (year))
1154 g_date_set_mdy (&d, 1, 2, year);
1155 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1156 g_date_set_mdy (&d, 12, 30, year);
1157 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1163 g_date_compare (GDate *lhs,
1166 g_return_val_if_fail (lhs != NULL, 0);
1167 g_return_val_if_fail (rhs != NULL, 0);
1168 g_return_val_if_fail (g_date_valid (lhs), 0);
1169 g_return_val_if_fail (g_date_valid (rhs), 0);
1171 /* Remember the self-comparison case! I think it works right now. */
1176 if (lhs->julian && rhs->julian)
1178 if (lhs->julian_days < rhs->julian_days) return -1;
1179 else if (lhs->julian_days > rhs->julian_days) return 1;
1182 else if (lhs->mdy && rhs->mdy)
1184 if (lhs->year < rhs->year) return -1;
1185 else if (lhs->year > rhs->year) return 1;
1188 if (lhs->month < rhs->month) return -1;
1189 else if (lhs->month > rhs->month) return 1;
1192 if (lhs->day < rhs->day) return -1;
1193 else if (lhs->day > rhs->day) return 1;
1202 if (!lhs->julian) g_date_update_julian (lhs);
1203 if (!rhs->julian) g_date_update_julian (rhs);
1204 g_return_val_if_fail (lhs->julian, 0);
1205 g_return_val_if_fail (rhs->julian, 0);
1209 return 0; /* warnings */
1214 g_date_to_struct_tm (GDate *d,
1219 g_return_if_fail (d != NULL);
1220 g_return_if_fail (g_date_valid (d));
1221 g_return_if_fail (tm != NULL);
1225 g_date_update_mdy (d);
1227 g_return_if_fail (d->mdy);
1229 /* zero all the irrelevant fields to be sure they're valid */
1231 /* On Linux and maybe other systems, there are weird non-POSIX
1232 * fields on the end of struct tm that choke strftime if they
1233 * contain garbage. So we need to 0 the entire struct, not just the
1234 * fields we know to exist.
1237 memset (tm, 0x0, sizeof (struct tm));
1239 tm->tm_mday = d->day;
1240 tm->tm_mon = d->month - 1; /* 0-11 goes in tm */
1241 tm->tm_year = ((int)d->year) - 1900; /* X/Open says tm_year can be negative */
1243 day = g_date_weekday (d);
1244 if (day == 7) day = 0; /* struct tm wants days since Sunday, so Sunday is 0 */
1246 tm->tm_wday = (int)day;
1248 tm->tm_yday = g_date_day_of_year (d) - 1; /* 0 to 365 */
1249 tm->tm_isdst = -1; /* -1 means "information not available" */
1253 g_date_strftime (gchar *s,
1255 const gchar *format,
1261 g_return_val_if_fail (d != NULL, 0);
1262 g_return_val_if_fail (g_date_valid (d), 0);
1263 g_return_val_if_fail (slen > 0, 0);
1264 g_return_val_if_fail (format != 0, 0);
1265 g_return_val_if_fail (s != 0, 0);
1267 g_date_to_struct_tm (d, &tm);
1269 retval = strftime (s, slen, format, &tm);
1272 /* If retval == 0, the contents of s are undefined. We define