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.
35 GDate *d = g_new0 (GDate, 1); /* happily, 0 is the invalid flag for everything. */
41 g_date_new_dmy (GDateDay day, GDateMonth m, GDateYear y)
44 g_return_val_if_fail (g_date_valid_dmy (day, m, y), NULL);
55 g_assert (g_date_valid (d));
61 g_date_new_julian (guint32 j)
64 g_return_val_if_fail (g_date_valid_julian (j), NULL);
73 g_assert (g_date_valid (d));
79 g_date_free (GDate *d)
81 g_return_if_fail (d != NULL);
87 g_date_valid (GDate *d)
89 g_return_val_if_fail (d != NULL, FALSE);
91 return (d->julian || d->dmy);
94 static const guint8 days_in_months[2][13] =
95 { /* error, jan feb mar apr may jun jul aug sep oct nov dec */
96 { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
97 { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } /* leap year */
100 static const guint16 days_in_year[2][14] =
101 { /* 0, jan feb mar apr may jun jul aug sep oct nov dec */
102 { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
103 { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
107 g_date_valid_month (GDateMonth m)
109 return ( (m > G_DATE_BAD_MONTH) && (m < 13) );
113 g_date_valid_year (GDateYear y)
115 return ( y > G_DATE_BAD_YEAR );
119 g_date_valid_day (GDateDay d)
121 return ( (d > G_DATE_BAD_DAY) && (d < 32) );
125 g_date_valid_weekday (GDateWeekday w)
127 return ( (w > G_DATE_BAD_WEEKDAY) && (w < 8) );
131 g_date_valid_julian (guint32 j)
133 return (j > G_DATE_BAD_JULIAN);
137 g_date_valid_dmy (GDateDay d,
141 return ( (m > G_DATE_BAD_MONTH) &&
143 (d > G_DATE_BAD_DAY) &&
144 (y > G_DATE_BAD_YEAR) && /* must check before using g_date_is_leap_year */
145 (d <= (g_date_is_leap_year (y) ?
146 days_in_months[1][m] : days_in_months[0][m])) );
150 /* "Julian days" just means an absolute number of days, where Day 1 ==
154 g_date_update_julian (GDate *d)
159 g_return_if_fail (d != NULL);
160 g_return_if_fail (d->dmy);
161 g_return_if_fail (!d->julian);
162 g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
164 /* What we actually do is: multiply years * 365 days in the year,
165 * add the number of years divided by 4, subtract the number of
166 * years divided by 100 and add the number of years divided by 400,
167 * which accounts for leap year stuff. Code from Steffen Beyer's
171 year = d->year - 1; /* we know d->year > 0 since it's valid */
173 d->julian_days = year * 365U;
174 d->julian_days += (year >>= 2); /* divide by 4 and add */
175 d->julian_days -= (year /= 25); /* divides original # years by 100 */
176 d->julian_days += year >> 2; /* divides by 4, which divides original by 400 */
178 index = g_date_is_leap_year (d->year) ? 1 : 0;
180 d->julian_days += days_in_year[index][d->month] + d->day;
182 g_return_if_fail (g_date_valid_julian (d->julian_days));
188 g_date_update_dmy (GDate *d)
194 guint32 A, B, C, D, E, M;
196 g_return_if_fail (d != NULL);
197 g_return_if_fail (d->julian);
198 g_return_if_fail (!d->dmy);
199 g_return_if_fail (g_date_valid_julian (d->julian_days));
201 /* Formula taken from the Calendar FAQ; the formula was for the
202 * Julian Period which starts on 1 January 4713 BC, so we add
203 * 1,721,425 to the number of days before doing the formula.
205 * I'm sure this can be simplified for our 1 January 1 AD period
206 * start, but I can't figure out how to unpack the formula.
209 A = d->julian_days + 1721425 + 32045;
210 B = ( 4 *(A + 36524) )/ 146097 - 1;
211 C = A - (146097 * B)/4;
212 D = ( 4 * (C + 365) ) / 1461 - 1;
213 E = C - ((1461*D) / 4);
214 M = (5 * (E - 1) + 2)/153;
216 m = M + 3 - (12*(M/10));
217 day = E - (153*M + 2)/5;
218 y = 100 * B + D - 4800 + (M/10);
220 #ifdef G_ENABLE_DEBUG
221 if (!g_date_valid_dmy (day, m, y))
223 g_warning ("\nOOPS julian: %u computed dmy: %u %u %u\n",
224 d->julian_days, day, m, y);
236 g_date_weekday (GDate *d)
238 g_return_val_if_fail (d != NULL, G_DATE_BAD_WEEKDAY);
239 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_WEEKDAY);
243 g_date_update_julian (d);
245 g_return_val_if_fail (d->julian, G_DATE_BAD_WEEKDAY);
247 return ((d->julian_days - 1) % 7) + 1;
251 g_date_month (GDate *d)
253 g_return_val_if_fail (d != NULL, G_DATE_BAD_MONTH);
254 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_MONTH);
258 g_date_update_dmy (d);
260 g_return_val_if_fail (d->dmy, G_DATE_BAD_MONTH);
266 g_date_year (GDate *d)
268 g_return_val_if_fail (d != NULL, G_DATE_BAD_YEAR);
269 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_YEAR);
273 g_date_update_dmy (d);
275 g_return_val_if_fail (d->dmy, G_DATE_BAD_YEAR);
281 g_date_day (GDate *d)
283 g_return_val_if_fail (d != NULL, G_DATE_BAD_DAY);
284 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_DAY);
288 g_date_update_dmy (d);
290 g_return_val_if_fail (d->dmy, G_DATE_BAD_DAY);
296 g_date_julian (GDate *d)
298 g_return_val_if_fail (d != NULL, G_DATE_BAD_JULIAN);
299 g_return_val_if_fail (g_date_valid (d), G_DATE_BAD_JULIAN);
303 g_date_update_julian (d);
305 g_return_val_if_fail (d->julian, G_DATE_BAD_JULIAN);
307 return d->julian_days;
311 g_date_day_of_year (GDate *d)
315 g_return_val_if_fail (d != NULL, 0);
316 g_return_val_if_fail (g_date_valid (d), 0);
320 g_date_update_dmy (d);
322 g_return_val_if_fail (d->dmy, 0);
324 index = g_date_is_leap_year (d->year) ? 1 : 0;
326 return (days_in_year[index][d->month] + d->day);
330 g_date_monday_week_of_year (GDate *d)
336 g_return_val_if_fail (d != NULL, 0);
337 g_return_val_if_fail (g_date_valid (d), 0);
341 g_date_update_dmy (d);
343 g_return_val_if_fail (d->dmy, 0);
345 g_date_clear (&first, 1);
347 g_date_set_dmy (&first, 1, 1, d->year);
349 wd = g_date_weekday (&first) - 1; /* make Monday day 0 */
350 day = g_date_day_of_year (d) - 1;
352 return ((day + wd)/7U + (wd == 0 ? 1 : 0));
356 g_date_sunday_week_of_year (GDate *d)
362 g_return_val_if_fail (d != NULL, 0);
363 g_return_val_if_fail (g_date_valid (d), 0);
367 g_date_update_dmy (d);
369 g_return_val_if_fail (d->dmy, 0);
371 g_date_clear (&first, 1);
373 g_date_set_dmy (&first, 1, 1, d->year);
375 wd = g_date_weekday (&first);
376 if (wd == 7) wd = 0; /* make Sunday day 0 */
377 day = g_date_day_of_year (d) - 1;
379 return ((day + wd)/7U + (wd == 0 ? 1 : 0));
383 g_date_clear (GDate *d, guint ndates)
385 g_return_if_fail (d != NULL);
386 g_return_if_fail (ndates != 0);
388 memset (d, 0x0, ndates*sizeof (GDate));
391 static G_LOCK_DEFINE(g_date_global);
393 /* These are for the parser, output to the user should use *
394 * g_date_strftime () - this creates more never-freed memory to annoy
395 * all those memory debugger users. :-)
398 static gchar *long_month_names[13] =
400 "Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
403 static gchar *short_month_names[13] =
405 "Error", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
408 /* This tells us if we need to update the parse info */
409 static gchar *current_locale = NULL;
411 /* order of these in the current locale */
412 static GDateDMY dmy_order[3] =
414 G_DATE_DAY, G_DATE_MONTH, G_DATE_YEAR
417 /* Where to chop two-digit years: i.e., for the 1930 default, numbers
418 * 29 and below are counted as in the year 2000, numbers 30 and above
419 * are counted as in the year 1900.
422 static GDateYear twodigit_start_year = 1930;
424 /* It is impossible to enter a year between 1 AD and 99 AD with this
427 static gboolean using_twodigit_years = FALSE;
429 struct _GDateParseTokens {
435 typedef struct _GDateParseTokens GDateParseTokens;
439 /* HOLDS: g_date_global_lock */
441 g_date_fill_parse_tokens (const gchar *str, GDateParseTokens *pt)
443 gchar num[4][NUM_LEN+1];
447 /* We count 4, but store 3; so we can give an error
450 num[0][0] = num[1][0] = num[2][0] = num[3][0] = '\0';
454 while (*s && pt->num_ints < 4)
458 while (*s && isdigit (*s) && i <= NUM_LEN)
460 num[pt->num_ints][i] = *s;
467 num[pt->num_ints][i] = '\0';
471 if (*s == '\0') break;
476 pt->n[0] = pt->num_ints > 0 ? atoi (num[0]) : 0;
477 pt->n[1] = pt->num_ints > 1 ? atoi (num[1]) : 0;
478 pt->n[2] = pt->num_ints > 2 ? atoi (num[2]) : 0;
480 pt->month = G_DATE_BAD_MONTH;
482 if (pt->num_ints < 3)
487 strncpy (lcstr, str, 127);
492 if (long_month_names[i] != NULL)
494 const gchar *found = strstr (lcstr, long_month_names[i]);
503 if (short_month_names[i] != NULL)
505 const gchar *found = strstr (lcstr, short_month_names[i]);
519 /* HOLDS: g_date_global_lock */
521 g_date_prepare_to_parse (const gchar *str, GDateParseTokens *pt)
523 const gchar *locale = setlocale (LC_TIME, NULL);
524 gboolean recompute_localeinfo = FALSE;
527 g_return_if_fail (locale != NULL); /* should not happen */
529 g_date_clear (&d, 1); /* clear for scratch use */
531 if ( (current_locale == NULL) || (strcmp (locale, current_locale) != 0) )
533 recompute_localeinfo = TRUE; /* Uh, there used to be a reason for the temporary */
536 if (recompute_localeinfo)
539 GDateParseTokens testpt;
542 g_free (current_locale); /* still works if current_locale == NULL */
544 current_locale = g_strdup (locale);
548 g_date_set_dmy (&d, 1, i, 1);
550 g_return_if_fail (g_date_valid (&d));
552 g_date_strftime (buf, 127, "%b", &d);
553 g_free (short_month_names[i]);
555 short_month_names[i] = g_strdup (buf);
559 g_date_strftime (buf, 127, "%B", &d);
560 g_free (long_month_names[i]);
562 long_month_names[i] = g_strdup (buf);
567 /* Determine DMY order */
569 g_date_set_dmy (&d, 4, 7, 1776); /* had to pick a random day */
571 g_date_strftime (buf, 127, "%x", &d);
573 g_date_fill_parse_tokens (buf, &testpt);
576 while (i < testpt.num_ints)
581 dmy_order[i] = G_DATE_MONTH;
584 dmy_order[i] = G_DATE_DAY;
587 using_twodigit_years = TRUE; /* FALL THRU */
589 dmy_order[i] = G_DATE_YEAR;
592 /* leave it unchanged */
598 #ifdef G_ENABLE_DEBUG
599 g_message ("**GDate prepared a new set of locale-specific parse rules.");
603 g_message (" %s %s", long_month_names[i], short_month_names[i]);
606 if (using_twodigit_years)
608 g_message ("**Using twodigit years with cutoff year: %u", twodigit_start_year);
615 switch (dmy_order[i])
618 strings[i] = "Month";
632 g_message ("**Order: %s, %s, %s", strings[0], strings[1], strings[2]);
633 g_message ("**Sample date in this locale: `%s'", buf);
638 g_date_fill_parse_tokens (str, pt);
642 g_date_set_parse (GDate *d,
646 guint m = G_DATE_BAD_MONTH, day = G_DATE_BAD_DAY, y = G_DATE_BAD_YEAR;
648 g_return_if_fail (d != NULL);
653 g_lock (g_date_global);
655 g_date_prepare_to_parse (str, &pt);
657 #ifdef G_ENABLE_DEBUG
658 g_message ("Found %d ints, `%d' `%d' `%d' and written out month %d",
659 pt.num_ints, pt.n[0], pt.n[1], pt.n[2], pt.month);
663 if (pt.num_ints == 4)
665 g_unlock (g_date_global);
666 return; /* presumably a typo; bail out. */
674 g_assert (pt.num_ints < 4); /* i.e., it is 2 or 3 */
676 while (i < pt.num_ints && j < 3)
678 switch (dmy_order[j])
682 if (pt.num_ints == 2 && pt.month != G_DATE_BAD_MONTH)
685 ++j; /* skip months, but don't skip this number */
694 if (pt.num_ints == 2 && pt.month == G_DATE_BAD_MONTH)
697 ++j; /* skip days, since we may have month/year */
707 if (using_twodigit_years && y < 100)
709 guint two = twodigit_start_year % 100;
710 guint century = (twodigit_start_year / 100) * 100;
728 if (pt.num_ints == 3 && !g_date_valid_dmy (day, m, y))
735 if (using_twodigit_years && y < 100)
736 y = G_DATE_BAD_YEAR; /* avoids ambiguity */
739 else if (pt.num_ints == 1)
741 if (pt.month != G_DATE_BAD_MONTH)
743 /* Month name and year? */
750 /* Try yyyymmdd and yymmdd */
752 m = (pt.n[0]/100) % 100;
756 /* FIXME move this into a separate function */
757 if (using_twodigit_years && y < 100)
759 guint two = twodigit_start_year % 100;
760 guint century = (twodigit_start_year / 100) * 100;
770 /* See if we got anything valid out of all this. */
771 /* y < 8000 is to catch 19998 style typos; the library is OK up to 65535 or so */
772 if (y < 8000 && g_date_valid_dmy (day, m, y))
779 #ifdef G_ENABLE_DEBUG
781 g_message ("Rejected DMY %u %u %u", day, m, y);
783 g_unlock (g_date_global);
787 g_date_set_time (GDate *d,
793 g_return_if_fail (d != NULL);
801 d->month = tm->tm_mon + 1;
802 d->day = tm->tm_mday;
803 d->year = tm->tm_year + 1900;
805 g_return_if_fail (g_date_valid_dmy (d->day, d->month, d->year));
816 g_date_set_month (GDate *d,
819 g_return_if_fail (d != NULL);
820 g_return_if_fail (g_date_valid_month (m));
822 if (d->julian && !d->dmy) g_date_update_dmy(d);
827 if (g_date_valid_dmy (d->day, d->month, 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));
840 if (d->julian && !d->dmy) g_date_update_dmy(d);
845 if (g_date_valid_dmy (d->day, d->month, d->year))
852 g_date_set_year (GDate *d,
855 g_return_if_fail (d != NULL);
856 g_return_if_fail (g_date_valid_year (y));
858 if (d->julian && !d->dmy) g_date_update_dmy(d);
863 if (g_date_valid_dmy (d->day, d->month, d->year))
870 g_date_set_dmy (GDate *d,
875 g_return_if_fail (d != NULL);
876 g_return_if_fail (g_date_valid_dmy (day, m, y));
888 g_date_set_julian (GDate *d, guint32 j)
890 g_return_if_fail (d != NULL);
891 g_return_if_fail (g_date_valid_julian (j));
900 g_date_is_first_of_month (GDate *d)
902 g_return_val_if_fail (d != NULL, FALSE);
903 g_return_val_if_fail (g_date_valid (d), FALSE);
907 g_date_update_dmy (d);
909 g_return_val_if_fail (d->dmy, FALSE);
911 if (d->day == 1) return TRUE;
916 g_date_is_last_of_month (GDate *d)
920 g_return_val_if_fail (d != NULL, FALSE);
921 g_return_val_if_fail (g_date_valid (d), FALSE);
925 g_date_update_dmy (d);
927 g_return_val_if_fail (d->dmy, FALSE);
929 index = g_date_is_leap_year (d->year) ? 1 : 0;
931 if (d->day == days_in_months[index][d->month]) return TRUE;
936 g_date_add_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);
947 d->julian_days += ndays;
952 g_date_subtract_days (GDate *d, guint ndays)
954 g_return_if_fail (d != NULL);
955 g_return_if_fail (g_date_valid (d));
959 g_date_update_julian (d);
961 g_return_if_fail (d->julian);
962 g_return_if_fail (d->julian_days > ndays);
964 d->julian_days -= ndays;
969 g_date_add_months (GDate *d,
975 g_return_if_fail (d != NULL);
976 g_return_if_fail (g_date_valid (d));
980 g_date_update_dmy (d);
982 g_return_if_fail (d->dmy);
984 nmonths += d->month - 1;
989 d->month = months + 1;
992 index = g_date_is_leap_year (d->year) ? 1 : 0;
994 if (d->day > days_in_months[index][d->month])
995 d->day = days_in_months[index][d->month];
999 g_return_if_fail (g_date_valid (d));
1003 g_date_subtract_months (GDate *d,
1006 guint years, months;
1009 g_return_if_fail (d != NULL);
1010 g_return_if_fail (g_date_valid (d));
1014 g_date_update_dmy (d);
1016 g_return_if_fail (d->dmy);
1019 months = nmonths%12;
1021 g_return_if_fail (d->year > years);
1025 if (d->month > months) d->month -= months;
1029 d->month = 12 - months;
1033 index = g_date_is_leap_year (d->year) ? 1 : 0;
1035 if (d->day > days_in_months[index][d->month])
1036 d->day = days_in_months[index][d->month];
1040 g_return_if_fail (g_date_valid (d));
1044 g_date_add_years (GDate *d,
1047 g_return_if_fail (d != NULL);
1048 g_return_if_fail (g_date_valid (d));
1052 g_date_update_dmy (d);
1054 g_return_if_fail (d->dmy);
1058 if (d->month == 2 && d->day == 29)
1060 if (!g_date_is_leap_year (d->year))
1070 g_date_subtract_years (GDate *d,
1073 g_return_if_fail (d != NULL);
1074 g_return_if_fail (g_date_valid (d));
1078 g_date_update_dmy (d);
1080 g_return_if_fail (d->dmy);
1081 g_return_if_fail (d->year > nyears);
1085 if (d->month == 2 && d->day == 29)
1087 if (!g_date_is_leap_year (d->year))
1098 g_date_is_leap_year (GDateYear year)
1100 g_return_val_if_fail (g_date_valid_year (year), FALSE);
1102 return ( (((year % 4) == 0) && ((year % 100) != 0)) ||
1103 (year % 400) == 0 );
1107 g_date_days_in_month (GDateMonth month,
1112 g_return_val_if_fail (g_date_valid_year (year), 0);
1113 g_return_val_if_fail (g_date_valid_month (month), 0);
1115 index = g_date_is_leap_year (year) ? 1 : 0;
1117 return days_in_months[index][month];
1121 g_date_monday_weeks_in_year (GDateYear year)
1125 g_return_val_if_fail (g_date_valid_year (year), 0);
1127 g_date_clear (&d, 1);
1128 g_date_set_dmy (&d, 1, 1, year);
1129 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1130 g_date_set_dmy (&d, 31, 12, year);
1131 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1132 if (g_date_is_leap_year (year))
1134 g_date_set_dmy (&d, 2, 1, year);
1135 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1136 g_date_set_dmy (&d, 30, 12, year);
1137 if (g_date_weekday (&d) == G_DATE_MONDAY) return 53;
1143 g_date_sunday_weeks_in_year (GDateYear year)
1147 g_return_val_if_fail (g_date_valid_year (year), 0);
1149 g_date_clear (&d, 1);
1150 g_date_set_dmy (&d, 1, 1, year);
1151 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1152 g_date_set_dmy (&d, 31, 12, year);
1153 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1154 if (g_date_is_leap_year (year))
1156 g_date_set_dmy (&d, 2, 1, year);
1157 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1158 g_date_set_dmy (&d, 30, 12, year);
1159 if (g_date_weekday (&d) == G_DATE_SUNDAY) return 53;
1165 g_date_compare (GDate *lhs,
1168 g_return_val_if_fail (lhs != NULL, 0);
1169 g_return_val_if_fail (rhs != NULL, 0);
1170 g_return_val_if_fail (g_date_valid (lhs), 0);
1171 g_return_val_if_fail (g_date_valid (rhs), 0);
1173 /* Remember the self-comparison case! I think it works right now. */
1178 if (lhs->julian && rhs->julian)
1180 if (lhs->julian_days < rhs->julian_days) return -1;
1181 else if (lhs->julian_days > rhs->julian_days) return 1;
1184 else if (lhs->dmy && rhs->dmy)
1186 if (lhs->year < rhs->year) return -1;
1187 else if (lhs->year > rhs->year) return 1;
1190 if (lhs->month < rhs->month) return -1;
1191 else if (lhs->month > rhs->month) return 1;
1194 if (lhs->day < rhs->day) return -1;
1195 else if (lhs->day > rhs->day) return 1;
1204 if (!lhs->julian) g_date_update_julian (lhs);
1205 if (!rhs->julian) g_date_update_julian (rhs);
1206 g_return_val_if_fail (lhs->julian, 0);
1207 g_return_val_if_fail (rhs->julian, 0);
1211 return 0; /* warnings */
1216 g_date_to_struct_tm (GDate *d,
1221 g_return_if_fail (d != NULL);
1222 g_return_if_fail (g_date_valid (d));
1223 g_return_if_fail (tm != NULL);
1227 g_date_update_dmy (d);
1229 g_return_if_fail (d->dmy);
1231 /* zero all the irrelevant fields to be sure they're valid */
1233 /* On Linux and maybe other systems, there are weird non-POSIX
1234 * fields on the end of struct tm that choke strftime if they
1235 * contain garbage. So we need to 0 the entire struct, not just the
1236 * fields we know to exist.
1239 memset (tm, 0x0, sizeof (struct tm));
1241 tm->tm_mday = d->day;
1242 tm->tm_mon = d->month - 1; /* 0-11 goes in tm */
1243 tm->tm_year = ((int)d->year) - 1900; /* X/Open says tm_year can be negative */
1245 day = g_date_weekday (d);
1246 if (day == 7) day = 0; /* struct tm wants days since Sunday, so Sunday is 0 */
1248 tm->tm_wday = (int)day;
1250 tm->tm_yday = g_date_day_of_year (d) - 1; /* 0 to 365 */
1251 tm->tm_isdst = -1; /* -1 means "information not available" */
1255 g_date_strftime (gchar *s,
1257 const gchar *format,
1263 g_return_val_if_fail (d != NULL, 0);
1264 g_return_val_if_fail (g_date_valid (d), 0);
1265 g_return_val_if_fail (slen > 0, 0);
1266 g_return_val_if_fail (format != 0, 0);
1267 g_return_val_if_fail (s != 0, 0);
1269 g_date_to_struct_tm (d, &tm);
1271 retval = strftime (s, slen, format, &tm);
1274 /* If retval == 0, the contents of s are undefined. We define