GnuCash c935c2f+
Loading...
Searching...
No Matches
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 <rclark@cs.hmc.edu>
5 * Copyright (C) 1998-2000, 2003 Linas Vepstas <linas@linas.org>
6 * Copyright 2005 Neil Williams <linux@codehelp.co.uk>
7 * Copyright (C) 2005 David Hampton <hampton@employees.org>
8 * Copyright 2012 John Ralls <jralls@ceridwen.us>
9 ********************************************************************/
10/********************************************************************\
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of the GNU General Public License as *
13 * published by the Free Software Foundation; either version 2 of *
14 * the License, or (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License for more details. *
20 * *
21 * You should have received a copy of the GNU General Public License*
22 * along with this program; if not, contact: *
23 * *
24 * Free Software Foundation Voice: +1-617-542-5942 *
25 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
26 * Boston, MA 02110-1301, USA gnu@gnu.org *
27\********************************************************************/
66#ifndef GNC_DATE_H
67#define GNC_DATE_H
68
69#include <glib-object.h>
70
71#include <time.h>
72
73#ifdef __cplusplus
74extern "C"
75{
76#endif
77
78
87typedef gint64 time64;
88/* A bit of a hack to create a type separate from the alias of int64_t so that
89 * compile-time dispatch can use the right KVP visitor.
90 */
91typedef struct
92{
93 time64 t;
94} Time64;
95
96
100GType time64_get_type( void );
101#define GNC_TYPE_TIME64 (time64_get_type ())
102
105extern const char *gnc_default_strftime_date_format;
106
108#define MAX_DATE_LENGTH 34
119#define QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ"
120
133
134#define DATE_FORMAT_FIRST QOF_DATE_FORMAT_US
135#define DATE_FORMAT_LAST QOF_DATE_FORMAT_UTC
136
143
148typedef enum
149{
150 GNCDATE_MONTH_NUMBER,
151 GNCDATE_MONTH_ABBREV,
152 GNCDATE_MONTH_NAME
154
155/* Replacements for POSIX functions which use time_t. Time_t is still
156 * 32 bits in Microsoft Windows, Apple OSX, and some BSD versions even
157 * when the rest of the system is 64-bits, as well as all 32-bit
158 * versions of Unix. 32-bit time_t overflows at 03:14:07 UTC on
159 * Tuesday, 19 January 2038 and so cannot represent dates after that.
160 *
161 * These functions use boost::date_time internally.
162 */
169struct tm* gnc_localtime (const time64 *secs);
170
177struct tm* gnc_localtime_r (const time64 *secs, struct tm* time);
178
185struct tm* gnc_gmtime (const time64 *secs);
186
190gint gnc_start_of_week (void);
191
198time64 gnc_mktime (struct tm* time);
199
206time64 gnc_timegm (struct tm* time);
207
216gchar* gnc_ctime (const time64 *secs);
217
224time64 gnc_time (time64 *tbuf);
225
235gdouble gnc_difftime (const time64 secs1, const time64 secs2);
236
240void gnc_tm_free (struct tm* time);
241
244
247
253gboolean gnc_date_string_to_dateformat(const gchar* format_string,
254 QofDateFormat *format);
255
256const gchar* gnc_date_monthformat_to_string(GNCDateMonthFormat format);
257
263gboolean gnc_date_string_to_monthformat(const gchar *format_string,
264 GNCDateMonthFormat *format);
265
271char* gnc_print_time64(time64 time, const char* format);
272
273// @}
274
279GDate* gnc_g_date_new_today (void);
280
284void gnc_gdate_set_today (GDate* gd);
285
290void gnc_gdate_set_time64 (GDate* gd, time64 time);
291
298
300time64 gdate_to_time64 (GDate d);
301
303time64 gnc_dmy2time64 (gint day, gint month, gint year);
304
312time64 gnc_dmy2time64_neutral (gint day, gint month, gint year);
313
315time64 gnc_dmy2time64_end (gint day, gint month, gint year);
316
334
351gchar * gnc_time64_to_iso8601_buff (time64, char * buff);
352// @}
353
354/* ======================================================== */
355
357// @{
364
371
381
391// @}
392
393/* ======================================================== */
394
401void qof_date_completion_set(QofDateCompletion dc, int backmonths);
402
412gchar dateSeparator(void);
413
414/* ======================================================== */
415
418// @{
427/* qof_format_time takes a format specification in UTF-8 and a broken-down time,
428 * tries to call strftime with a sufficiently large buffer and, if successful,
429 * return a newly allocated string in UTF-8 for the printing result.
430 *
431 * @param format A format specification in UTF-8.
432 *
433 * @param tm A broken-down time.
434 *
435 * @return A newly allocated string on success, or NULL otherwise.
436 */
437/* gchar *qof_format_time(const gchar *format, const struct tm *tm); */
438
453gsize qof_strftime(gchar *buf, gsize max, const gchar *format,
454 const struct tm *tm);
455
471size_t qof_print_date_dmy_buff (gchar * buff, size_t buflen, int day, int month, int year);
472
474size_t qof_print_date_buff (char * buff, size_t buflen, time64 secs);
475
477size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd);
478
482char * qof_print_date (time64 secs);
483
484
485gchar* gnc_date_interval_format (time64 from_date, time64 to_date);
486
487/* ------------------------------------------------------------------ */
488/* time printing utilities */
489
494size_t qof_print_date_time_buff (char * buff, size_t len, time64 secs);
495
509gboolean qof_scan_date (const char *buff, int *day, int *month, int *year);
510
511// @}
512
513/* ======================================================== */
514
518// @{
519
524static inline
525void gnc_tm_set_day_start (struct tm *tm)
526{
527 /* First second of the day */
528 g_return_if_fail (tm != NULL);
529 tm->tm_hour = 0;
530 tm->tm_min = 0;
531 tm->tm_sec = 0;
532}
533
537void gnc_tm_set_day_neutral (struct tm *tm);
538
543static inline
544void gnc_tm_set_day_middle (struct tm *tm)
545{
546 /* First second of the day */
547 g_return_if_fail (tm != NULL);
548 tm->tm_hour = 12;
549 tm->tm_min = 0;
550 tm->tm_sec = 0;
551}
552
557static inline
558void gnc_tm_set_day_end (struct tm *tm)
559{
560 /* Last second of the day */
561 g_return_if_fail (tm != NULL);
562 tm->tm_hour = 23;
563 tm->tm_min = 59;
564 tm->tm_sec = 59;
565}
566
570
574
578
580int gnc_date_get_last_mday (int month, int year);
581
582// @}
583
584/* ======================================================== */
585
587// @{
590void gnc_tm_get_today_start(struct tm *tm);
591
594void gnc_tm_get_today_neutral(struct tm *tm);
595
598void gnc_tm_get_today_end(struct tm *tm);
599
603
607
611char * gnc_date_timestamp (void);
612
613#define MIN_BUF_LEN 10
619void gnc_dow_abbrev(gchar *buf, int buf_len, int dow);
620
622
623/* ======================================================== */
624
626// @{
627
630gint gnc_gdate_equal(gconstpointer gda, gconstpointer gdb);
631
632
635guint gnc_gdate_hash( gconstpointer gd );
636
638
639/* ======================================================== */
640
642// @{
647GDate time64_to_gdate (time64 t);
648
652time64 gnc_time64_get_day_start_gdate (const GDate *date);
653
657time64 gnc_time64_get_day_end_gdate (const GDate *date);
658
660
661/* ======================================================== */
662
664// @{
665
671void gnc_gdate_set_month_start (GDate *date);
672
673
679void gnc_gdate_set_month_end (GDate *date);
680
681
688void gnc_gdate_set_prev_month_start (GDate *date);
689
690
697void gnc_gdate_set_prev_month_end (GDate *date);
698
699
705void gnc_gdate_set_quarter_start (GDate *date);
706
707
713void gnc_gdate_set_quarter_end (GDate *date);
714
715
722void gnc_gdate_set_prev_quarter_start (GDate *date);
723
724
731void gnc_gdate_set_prev_quarter_end (GDate *date);
732
733
739void gnc_gdate_set_year_start (GDate *date);
740
741
747void gnc_gdate_set_year_end (GDate *date);
748
749
756void gnc_gdate_set_prev_year_start (GDate *date);
757
758
765void gnc_gdate_set_prev_year_end (GDate *date);
766
767
777void gnc_gdate_set_fiscal_year_start (GDate *date, const GDate *year_end);
778
779
789void gnc_gdate_set_fiscal_year_end (GDate *date, const GDate *year_end);
790
791
801void gnc_gdate_set_prev_fiscal_year_start (GDate *date, const GDate *year_end);
802
803
813void gnc_gdate_set_prev_fiscal_year_end (GDate *date, const GDate *year_end);
814
816
818#ifdef __cplusplus
819}
820#endif
821
822#endif /* GNC_DATE_H */
time64 gnc_mktime(struct tm *time)
calculate seconds from the epoch given a time struct
Definition gnc-date.cpp:219
int gnc_date_get_last_mday(int month, int year)
Get the numerical last date of the month.
Definition gnc-date.cpp:413
void gnc_tm_set_day_neutral(struct tm *tm)
The gnc_tm_set_day_neutral() inline routine will set the appropriate fields in the struct tm to indic...
gboolean gnc_date_string_to_monthformat(const gchar *format_string, GNCDateMonthFormat *format)
Converts the month format to a printable string.
gint gnc_gdate_equal(gconstpointer gda, gconstpointer gdb)
Compares two GDate*'s for equality; useful for using GDate*'s as GHashTable keys.
void gnc_gdate_set_prev_year_end(GDate *date)
This function modifies a GDate to set it to the last day of the year prior to the one in which it fal...
void gnc_gdate_set_year_end(GDate *date)
This function modifies a GDate to set it to the last day of the year in which it falls.
time64 gnc_timegm(struct tm *time)
calculate seconds from the epoch given a time struct
Definition gnc-date.cpp:235
void qof_date_format_set(QofDateFormat df)
The qof_date_format_set() routine sets date format to one of US, UK, CE, OR ISO.
Definition gnc-date.cpp:433
const gchar * qof_date_text_format_get_string(QofDateFormat df)
This function returns a strftime formatting string for printing a date using words and numbers (e....
Definition gnc-date.cpp:525
gdouble gnc_difftime(const time64 secs1, const time64 secs2)
Find the difference in seconds between two time values (deprecated)
Definition gnc-date.cpp:272
void gnc_gdate_set_prev_month_end(GDate *date)
This function modifies a GDate to set it to the last day of the month prior to the one in which it fa...
gchar * gnc_time64_to_iso8601_buff(time64, char *buff)
The gnc_time64_to_iso8601_buff() routine takes the input UTC time64 value and prints it as an ISO-860...
void gnc_gdate_set_year_start(GDate *date)
This function modifies a GDate to set it to the first day of the year in which it falls.
size_t qof_print_date_time_buff(char *buff, size_t len, time64 secs)
Returns the number of bytes printed.
void gnc_dow_abbrev(gchar *buf, int buf_len, int dow)
Localized DOW abbreviation.
time64 gnc_dmy2time64_end(gint day, gint month, gint year)
Same as gnc_dmy2time64, but last second of the day.
gchar * gnc_ctime(const time64 *secs)
Return a string representation of a date from a 64-bit time value.
Definition gnc-date.cpp:256
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.
Definition gnc-date.cpp:115
gchar dateSeparator(void)
dateSeparator Return the field separator for the current date format
Definition gnc-date.cpp:999
void qof_date_completion_set(QofDateCompletion dc, int backmonths)
The qof_date_completion_set() routing sets the date completion method to one of QOF_DATE_COMPLETION_T...
Definition gnc-date.cpp:468
void gnc_gdate_set_time64(GDate *gd, time64 time)
Set a GDate to a time64.
guint gnc_gdate_hash(gconstpointer gd)
Provides a "hash" of a GDate* value; useful for using GDate*'s as GHashTable keys.
void gnc_tm_get_today_neutral(struct tm *tm)
The gnc_tm_get_today_start() routine takes a pointer to a struct tm and fills it in with the timezone...
gboolean qof_scan_date(const char *buff, int *day, int *month, int *year)
qof_scan_date Convert a string into day / month / year integers according to the current dateFormat v...
Definition gnc-date.cpp:991
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
size_t qof_print_date_dmy_buff(gchar *buff, size_t buflen, int day, int month, int year)
qof_print_date_dmy_buff Convert a date as day / month / year integers into a localized string represe...
QofDateFormat qof_date_format_get(void)
The qof_date_format_get routine returns the date format that the date printing will use when printing...
Definition gnc-date.cpp:428
void gnc_gdate_set_prev_year_start(GDate *date)
This function modifies a GDate to set it to the first day of the year prior to the one in which it fa...
gboolean gnc_date_string_to_dateformat(const gchar *format_string, QofDateFormat *format)
Converts the date format to a printable string.
time64 gnc_dmy2time64_neutral(gint day, gint month, gint year)
Converts a day, month, and year to a time64 representing 11:00:00 UTC 11:00:00 UTC falls on the same ...
void gnc_gdate_set_quarter_start(GDate *date)
This function modifies a GDate to set it to the first day of the quarter in which it falls.
size_t qof_print_date_buff(char *buff, size_t buflen, time64 secs)
Convenience: calls through to qof_print_date_dmy_buff().
Definition gnc-date.cpp:574
time64 gnc_time64_get_day_neutral(time64 time_val)
The gnc_time64_get_day_neutral() routine will take the given time in seconds and adjust it to 10:59:0...
char * qof_print_date(time64 secs)
Convenience; calls through to qof_print_date_dmy_buff().
Definition gnc-date.cpp:610
GNCDateMonthFormat
This is how to format the month, as a number, an abbreviated string, or the full name.
Definition gnc-date.h:149
time64 gnc_time64_get_day_start(time64 time_val)
The gnc_time64_get_day_start() routine will take the given time in seconds and adjust it to the first...
GDate * gnc_g_date_new_today(void)
Returns a newly allocated date of the current clock time, taken from time(2).
time64 gnc_time64_get_today_start(void)
The gnc_time64_get_today_start() routine returns a time64 value corresponding to the first second of ...
QofDateFormat
Enum for determining a date format.
Definition gnc-date.h:123
time64 gnc_time64_get_day_end(time64 time_val)
The gnc_time64_get_day_end() routine will take the given time in seconds and adjust it to the last se...
void gnc_gdate_set_quarter_end(GDate *date)
This function modifies a GDate to set it to the last day of the quarter in which it falls.
void gnc_gdate_set_fiscal_year_start(GDate *date, const GDate *year_end)
This function modifies a GDate to set it to the first day of the fiscal year in which it falls.
void gnc_tm_get_today_end(struct tm *tm)
The gnc_tm_get_today_end() routine takes a pointer to a struct tm and fills it in with the last secon...
const gchar * gnc_date_dateformat_to_string(QofDateFormat format)
The string->value versions return FALSE on success and TRUE on failure.
Definition gnc-date.cpp:281
void gnc_gdate_set_prev_quarter_end(GDate *date)
This function modifies a GDate to set it to the last day of the quarter prior to the one in which it ...
void gnc_gdate_set_month_start(GDate *date)
This function modifies a GDate to set it to the first day of the month in which it falls.
gint gnc_start_of_week(void)
returns an integer corresponding to locale start of week
Definition gnc-date.cpp:195
void gnc_gdate_set_prev_fiscal_year_start(GDate *date, const GDate *year_end)
This function modifies a GDate to set it to the first day of the fiscal year prior to the one in whic...
void gnc_gdate_set_today(GDate *gd)
Set a GDate to the current day.
char * gnc_print_time64(time64 time, const char *format)
print a time64 as a date string per format
Definition gnc-date.cpp:370
QofDateCompletion
Enum for date completion modes (for dates entered without year)
Definition gnc-date.h:139
time64 gdate_to_time64(GDate d)
Turns a GDate into a time64, returning the first second of the day.
void gnc_tm_free(struct tm *time)
free a struct tm* created with gnc_localtime() or gnc_gmtime()
Definition gnc-date.cpp:97
GDate time64_to_gdate(time64 t)
Returns the GDate in which the time64 occurs.
void gnc_gdate_set_prev_quarter_start(GDate *date)
This function modifies a GDate to set it to the first day of the quarter prior to the one in which it...
time64 gnc_time(time64 *tbuf)
get the current time
Definition gnc-date.cpp:262
struct tm * gnc_localtime(const time64 *secs)
fill out a time struct from a 64-bit time value.
Definition gnc-date.cpp:103
const gchar * qof_date_format_get_string(QofDateFormat df)
This function returns a strftime formatting string for printing an all numeric date (e....
Definition gnc-date.cpp:502
void gnc_gdate_set_month_end(GDate *date)
This function modifies a GDate to set it to the last day of the month in which it falls.
time64 gnc_time64_get_day_end_gdate(const GDate *date)
The gnc_time64_get_day_end() routine will take the given time in GLib GDate format and adjust it to t...
struct tm * gnc_gmtime(const time64 *secs)
fill out a time struct from a 64-bit time value
Definition gnc-date.cpp:178
size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd)
Convenience; calls through to qof_print_date_dmy_buff().
Definition gnc-date.cpp:598
time64 gnc_time64_get_day_start_gdate(const GDate *date)
The gnc_time64_get_day_start() routine will take the given time in GLib GDate format and adjust it to...
const char * gnc_default_strftime_date_format
The default date format for use with strftime.
Definition gnc-date.cpp:74
time64 gnc_iso8601_to_time64_gmt(const gchar *)
The gnc_iso8601_to_time64_gmt() routine converts an ISO-8601 style date/time string to time64.
time64 time64CanonicalDayTime(time64 t)
convert a time64 on a certain day (localtime) to the time64 representing midday on that day.
Definition gnc-date.cpp:404
void gnc_gdate_set_fiscal_year_end(GDate *date, const GDate *year_end)
This function modifies a GDate to set it to the last day of the fiscal year in which it falls.
void gnc_tm_get_today_start(struct tm *tm)
The gnc_tm_get_today_start() routine takes a pointer to a struct tm and fills it in with the first se...
time64 gnc_time64_get_today_end(void)
The gnc_time64_get_today_end() routine returns a time64 value corresponding to the last second of tod...
time64 gnc_dmy2time64(gint day, gint month, gint year)
Convert a day, month, and year to a time64, returning the first second of the day.
gsize qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
qof_strftime calls qof_format_time to print a given time and afterwards tries to put the result into ...
void gnc_gdate_set_prev_month_start(GDate *date)
This function modifies a GDate to set it to the first day of the month prior to the one in which it f...
char * gnc_date_timestamp(void)
Make a timestamp in YYYYMMDDHHMMSS format.
void gnc_gdate_set_prev_fiscal_year_end(GDate *date, const GDate *year_end)
This function modifies a GDate to set it to the last day of the fiscal year prior to the one in which...
@ QOF_DATE_FORMAT_US
United states: mm/dd/yyyy.
Definition gnc-date.h:124
@ QOF_DATE_FORMAT_LOCALE
Take from locale information.
Definition gnc-date.h:128
@ QOF_DATE_FORMAT_UNSET
No Fancy Date Format, use Global.
Definition gnc-date.h:131
@ QOF_DATE_FORMAT_UTC
UTC: 2004-12-12T23:39:11Z.
Definition gnc-date.h:129
@ QOF_DATE_FORMAT_CE
Continental Europe: dd.mm.yyyy.
Definition gnc-date.h:126
@ QOF_DATE_FORMAT_UK
Britain: dd/mm/yyyy.
Definition gnc-date.h:125
@ QOF_DATE_FORMAT_CUSTOM
Used by the check printing code.
Definition gnc-date.h:130
@ QOF_DATE_FORMAT_ISO
ISO: yyyy-mm-dd.
Definition gnc-date.h:127
@ QOF_DATE_COMPLETION_THISYEAR
use current year
Definition gnc-date.h:140
@ QOF_DATE_COMPLETION_SLIDING
use sliding 12-month window
Definition gnc-date.h:141