GnuCash
5.6-150-g038405b370+
|
Utility functions to handle date and time (adjusting, getting the current date, printing the date and time, etc.) More...
Files | |
file | gnc-date.h |
Date and Time handling routines. | |
Data Structures | |
struct | Time64 |
Macros | |
#define | MAX_DATE_LENGTH 34 |
The maximum length of a string created by the date printers. | |
#define | QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ" |
Constants. More... | |
#define | DATE_FORMAT_FIRST QOF_DATE_FORMAT_US |
#define | DATE_FORMAT_LAST QOF_DATE_FORMAT_UTC |
Typedefs | |
typedef gint64 | time64 |
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux, support 64-bit time_t even on 32-bit architectures. More... | |
Enumerations | |
enum | QofDateFormat { QOF_DATE_FORMAT_US, QOF_DATE_FORMAT_UK, QOF_DATE_FORMAT_CE, QOF_DATE_FORMAT_ISO, QOF_DATE_FORMAT_LOCALE, QOF_DATE_FORMAT_UTC, QOF_DATE_FORMAT_CUSTOM, QOF_DATE_FORMAT_UNSET } |
Enum for determining a date format. More... | |
enum | QofDateCompletion { QOF_DATE_COMPLETION_THISYEAR, QOF_DATE_COMPLETION_SLIDING } |
Enum for date completion modes (for dates entered without year) More... | |
enum | GNCDateMonthFormat { GNCDATE_MONTH_NUMBER, GNCDATE_MONTH_ABBREV, GNCDATE_MONTH_NAME } |
This is how to format the month, as a number, an abbreviated string, or the full name. | |
Functions | |
struct tm * | gnc_localtime (const time64 *secs) |
fill out a time struct from a 64-bit time value. More... | |
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. More... | |
struct tm * | gnc_gmtime (const time64 *secs) |
fill out a time struct from a 64-bit time value More... | |
gint | gnc_start_of_week (void) |
returns an integer corresponding to locale start of week More... | |
time64 | gnc_mktime (struct tm *time) |
calculate seconds from the epoch given a time struct More... | |
time64 | gnc_timegm (struct tm *time) |
calculate seconds from the epoch given a time struct More... | |
gchar * | gnc_ctime (const time64 *secs) |
Return a string representation of a date from a 64-bit time value. More... | |
time64 | gnc_time (time64 *tbuf) |
get the current time More... | |
gdouble | gnc_difftime (const time64 secs1, const time64 secs2) |
Find the difference in seconds between two time values (deprecated) More... | |
void | gnc_tm_free (struct tm *time) |
free a struct tm* created with gnc_localtime() or gnc_gmtime() More... | |
time64 | time64CanonicalDayTime (time64 t) |
convert a time64 on a certain day (localtime) to the time64 representing midday on that day. More... | |
time64 | gdate_to_time64 (GDate d) |
Turns a GDate into a time64, returning the first second of the day. | |
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. | |
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 time in almost all timezones, the exceptions being the +13, +14, and -12 timezones used by countries along the International Date Line. More... | |
time64 | gnc_dmy2time64_end (gint day, gint month, gint year) |
Same as gnc_dmy2time64, but last second of the day. | |
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. More... | |
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-8601 style string. More... | |
Variables | |
const char * | gnc_default_strftime_date_format |
The default date format for use with strftime. More... | |
GValue | |
GType | time64_get_type (void) |
#define | GNC_TYPE_TIME64 (time64_get_type ()) |
String / DateFormat conversion. | |
const gchar * | gnc_date_dateformat_to_string (QofDateFormat format) |
The string->value versions return FALSE on success and TRUE on failure. | |
gboolean | gnc_date_string_to_dateformat (const gchar *format_string, QofDateFormat *format) |
Converts the date format to a printable string. More... | |
const gchar * | gnc_date_monthformat_to_string (GNCDateMonthFormat format) |
gboolean | gnc_date_string_to_monthformat (const gchar *format_string, GNCDateMonthFormat *format) |
Converts the month format to a printable string. More... | |
char * | gnc_print_time64 (time64 time, const char *format) |
print a time64 as a date string per format More... | |
GDate time64 setters | |
GDate * | gnc_g_date_new_today (void) |
Returns a newly allocated date of the current clock time, taken from time(2). More... | |
void | gnc_gdate_set_today (GDate *gd) |
Set a GDate to the current day. More... | |
void | gnc_gdate_set_time64 (GDate *gd, time64 time) |
Set a GDate to a time64. More... | |
Utility functions to handle date and time (adjusting, getting the current date, printing the date and time, etc.)
Overall, this file is quite a mess.
An important note about time-keeping: The general goal of any program that works with numeric time values SHOULD BE to always stores and use UNIVERSAL TIME internally. Universal time is the 'one true time' that is independent of one's location on planet Earth. It is measured in seconds from midnight January 1, 1970 in localtime-Greenwich (GMT). If one wants to display the local time, then the display-print routine should make all final tweaks to print the local time. The local time must not be kept as a numeric value anywhere in the program. If one wants to parse a user's input string as if it were local time, then the output of the parse routine MUST BE universal time. A sane program must never ever store (to file or db) a time that is not Universal Time. Break these rules, and you will rue the day...
(to be renamed qofdate.h in libqof2.)
#define QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ" |
Constants.
UTC date format string.
Time zone independent, date and time inclusive, as used in the QSF backend. The T and Z characters are from xsd:dateTime format in coordinated universal time, UTC. You can reproduce the string from the GNU/Linux command line using the date utility: date -u +Y-m-dTH:M:SZ = 2004-12-12T23:39:11Z The datestring must be time zone independent and include all specified fields. Remember to use gmtime() NOT localtime()!
Definition at line 119 of file gnc-date.h.
typedef gint64 time64 |
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux, support 64-bit time_t even on 32-bit architectures.
See https://en.wikipedia.org/wiki/Year_2038_problem
For practical reasons – as not all have made the transition to 64-bit – we define our own 64-bit time type.
Definition at line 87 of file gnc-date.h.
enum QofDateCompletion |
Enum for date completion modes (for dates entered without year)
Enumerator | |
---|---|
QOF_DATE_COMPLETION_THISYEAR | use current year |
QOF_DATE_COMPLETION_SLIDING | use sliding 12-month window |
Definition at line 138 of file gnc-date.h.
enum QofDateFormat |
Enum for determining a date format.
Definition at line 122 of file gnc-date.h.
gchar* gnc_ctime | ( | const time64 * | secs | ) |
Return a string representation of a date from a 64-bit time value.
secs | Seconds since 00:00:00 UTC 01 January 1970 (negative values are seconds before that moment) |
Definition at line 255 of file gnc-date.cpp.
gboolean gnc_date_string_to_dateformat | ( | const gchar * | format_string, |
QofDateFormat * | format | ||
) |
Converts the date format to a printable string.
Note the reversed return values!
gboolean gnc_date_string_to_monthformat | ( | const gchar * | format_string, |
GNCDateMonthFormat * | format | ||
) |
Converts the month format to a printable string.
Note the reversed return values!
Find the difference in seconds between two time values (deprecated)
secs1 | The first time value, in Seconds since 00:00:00 UTC 01 January 1970 (negative values are seconds before that moment) |
secs2 | The second time value, in Seconds since 00:00:00 UTC 01 January 1970 (negative values are seconds before that moment) |
Definition at line 271 of file gnc-date.cpp.
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 time in almost all timezones, the exceptions being the +13, +14, and -12 timezones used by countries along the International Date Line.
Since users in those timezones would see dates immediately change by one day, the function checks the current timezone for those changes and adjusts the UTC time so that the date will be consistent.
GDate* gnc_g_date_new_today | ( | void | ) |
Returns a newly allocated date of the current clock time, taken from time(2).
The caller must g_date_free() the object afterwards.
Definition at line 1225 of file gnc-date.cpp.
void gnc_gdate_set_time64 | ( | GDate * | gd, |
time64 | time | ||
) |
Set a GDate to a time64.
gd | the date to act on |
time | the time to set it to. |
Definition at line 1244 of file gnc-date.cpp.
void gnc_gdate_set_today | ( | GDate * | gd | ) |
Set a GDate to the current day.
gd | The date to act on |
Definition at line 1236 of file gnc-date.cpp.
struct tm* gnc_gmtime | ( | const time64 * | secs | ) |
fill out a time struct from a 64-bit time value
secs | Seconds since 00:00:00 UTC 01 January 1970 (negative values are seconds before that moment) |
Definition at line 177 of file gnc-date.cpp.
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.
Please note that ISO-8601 strings are a representation of Universal Time (UTC), and as such, they 'store' UTC. To make them human readable, they show time zone information along with a local-time string. But fundamentally, they are UTC. Thus, this routine takes a UTC input, and returns a UTC output.
For example: 1998-07-17 11:00:00.68-0500 is 680 milliseconds after 11 o'clock, central daylight time It is also 680 milliseconds after 16:00:00 hours UTC.
XXX Caution: this routine does not handle strings that specify times before January 1 1970.
struct tm* gnc_localtime | ( | const time64 * | secs | ) |
fill out a time struct from a 64-bit time value.
secs | Seconds since 00:00:00 UTC 01 January 1970 (negative values are seconds before that moment). |
Definition at line 102 of file gnc-date.cpp.
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.
secs | Seconds since 00:00:00 UTC 01 January 1970 (negative values are seconds before that moment) |
time | A struct tm* for the function to fill. The time is adjusted for the current local time zone. |
Definition at line 114 of file gnc-date.cpp.
time64 gnc_mktime | ( | struct tm * | time | ) |
calculate seconds from the epoch given a time struct
time | A struct tm* containing the date-time information. The time is understood to be in the current local time zone. |
Definition at line 218 of file gnc-date.cpp.
char* gnc_print_time64 | ( | time64 | time, |
const char * | format | ||
) |
print a time64 as a date string per format
time | The time64 to print |
format | A date format conforming to the strftime format rules. |
Definition at line 369 of file gnc-date.cpp.
gint gnc_start_of_week | ( | void | ) |
returns an integer corresponding to locale start of week
Definition at line 194 of file gnc-date.cpp.
get the current time
A | time64* which, if not NULL, will be filled in with the same value as is returned. |
Definition at line 261 of file gnc-date.cpp.
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-8601 style string.
The buffer must be long enough to contain the NULL-terminated string (32 characters + NUL). This routine returns a pointer to the null terminator (and can thus be used in the 'stpcpy' metaphor of string concatenation).
Please note that ISO-8601 strings are a representation of Universal Time (UTC), and as such, they 'store' UTC. To make them human readable, they show time zone information along with a local-time string. But fundamentally, they are UTC. Thus, this routine takes a UTC input, and returns a UTC output.
The string generated by this routine uses the local time zone on the machine on which it is executing to create the time string.
Definition at line 1140 of file gnc-date.cpp.
time64 gnc_timegm | ( | struct tm * | time | ) |
calculate seconds from the epoch given a time struct
time | A struct tm* containing the date-time information The time is understood to be utc. |
Definition at line 234 of file gnc-date.cpp.
void gnc_tm_free | ( | struct tm * | time | ) |
free a struct tm* created with gnc_localtime() or gnc_gmtime()
time | The struct tm* to be freed. |
Definition at line 96 of file gnc-date.cpp.
convert a time64 on a certain day (localtime) to the time64 representing midday on that day.
Watch out - this is not the first second of the day, which is returned by various other functions returning a time64.
Definition at line 403 of file gnc-date.cpp.
const char* gnc_default_strftime_date_format |
The default date format for use with strftime.
Definition at line 73 of file gnc-date.cpp.