34 #include "qofdate-p.h" 67 g_return_if_fail (qt);
68 g_return_if_fail (qt->valid);
77 g_return_val_if_fail (qt, NULL);
78 g_return_val_if_fail (qt->valid, NULL);
87 g_return_val_if_fail (qt->valid, NULL);
88 if ((qt->qt_sec < 0) && (qt->qt_nsec >
QOF_NSECS))
93 if ((qt->qt_sec >= 0) && (qt->qt_nsec >
QOF_NSECS))
98 if ((qt->qt_sec < 0) && (qt->qt_nsec < -
QOF_NSECS))
100 qt->qt_sec -= -(-qt->qt_nsec /
QOF_NSECS);
101 qt->qt_nsec = -(-qt->qt_nsec %
QOF_NSECS);
103 if ((qt->qt_sec >= 0) && (qt->qt_nsec < -
QOF_NSECS))
105 qt->qt_sec += -(-qt->qt_nsec /
QOF_NSECS);
106 qt->qt_nsec = -(-qt->qt_nsec %
QOF_NSECS);
108 if (qt->qt_sec >= 0 && qt->qt_nsec < 0)
135 g_return_val_if_fail (qt, 0);
136 g_return_val_if_fail (qt->valid == TRUE, 0);
143 g_return_val_if_fail (qt->valid == TRUE, 0);
156 g_return_val_if_fail (ta->valid && tb->valid, FALSE);
157 if (ta->qt_sec != tb->qt_sec)
159 if (ta->qt_nsec != tb->qt_nsec)
167 g_return_val_if_fail (ta->valid && tb->valid, -1);
170 if (ta->qt_sec < tb->qt_sec)
172 if (ta->qt_sec > tb->qt_sec)
174 if (ta->qt_nsec < tb->qt_nsec)
176 if (ta->qt_nsec > tb->qt_nsec)
186 g_return_val_if_fail (ta->valid && tb->valid, NULL);
188 retval->qt_sec = ta->qt_sec - tb->qt_sec;
189 retval->qt_nsec = ta->qt_nsec - tb->qt_nsec;
190 retval->valid = TRUE;
191 time_normalize (retval);
198 g_return_val_if_fail (qt, NULL);
199 return time_normalize (qt);
203 qof_time_is_valid (
const QofTime * qt)
205 g_return_val_if_fail (qt, FALSE);
216 qt->qt_nsec = nanosecs;
225 g_return_val_if_fail (qt, NULL);
226 g_return_val_if_fail (qt->valid, NULL);
245 *nanosecs = qt->qt_nsec;
247 if ((
sizeof (qt->qt_sec) > sizeof (time_t))
248 && (qt->qt_sec > G_MAXINT32))
250 PERR (
" QofTime too large for time_t on this platform.");
276 PERR (
" invalid QofTime passed");
279 if (qt->qt_sec > G_MAXLONG)
281 PERR (
" QofTime out of range for GTimeVal");
284 gtv->tv_sec = (glong) qt->qt_sec;
285 gtv->tv_usec = qt->qt_nsec;
293 qt->qt_nsec = gtv->tv_usec * 1000;
306 if (g_date_valid (d))
318 g_return_val_if_fail (date, NULL);
319 g_date_to_struct_tm (date, >m);
351 current = g_new0 (GTimeVal, 1);
352 g_get_current_time (current);
354 tm = *gmtime_r (¤t->tv_sec, &tm);
355 current->tv_sec -= tm.tm_sec;
356 current->tv_sec -= tm.tm_min * 60;
357 current->tv_sec -= tm.tm_hour * 60 * 60;
368 g_get_current_time (&gnow);
379 g_return_val_if_fail (qt, FALSE);
429 g_return_val_if_fail (qt, 0);
433 m = g_date_get_month (d);
434 y = g_date_get_year (d);
435 return g_date_get_days_in_month (m, y);
448 *day = g_date_get_day (d);
450 *month = g_date_get_month (d);
452 *year = g_date_get_year (d);
462 g_return_val_if_fail (g_date_valid_dmy (day, month, year), NULL);
463 d = g_date_new_dmy (day, month, year);
479 qtm = *gmtime_r (&t, &qtm);
482 if (len == 0 && test[0] !=
'\0')
484 LEAVE (
" strftime failed.");
488 return g_strdup (test);
gint64 qd_year
Extended version to cope with full range of dates.
#define QOF_DATE_FORMAT_UTC
QOF UTC format, xsd:date compatible. QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ".
#define PERR(format, args...)
QofTime * qof_time_from_gdate(GDate *date)
Convert a GDate to a QofTime.
gchar * qof_time_stamp_now(void)
void qof_date_free(QofDate *date)
QofDate * qof_date_from_qtime(const QofTime *qt)
gboolean qof_time_set_day_end(QofTime *qt)
set the given QofTime to the last second of that day.
QofTime * qof_time_add_secs_copy(QofTime *qt, QofTimeSecs secs)
Create a new QofTime, secs different to an original.
QofTime * qof_time_abs(QofTime *qt)
QofTimeSecs qof_time_get_secs(const QofTime *qt)
Get the number of seconds.
QofTime * qof_time_get_today_end(void)
gboolean qof_time_to_dmy(QofTime *qt, guint8 *day, guint8 *month, guint16 *year)
QofTime * qof_time_copy(const QofTime *qt)
Create a copy of a QofTime.
void qof_time_set_secs(QofTime *qt, QofTimeSecs secs)
Set the number of seconds.
QofTime * qof_time_new(void)
create an empty QofTime
QofTime * qof_time_from_time_t(time_t t, glong nanosecs)
GDate * qof_time_to_gdate(QofTime *qt)
Convert QofTime to GDate.
gboolean qof_time_set_day_start(QofTime *qt)
set the given QofTime to the first second of that day.
QofTime * qof_time_dmy_to_time(guint8 day, guint8 month, guint16 year)
glong qof_time_get_nanosecs(const QofTime *qt)
Get the number of seconds.
const gchar * qof_date_format_get_format(QofDateFormat df)
Retrieve the strftime format string for a registered date format.
#define LEAVE(format, args...)
QofTime * qof_date_to_qtime(const QofDate *qd)
Full range replacement for struct tm.
QofTime * qof_time_get_current(void)
Get the current QofTime.
gboolean qof_time_set_day_middle(QofTime *qt)
set the given QofTime to midday on the same day.
void qof_time_free(QofTime *qt)
Free a QofTime when no longer required.
gint qof_time_cmp(const QofTime *ta, const QofTime *tb)
glong qd_mon
Signed replacement of struct tm.tm_mon.
void qof_time_add_secs(QofTime *qt, QofTimeSecs secs)
Add (or subtract) seconds from a QofTime.
QofTime * qof_time_get_today_start(void)
GTimeVal * qof_time_get_current_start(void)
gboolean qof_time_equal(const QofTime *ta, const QofTime *tb)
gboolean qof_time_to_time_t(QofTime *qt, time_t *t, glong *nanosecs)
void qof_time_set_nanosecs(QofTime *qt, glong nano)
Set the number of seconds.
guint8 qof_time_last_mday(QofTime *qt)
#define MAX_DATE_LENGTH
The maximum length of a string used for or created by dates.
glong qd_gmt_off
Calculated value based on struct tm.tm_gmtoff.
QofTime * qof_time_set(QofTimeSecs t, glong nanosecs)
gint64 QofTimeSecs
Replacement for time_t.
struct QofTime64 QofTime
Use a 64-bit signed int QofTime.
QofTime * qof_time_from_tm(struct tm *qtm, glong nanosecs)
Convert a broken-down into a QofTime.
void qof_time_from_gtimeval(QofTime *qt, GTimeVal *gtv)
Convert a QofTime to a GTimeVal.
#define QOF_DAYS_TO_SEC(x)
glong qd_mday
Signed replacement of struct tm.tm_mday.
gboolean qof_time_to_gtimeval(QofTime *qt, GTimeVal *gtv)
Convert a QofTime to a GTimeVal.
#define ENTER(format, args...)
QofTime * qof_time_diff(const QofTime *ta, const QofTime *tb)
difference between two QofTimes.
const gchar * QofLogModule
QofDate * qof_date_from_struct_tm(const struct tm *stm)
Convert a struct tm to a QofDate.