- glsi32 microsec;
-
- bzero(tm, sizeof(tm));
- tm->tm_year = date->year - 1900;
- tm->tm_mon = date->month - 1;
- tm->tm_mday = date->day;
- tm->tm_wday = date->weekday;
- tm->tm_hour = date->hour;
- tm->tm_min = date->minute;
- tm->tm_sec = date->second;
- microsec = date->microsec;
-
- if (microsec >= G_USEC_PER_SEC) {
- tm->tm_sec += (microsec / G_USEC_PER_SEC);
- microsec = microsec % G_USEC_PER_SEC;
- }
- else if (microsec < 0) {
- microsec = -1 - microsec;
- tm->tm_sec -= (1 + microsec / G_USEC_PER_SEC);
- microsec = (G_USEC_PER_SEC - 1) - (microsec % G_USEC_PER_SEC);
- }
-
- return microsec;
+ /* Combining seconds and microseconds into one floating-point number should
+ * take care of normalizing any negative microseconds or microseconds > one
+ * million */
+ double seconds = date->second + (double)date->microsec / G_USEC_PER_SEC;
+ if( G_UNLIKELY(date->year < 1) ) {
+ WARNING("Years earlier than 1 C.E. are not currently supported.");
+ return NULL;
+ }
+ if( G_UNLIKELY(date->year > 9999) ) {
+ WARNING("Years later than 9999 C.E. are not currently supported.");
+ return NULL;
+ }
+ return g_date_time_new(tz,
+ date->year,
+ date->month,
+ date->day,
+ date->hour,
+ date->minute,
+ seconds);