GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-date.h
Go to the documentation of this file.
1 /***************************************************************************
2  * gnc-date.h (to be renamed qofdate.h)
3  *
4  * Copyright (C) 1997 Robin D. Clark <[email protected]>
5  * Copyright (C) 1998-2000, 2003 Linas Vepstas <[email protected]>
6  * Copyright 2005 Neil Williams <[email protected]>
7  * Copyright 2012 John Ralls <[email protected]>
8  ****************************************************************************/
9 /********************************************************************\
10  * This program is free software; you can redistribute it and/or *
11  * modify it under the terms of the GNU General Public License as *
12  * published by the Free Software Foundation; either version 2 of *
13  * the License, or (at your option) any later version. *
14  * *
15  * This program is distributed in the hope that it will be useful, *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18  * GNU General Public License for more details. *
19  * *
20  * You should have received a copy of the GNU General Public License*
21  * along with this program; if not, contact: *
22  * *
23  * Free Software Foundation Voice: +1-617-542-5942 *
24  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
25  * Boston, MA 02110-1301, USA [email protected] *
26 \********************************************************************/
68 #ifndef GNC_DATE_H
69 #define GNC_DATE_H
70 #ifdef __cplusplus
71 extern "C"
72 {
73 #endif
74 
75 #include <glib-object.h>
76 #include <time.h>
77 
83 typedef gint64 time64;
84 
93 typedef struct timespec64 Timespec;
94 
98 GType timespec_get_type( void );
99 #define GNC_TYPE_TIMESPEC (timespec_get_type ())
100 
103 extern const char *gnc_default_strftime_date_format;
104 
106 #define MAX_DATE_LENGTH 34
107 
118 #define QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ"
119 
121 typedef enum
122 {
130 } QofDateFormat;
131 
132 #define DATE_FORMAT_FIRST QOF_DATE_FORMAT_US
133 #define DATE_FORMAT_LAST QOF_DATE_FORMAT_UTC
134 
136 typedef enum
137 {
141 
144 #define qof_date_format_get_format qof_date_text_format_get_string
145 
150 typedef enum
151 {
152  GNCDATE_MONTH_NUMBER,
153  GNCDATE_MONTH_ABBREV,
154  GNCDATE_MONTH_NAME
156 /* Replacements for POSIX functions which use time_t. Time_t is still
157  * 32 bits in Microsoft Windows, Apple OSX, and some BSD versions even
158  * when the rest of the system is 64-bits, as well as all 32-bit
159  * versions of Unix. 32-bit time_t overflows at 03:14:07 UTC on
160  * Tuesday, 19 January 2038 and so cannot represent dates after that.
161  *
162  * These functions use GLib's GDateTime internally, and include a
163  * workaround for the lack of Win32 support before GLib 2.36.
164  */
171 struct tm* gnc_localtime (const time64 *secs);
172 
179 struct tm* gnc_localtime_r (const time64 *secs, struct tm* time);
180 
187 struct tm* gnc_gmtime (const time64 *secs);
188 
195 time64 gnc_mktime (struct tm* time);
196 
203 time64 gnc_timegm (struct tm* time);
204 
213 gchar* gnc_ctime (const time64 *secs);
214 
221 time64 gnc_time (time64 *tbuf);
222 
229 time64 gnc_time_utc (time64 *tbuf);
230 
239 gdouble gnc_difftime (const time64 secs1, const time64 secs2);
240 
244 GDateTime*
246 
250 void gnc_tm_free (struct tm* time);
251 
259 
262 
264 const gchar* gnc_date_dateformat_to_string(QofDateFormat format);
265 
271 gboolean gnc_date_string_to_dateformat(const gchar* format_string,
272  QofDateFormat *format);
273 
274 const gchar* gnc_date_monthformat_to_string(GNCDateMonthFormat format);
275 
281 gboolean gnc_date_string_to_monthformat(const gchar *format_string,
282  GNCDateMonthFormat *format);
283 // @}
284 
285 /* Datatypes *******************************************************/
286 
298 #ifndef SWIG /* swig 1.1p5 can't hack the long long type */
300 {
301  time64 tv_sec;
302  glong tv_nsec;
303 };
304 #endif /* SWIG */
305 
306 
307 
308 /* Prototypes ******************************************************/
309 
311 // @{
313 gboolean timespec_equal(const Timespec *ta, const Timespec *tb);
314 
316 gint timespec_cmp(const Timespec *ta, const Timespec *tb);
317 
321 Timespec timespec_diff(const Timespec *ta, const Timespec *tb);
322 
324 Timespec timespec_abs(const Timespec *t);
325 
331 
333 Timespec timespec_now (void);
334 
336 void timespecFromTime64 (Timespec *ts, time64 t );
337 
339 time64 timespecToTime64 (Timespec ts);
340 
343 GDate* gnc_g_date_new_today (void);
344 
346 GDate timespec_to_gdate (Timespec ts);
347 
349 Timespec gdate_to_timespec (GDate d);
350 
351 
353 Timespec gnc_dmy2timespec (gint day, gint month, gint year);
354 
356 Timespec gnc_dmy2timespec_end (gint day, gint month, gint year);
357 
375 
392 gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
393 
400 void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
401 
414 glong gnc_timezone (const struct tm *tm);
415 // @}
416 
417 /* ------------------------------------------------------------------------ */
419 // @{
426 
433 
443 
453 // @}
454 
461 void qof_date_completion_set(QofDateCompletion dc, int backmonths);
462 
472 gchar dateSeparator(void);
473 
476 // @{
485 /* qof_format_time takes a format specification in UTF-8 and a broken-down time,
486  * tries to call strftime with a sufficiently large buffer and, if successful,
487  * return a newly allocated string in UTF-8 for the printing result.
488  *
489  * @param format A format specification in UTF-8.
490  *
491  * @param tm A broken-down time.
492  *
493  * @return A newly allocated string on success, or NULL otherwise.
494  */
495 /* gchar *qof_format_time(const gchar *format, const struct tm *tm); */
496 
511 gsize qof_strftime(gchar *buf, gsize max, const gchar *format,
512  const struct tm *tm);
513 
529 size_t qof_print_date_dmy_buff (gchar * buff, size_t buflen, int day, int month, int year);
530 
532 size_t qof_print_date_buff (char * buff, size_t buflen, time64 secs);
533 
535 size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd);
536 
540 char * qof_print_date (time64 secs);
541 
548 const char * gnc_print_date(Timespec ts);
549 
550 /* ------------------------------------------------------------------ */
551 /* time printing utilities */
552 
557 size_t qof_print_date_time_buff (char * buff, size_t len, time64 secs);
558 
572 gboolean qof_scan_date (const char *buff, int *day, int *month, int *year);
573 
574 // @}
578 // @{
579 
584 static inline
585 void gnc_tm_set_day_start (struct tm *tm)
586 {
587  /* First second of the day */
588  g_return_if_fail (tm != NULL);
589  tm->tm_hour = 0;
590  tm->tm_min = 0;
591  tm->tm_sec = 0;
592  tm->tm_isdst = -1;
593 }
594 
599 static inline
600 void gnc_tm_set_day_middle (struct tm *tm)
601 {
602  /* First second of the day */
603  g_return_if_fail (tm != NULL);
604  tm->tm_hour = 12;
605  tm->tm_min = 0;
606  tm->tm_sec = 0;
607  tm->tm_isdst = -1;
608 }
609 
614 static inline
615 void gnc_tm_set_day_end (struct tm *tm)
616 {
617  /* Last second of the day */
618  g_return_if_fail (tm != NULL);
619  tm->tm_hour = 23;
620  tm->tm_min = 59;
621  tm->tm_sec = 59;
622  tm->tm_isdst = -1;
623 }
624 
627 time64 gnc_time64_get_day_start(time64 time_val);
628 
631 time64 gnc_time64_get_day_end(time64 time_val);
632 
634 int gnc_date_get_last_mday (int month, int year);
635 
636 // @}
637 
638 /* ======================================================== */
639 
641 // @{
644 void gnc_tm_get_today_start(struct tm *tm);
645 
648 void gnc_tm_get_today_end(struct tm *tm);
649 
652 time64 gnc_time64_get_today_start(void);
653 
656 time64 gnc_time64_get_today_end(void);
657 
661 char * gnc_date_timestamp (void);
662 
663 #define MIN_BUF_LEN 10
664 
669 void gnc_dow_abbrev(gchar *buf, int buf_len, int dow);
670 
672 
673 #ifdef __cplusplus
674 }
675 #endif
676 
677 #endif /* GNC_DATE_H */
time64 gnc_time64_get_today_start(void)
gchar * gnc_timespec_to_iso8601_buff(Timespec ts, gchar *buff)
time64 timespecToTime64(Timespec ts)
const char * gnc_print_date(Timespec ts)
gboolean gnc_date_string_to_monthformat(const gchar *format_string, GNCDateMonthFormat *format)
Converts the month format to a printable string.
const gchar * gnc_date_dateformat_to_string(QofDateFormat format)
The string->value versions return FALSE on success and TRUE on failure.
QofDateCompletion
Definition: gnc-date.h:136
time64 gnc_time64_get_today_end(void)
const gchar * qof_date_text_format_get_string(QofDateFormat df)
Timespec timespecCanonicalDayTime(Timespec t)
glong gnc_timezone(const struct tm *tm)
Timespec gnc_dmy2timespec_end(gint day, gint month, gint year)
gboolean timespec_equal(const Timespec *ta, const Timespec *tb)
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
GDateTime * gnc_g_date_time_new_from_unix_local(time64 time)
gchar dateSeparator(void)
void gnc_dow_abbrev(gchar *buf, int buf_len, int dow)
const char * gnc_default_strftime_date_format
Timespec gnc_dmy2timespec(gint day, gint month, gint year)
struct tm * gnc_localtime_r(const time64 *secs, struct tm *time)
fill out a time struct from a 64-bit time value adjusted for the current time zone.
Timespec timespec_abs(const Timespec *t)
void gnc_tm_free(struct tm *time)
free a struct tm* created with gnc_localtime() or gnc_gmtime()
char * qof_print_date(time64 secs)
gint timespec_cmp(const Timespec *ta, const Timespec *tb)
GDate timespec_to_gdate(Timespec ts)
void qof_date_completion_set(QofDateCompletion dc, int backmonths)
time64 gnc_time64_get_day_end(time64 time_val)
const gchar * qof_date_format_get_string(QofDateFormat df)
time64 gnc_mktime(struct tm *time)
calculate seconds from the epoch given a time struct
int gnc_date_get_last_mday(int month, int year)
GNCDateMonthFormat
Definition: gnc-date.h:150
gsize qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
time64 gnc_timegm(struct tm *time)
calculate seconds from the epoch given a time struct
struct tm * gnc_localtime(const time64 *secs)
fill out a time struct from a 64-bit time value.
Timespec gnc_iso8601_to_timespec_gmt(const gchar *)
gdouble gnc_difftime(const time64 secs1, const time64 secs2)
Find the difference in seconds between two time values.
GDateTime * gnc_g_date_time_new_from_timespec_local(Timespec tm)
Create a GDateTime from a Timespec.
void gnc_tm_get_today_start(struct tm *tm)
time64 gnc_time64_get_day_start(time64 time_val)
Timespec timespec_diff(const Timespec *ta, const Timespec *tb)
void gnc_tm_get_today_end(struct tm *tm)
size_t qof_print_date_dmy_buff(gchar *buff, size_t buflen, int day, int month, int year)
Timespec timespec_now(void)
time64 gnc_time_utc(time64 *tbuf)
get the current utc time
gboolean qof_scan_date(const char *buff, int *day, int *month, int *year)
QofDateFormat qof_date_format_get(void)
struct tm * gnc_gmtime(const time64 *secs)
fill out a time struct from a 64-bit time value
void qof_date_format_set(QofDateFormat df)
time64 gnc_time(time64 *tbuf)
get the current local time
gint64 time64
Definition: gnc-date.h:83
Timespec gdate_to_timespec(GDate d)
size_t qof_print_date_buff(char *buff, size_t buflen, time64 secs)
gchar * gnc_ctime(const time64 *secs)
Return a string representation of a date from a 64-bit time value.
gboolean gnc_date_string_to_dateformat(const gchar *format_string, QofDateFormat *format)
Converts the date format to a printable string.
QofDateFormat
Definition: gnc-date.h:121
void gnc_timespec2dmy(Timespec ts, gint *day, gint *month, gint *year)
size_t qof_print_date_time_buff(char *buff, size_t len, time64 secs)
size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd)
void timespecFromTime64(Timespec *ts, time64 t)
char * gnc_date_timestamp(void)
Make a timestamp in YYYYMMDDHHMMSS format.
GDate * gnc_g_date_new_today(void)