00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00067 #ifndef GNC_DATE_H
00068 #define GNC_DATE_H
00069
00070 #include <time.h>
00071
00073 #define MAX_DATE_LENGTH 31
00074
00085 #define QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ"
00086
00088 typedef enum
00089 {
00090 QOF_DATE_FORMAT_US,
00091 QOF_DATE_FORMAT_UK,
00092 QOF_DATE_FORMAT_CE,
00093 QOF_DATE_FORMAT_ISO,
00094 QOF_DATE_FORMAT_UTC,
00095 QOF_DATE_FORMAT_LOCALE,
00096 QOF_DATE_FORMAT_CUSTOM
00097 } QofDateFormat;
00098
00099 #define DATE_FORMAT_FIRST QOF_DATE_FORMAT_US
00100 #define DATE_FORMAT_LAST QOF_DATE_FORMAT_LOCALE
00101
00104 #define qof_date_format_get_format qof_date_text_format_get_string
00105
00110 typedef enum {
00111 GNCDATE_MONTH_NUMBER,
00112 GNCDATE_MONTH_ABBREV,
00113 GNCDATE_MONTH_NAME
00114 } GNCDateMonthFormat;
00115
00116
00119
00121 const gchar* gnc_date_dateformat_to_string(QofDateFormat format);
00122
00128 gboolean gnc_date_string_to_dateformat(const gchar* format_string,
00129 QofDateFormat *format);
00130
00131 const gchar* gnc_date_monthformat_to_string(GNCDateMonthFormat format);
00132
00138 gboolean gnc_date_string_to_monthformat(const gchar *format_string,
00139 GNCDateMonthFormat *format);
00140
00141
00142
00143
00154 #ifndef SWIG
00155 struct timespec64
00156 {
00157 guint64 tv_sec;
00158 glong tv_nsec;
00159 };
00160 #endif
00161
00169 typedef struct timespec64 Timespec;
00170
00171
00172
00173
00175
00177 gboolean timespec_equal(const Timespec *ta, const Timespec *tb);
00178
00180 gint timespec_cmp(const Timespec *ta, const Timespec *tb);
00181
00185 Timespec timespec_diff(const Timespec *ta, const Timespec *tb);
00186
00188 Timespec timespec_abs(const Timespec *t);
00189
00192 Timespec timespecCanonicalDayTime(Timespec t);
00193
00195 void timespecFromTime_t( Timespec *ts, time_t t );
00196
00198 time_t timespecToTime_t (Timespec ts);
00199
00201 Timespec gnc_dmy2timespec (gint day, gint month, gint year);
00202
00204 Timespec gnc_dmy2timespec_end (gint day, gint month, gint year);
00205
00222 Timespec gnc_iso8601_to_timespec_gmt(const gchar *);
00223
00240 gchar * gnc_timespec_to_iso8601_buff (Timespec ts, gchar * buff);
00241
00244 void gnc_timespec2dmy (Timespec ts, gint *day, gint *month, gint *year);
00245
00252 gboolean qof_date_add_days(Timespec *ts, gint days);
00253
00262 gboolean qof_date_add_months(Timespec *ts, gint months, gboolean track_last_day);
00263
00266 void date_add_months (struct tm *tm, gint months, gboolean track_last_day);
00267
00276 time_t xaccDMYToSec (gint day, gint month, gint year);
00277
00290 glong gnc_timezone (struct tm *tm);
00291
00292
00293
00295
00301 QofDateFormat qof_date_format_get(void);
00302
00308 void qof_date_format_set(QofDateFormat df);
00309
00318 const gchar *qof_date_format_get_string(QofDateFormat df);
00319
00328 const gchar *qof_date_text_format_get_string(QofDateFormat df);
00329
00330
00340 gchar dateSeparator(void);
00341
00344
00368 size_t qof_print_date_dmy_buff (gchar * buff, size_t buflen, int day, int month, int year);
00369
00371 size_t qof_print_date_buff (char * buff, size_t buflen, time_t secs);
00372
00374 size_t qof_print_gdate( char *buf, size_t bufflen, GDate *gd );
00375
00379 char * qof_print_date (time_t secs);
00380
00387 const char * gnc_print_date(Timespec ts);
00388
00389
00390
00391
00397 size_t qof_print_hours_elapsed_buff (char * buff, size_t len, int secs, gboolean show_secs);
00398 size_t qof_print_minutes_elapsed_buff (char * buff, size_t len, int secs, gboolean show_secs);
00399
00405 size_t qof_print_time_buff (char * buff, size_t len, time_t secs);
00406 size_t qof_print_date_time_buff (char * buff, size_t len, time_t secs);
00407
00412 gboolean qof_is_same_day (time_t, time_t);
00413
00414
00420 char * xaccDateUtilGetStamp (time_t thyme);
00421
00435 gboolean qof_scan_date (const char *buff, int *day, int *month, int *year);
00436
00438 gboolean qof_scan_date_secs (const char *buff, time_t *secs);
00439
00440
00444
00445
00450 static inline
00451 void gnc_tm_set_day_start (struct tm *tm)
00452 {
00453
00454 tm->tm_hour = 0;
00455 tm->tm_min = 0;
00456 tm->tm_sec = 0;
00457 tm->tm_isdst = -1;
00458 }
00459
00464 static inline
00465 void gnc_tm_set_day_middle (struct tm *tm)
00466 {
00467
00468 tm->tm_hour = 12;
00469 tm->tm_min = 0;
00470 tm->tm_sec = 0;
00471 tm->tm_isdst = -1;
00472 }
00473
00478 static inline
00479 void gnc_tm_set_day_end (struct tm *tm)
00480 {
00481
00482 tm->tm_hour = 23;
00483 tm->tm_min = 59;
00484 tm->tm_sec = 59;
00485 tm->tm_isdst = -1;
00486 }
00487
00491 void gnc_tm_get_day_start(struct tm *tm, time_t time_val);
00492
00496 void gnc_tm_get_day_end(struct tm *tm, time_t time_val);
00497
00500 time_t gnc_timet_get_day_start(time_t time_val);
00501
00504 time_t gnc_timet_get_day_end(time_t time_val);
00505
00506 #ifndef GNUCASH_MAJOR_VERSION
00507
00512 time_t gnc_timet_get_day_start_gdate (GDate *date);
00513
00519 time_t gnc_timet_get_day_end_gdate (GDate *date);
00520 #endif
00521
00523 int date_get_last_mday(struct tm *tm);
00524
00526 gboolean date_is_last_mday(struct tm *tm);
00527
00529 int gnc_date_my_last_mday (int month, int year);
00531 int gnc_timespec_last_mday (Timespec ts);
00532
00533
00534
00535
00537
00540 void gnc_tm_get_today_start(struct tm *tm);
00541
00544 void gnc_tm_get_today_end(struct tm *tm);
00545
00548 time_t gnc_timet_get_today_start(void);
00549
00552 time_t gnc_timet_get_today_end(void);
00553
00558 char * xaccDateUtilGetStampNow (void);
00559
00561
00562 #endif