mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Create 64-bit time type time64 and replace gint64 with time64
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22615 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -190,7 +190,7 @@ gnc_g_date_time_adjust_for_dst (GDateTime *gdt, GTimeZone *tz)
|
||||
}
|
||||
|
||||
static GDateTime*
|
||||
gnc_g_date_time_new_from_unix_local (gint64 time)
|
||||
gnc_g_date_time_new_from_unix_local (time64 time)
|
||||
{
|
||||
#ifndef G_OS_WIN32
|
||||
return g_date_time_new_from_unix_local (time);
|
||||
@@ -246,7 +246,7 @@ typedef struct
|
||||
{
|
||||
GDateTime *(*new_local)(gint, gint, gint, gint, gint, gdouble);
|
||||
GDateTime *(*adjust_for_dst)(GDateTime *, GTimeZone *);
|
||||
GDateTime *(*new_from_unix_local)(gint64);
|
||||
GDateTime *(*new_from_unix_local)(time64);
|
||||
GDateTime *(*new_from_timeval_local)(const GTimeVal *);
|
||||
GDateTime *(*new_now_local)(void);
|
||||
GDateTime *(*to_local)(GDateTime *);
|
||||
@@ -287,7 +287,7 @@ gnc_g_date_time_fill_struct_tm (GDateTime *gdt, struct tm* time)
|
||||
}
|
||||
|
||||
struct tm*
|
||||
gnc_localtime (const gint64 *secs)
|
||||
gnc_localtime (const time64 *secs)
|
||||
{
|
||||
struct tm *time = g_slice_alloc0 (sizeof (struct tm));
|
||||
if (gnc_localtime_r (secs, time) == NULL)
|
||||
@@ -299,7 +299,7 @@ gnc_localtime (const gint64 *secs)
|
||||
}
|
||||
|
||||
struct tm*
|
||||
gnc_localtime_r (const gint64 *secs, struct tm* time)
|
||||
gnc_localtime_r (const time64 *secs, struct tm* time)
|
||||
{
|
||||
guint index = 0;
|
||||
GDateTime *gdt = gnc_g_date_time_new_from_unix_local (*secs);
|
||||
@@ -323,7 +323,7 @@ gnc_localtime_r (const gint64 *secs, struct tm* time)
|
||||
}
|
||||
|
||||
struct tm*
|
||||
gnc_gmtime (const gint64 *secs)
|
||||
gnc_gmtime (const time64 *secs)
|
||||
{
|
||||
struct tm *time;
|
||||
GDateTime *gdt = g_date_time_new_from_unix_utc (*secs);
|
||||
@@ -361,7 +361,7 @@ normalize_struct_tm (struct tm* time)
|
||||
{
|
||||
gint year = time->tm_year + 1900;
|
||||
gint last_day;
|
||||
gint64 secs;
|
||||
time64 secs;
|
||||
|
||||
++time->tm_mon;
|
||||
|
||||
@@ -386,11 +386,11 @@ normalize_struct_tm (struct tm* time)
|
||||
time->tm_year = year - 1900;
|
||||
}
|
||||
|
||||
gint64
|
||||
time64
|
||||
gnc_mktime (struct tm* time)
|
||||
{
|
||||
GDateTime *gdt;
|
||||
gint64 secs;
|
||||
time64 secs;
|
||||
normalize_struct_tm (time);
|
||||
gdt = gnc_g_date_time_new_local (time->tm_year + 1900, time->tm_mon,
|
||||
time->tm_mday, time->tm_hour,
|
||||
@@ -409,11 +409,11 @@ gnc_mktime (struct tm* time)
|
||||
return secs;
|
||||
}
|
||||
|
||||
gint64
|
||||
time64
|
||||
gnc_timegm (struct tm* time)
|
||||
{
|
||||
GDateTime *gdt;
|
||||
gint64 secs;
|
||||
time64 secs;
|
||||
normalize_struct_tm (time);
|
||||
gdt = g_date_time_new_utc (time->tm_year + 1900, time->tm_mon,
|
||||
time->tm_mday, time->tm_hour, time->tm_min,
|
||||
@@ -429,7 +429,7 @@ gnc_timegm (struct tm* time)
|
||||
}
|
||||
|
||||
gchar*
|
||||
gnc_ctime (const gint64 *secs)
|
||||
gnc_ctime (const time64 *secs)
|
||||
{
|
||||
GDateTime *gdt = gnc_g_date_time_new_from_unix_local (*secs);
|
||||
gchar *string = g_date_time_format (gdt, "%a %b %H:%M:%S %Y");
|
||||
@@ -437,11 +437,22 @@ gnc_ctime (const gint64 *secs)
|
||||
return string;
|
||||
}
|
||||
|
||||
gint64
|
||||
gnc_time (gint64 *tbuf)
|
||||
time64
|
||||
gnc_time (time64 *tbuf)
|
||||
{
|
||||
GDateTime *gdt = gnc_g_date_time_new_now_local ();
|
||||
gint64 secs = g_date_time_to_unix (gdt);
|
||||
time64 secs = g_date_time_to_unix (gdt);
|
||||
g_date_time_unref (gdt);
|
||||
if (tbuf != NULL)
|
||||
*tbuf = secs;
|
||||
return secs;
|
||||
}
|
||||
|
||||
time64
|
||||
gnc_time_utc (time64 *tbuf)
|
||||
{
|
||||
GDateTime *gdt = g_date_time_new_now_utc ();
|
||||
time64 secs = g_date_time_to_unix (gdt);
|
||||
g_date_time_unref (gdt);
|
||||
if (tbuf != NULL)
|
||||
*tbuf = secs;
|
||||
@@ -449,7 +460,7 @@ gnc_time (gint64 *tbuf)
|
||||
}
|
||||
|
||||
gdouble
|
||||
gnc_difftime (const gint64 secs1, const gint64 secs2)
|
||||
gnc_difftime (const time64 secs1, const time64 secs2)
|
||||
{
|
||||
return (double)secs2 - (double)secs1;
|
||||
}
|
||||
@@ -656,7 +667,7 @@ timespecCanonicalDayTime(Timespec t)
|
||||
{
|
||||
struct tm tm;
|
||||
Timespec retval;
|
||||
gint64 t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
|
||||
time64 t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
|
||||
gnc_localtime_r(&t_secs, &tm);
|
||||
gnc_tm_set_day_middle(&tm);
|
||||
retval.tv_sec = gnc_mktime(&tm);
|
||||
@@ -857,7 +868,7 @@ qof_print_date_dmy_buff (char * buff, size_t len, int day, int month, int year)
|
||||
case QOF_DATE_FORMAT_LOCALE:
|
||||
{
|
||||
struct tm tm_str;
|
||||
gint64 t;
|
||||
time64 t;
|
||||
|
||||
tm_str.tm_mday = day;
|
||||
tm_str.tm_mon = month - 1; /* tm_mon = 0 through 11 */
|
||||
@@ -886,10 +897,10 @@ qof_print_date_dmy_buff (char * buff, size_t len, int day, int month, int year)
|
||||
}
|
||||
|
||||
size_t
|
||||
qof_print_date_buff (char * buff, size_t len, gint64 t)
|
||||
qof_print_date_buff (char * buff, size_t len, time64 t)
|
||||
{
|
||||
struct tm theTime;
|
||||
gint64 bt = t;
|
||||
time64 bt = t;
|
||||
size_t actual;
|
||||
if (!buff) return 0 ;
|
||||
if (!gnc_localtime_r(&bt, &theTime))
|
||||
@@ -912,7 +923,7 @@ qof_print_gdate( char *buf, size_t len, const GDate *gd )
|
||||
}
|
||||
|
||||
char *
|
||||
qof_print_date (gint64 t)
|
||||
qof_print_date (time64 t)
|
||||
{
|
||||
char buff[MAX_DATE_LENGTH];
|
||||
memset (buff, 0, sizeof (buff));
|
||||
@@ -924,10 +935,10 @@ const char *
|
||||
gnc_print_date (Timespec ts)
|
||||
{
|
||||
static char buff[MAX_DATE_LENGTH];
|
||||
gint64 t;
|
||||
time64 t;
|
||||
|
||||
memset (buff, 0, sizeof (buff));
|
||||
t = ts.tv_sec + (gint64)(ts.tv_nsec / 1000000000.0);
|
||||
t = ts.tv_sec + (time64)(ts.tv_nsec / 1000000000.0);
|
||||
|
||||
qof_print_date_buff (buff, MAX_DATE_LENGTH, t);
|
||||
|
||||
@@ -981,7 +992,7 @@ qof_scan_date_internal (const char *buff, int *day, int *month, int *year,
|
||||
int iday, imonth, iyear;
|
||||
int now_day, now_month, now_year;
|
||||
struct tm *now, utc;
|
||||
gint64 secs;
|
||||
time64 secs;
|
||||
|
||||
if (!buff) return(FALSE);
|
||||
|
||||
@@ -1238,7 +1249,7 @@ char dateSeparator (void)
|
||||
/* Make a guess */
|
||||
gchar string[256];
|
||||
struct tm tm;
|
||||
gint64 secs;
|
||||
time64 secs;
|
||||
gchar *s;
|
||||
|
||||
secs = gnc_time (NULL);
|
||||
@@ -1479,7 +1490,7 @@ void
|
||||
gnc_timespec2dmy (Timespec t, int *day, int *month, int *year)
|
||||
{
|
||||
struct tm result;
|
||||
gint64 t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
|
||||
time64 t_secs = t.tv_sec + (t.tv_nsec / NANOS_PER_SECOND);
|
||||
gnc_localtime_r(&t_secs, &result);
|
||||
|
||||
if (day) *day = result.tm_mday;
|
||||
@@ -1557,7 +1568,7 @@ gnc_timezone (const struct tm *tm)
|
||||
|
||||
|
||||
void
|
||||
timespecFromTime_t( Timespec *ts, gint64 t )
|
||||
timespecFromTime_t( Timespec *ts, time64 t )
|
||||
{
|
||||
ts->tv_sec = t;
|
||||
ts->tv_nsec = 0;
|
||||
@@ -1572,7 +1583,7 @@ timespec_now()
|
||||
return ts;
|
||||
}
|
||||
|
||||
gint64
|
||||
time64
|
||||
timespecToTime_t (Timespec ts)
|
||||
{
|
||||
return ts.tv_sec;
|
||||
@@ -1617,7 +1628,7 @@ Timespec gdate_to_timespec (GDate d)
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_tm_get_day_start (struct tm *tm, gint64 time_val)
|
||||
gnc_tm_get_day_start (struct tm *tm, time64 time_val)
|
||||
{
|
||||
/* Get the equivalent time structure */
|
||||
if (!gnc_localtime_r(&time_val, tm))
|
||||
@@ -1626,7 +1637,7 @@ gnc_tm_get_day_start (struct tm *tm, gint64 time_val)
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_tm_get_day_end (struct tm *tm, gint64 time_val)
|
||||
gnc_tm_get_day_end (struct tm *tm, time64 time_val)
|
||||
{
|
||||
/* Get the equivalent time structure */
|
||||
if (!gnc_localtime_r(&time_val, tm))
|
||||
@@ -1634,22 +1645,22 @@ gnc_tm_get_day_end (struct tm *tm, gint64 time_val)
|
||||
gnc_tm_set_day_end(tm);
|
||||
}
|
||||
|
||||
gint64
|
||||
gnc_timet_get_day_start (gint64 time_val)
|
||||
time64
|
||||
gnc_timet_get_day_start (time64 time_val)
|
||||
{
|
||||
struct tm tm;
|
||||
gint64 new_time;
|
||||
time64 new_time;
|
||||
|
||||
gnc_tm_get_day_start(&tm, time_val);
|
||||
new_time = gnc_mktime(&tm);
|
||||
return new_time;
|
||||
}
|
||||
|
||||
gint64
|
||||
gnc_timet_get_day_end (gint64 time_val)
|
||||
time64
|
||||
gnc_timet_get_day_end (time64 time_val)
|
||||
{
|
||||
struct tm tm;
|
||||
gint64 new_time;
|
||||
time64 new_time;
|
||||
|
||||
gnc_tm_get_day_end(&tm, time_val);
|
||||
new_time = gnc_mktime(&tm);
|
||||
@@ -1671,7 +1682,7 @@ gnc_tm_get_today_end (struct tm *tm)
|
||||
gnc_tm_get_day_end(tm, time(NULL));
|
||||
}
|
||||
|
||||
gint64
|
||||
time64
|
||||
gnc_timet_get_today_start (void)
|
||||
{
|
||||
struct tm tm;
|
||||
@@ -1680,7 +1691,7 @@ gnc_timet_get_today_start (void)
|
||||
return gnc_mktime(&tm);
|
||||
}
|
||||
|
||||
gint64
|
||||
time64
|
||||
gnc_timet_get_today_end (void)
|
||||
{
|
||||
struct tm tm;
|
||||
|
||||
@@ -71,6 +71,13 @@
|
||||
#include <glib-object.h>
|
||||
#include <time.h>
|
||||
|
||||
/**
|
||||
* Many systems, including Microsoft Windows and BSD-derived Unixes
|
||||
* like Darwin, are retaining the int-32 typedef for time_t. Since
|
||||
* this stops working in 2038, we define our own:
|
||||
*/
|
||||
typedef gint64 time64;
|
||||
|
||||
/** The Timespec is just like the unix 'struct timespec'
|
||||
* except that we use a 64-bit unsigned int to
|
||||
* store the seconds. This should adequately cover dates in the
|
||||
@@ -157,7 +164,7 @@ typedef enum
|
||||
* \return A struct tm*, allocated on the heap. Must be freed with gnc_tm_free().
|
||||
* The time is adjusted for the current local time zone.
|
||||
*/
|
||||
struct tm* gnc_localtime (const gint64 *secs);
|
||||
struct tm* gnc_localtime (const time64 *secs);
|
||||
|
||||
/** \brief fill out a time struct from a 64-bit time value adjusted for the current time zone.
|
||||
* \param secs: Seconds since 00:00:01 UTC 01 January 1970 (negative values
|
||||
@@ -165,7 +172,7 @@ struct tm* gnc_localtime (const gint64 *secs);
|
||||
* \param time: A struct tm* for the function to fill.
|
||||
* The time is adjusted for the current local time zone.
|
||||
*/
|
||||
struct tm* gnc_localtime_r (const gint64 *secs, struct tm* time);
|
||||
struct tm* gnc_localtime_r (const time64 *secs, struct tm* time);
|
||||
|
||||
/** \brief fill out a time struct from a 64-bit time value
|
||||
* \param secs: Seconds since 00:00:01 UTC 01 January 1970 (negative values
|
||||
@@ -173,7 +180,7 @@ struct tm* gnc_localtime_r (const gint64 *secs, struct tm* time);
|
||||
* \return A struct tm*, allocated on the heap. Must be freed with gnc_tm_free()
|
||||
* The time is UTC.
|
||||
*/
|
||||
struct tm* gnc_gmtime (const gint64 *secs);
|
||||
struct tm* gnc_gmtime (const time64 *secs);
|
||||
|
||||
/** \brief calculate seconds from the epoch given a time struct
|
||||
* \param time: A struct tm* for the function to fill.
|
||||
@@ -181,7 +188,7 @@ struct tm* gnc_gmtime (const gint64 *secs);
|
||||
* \return Seconds since 00:00:01 UTC 01 January 1970 (negative values
|
||||
* are seconds before that moment).
|
||||
*/
|
||||
gint64 gnc_mktime (struct tm* time);
|
||||
time64 gnc_mktime (struct tm* time);
|
||||
|
||||
/** \brief calculate seconds from the epoch given a time struct
|
||||
* \param time: A struct tm* for the function to fill.
|
||||
@@ -189,7 +196,7 @@ gint64 gnc_mktime (struct tm* time);
|
||||
* \return Seconds since 00:00:01 UTC 01 January 1970 (negative values
|
||||
* are seconds before that moment).
|
||||
*/
|
||||
gint64 gnc_timegm (struct tm* time);
|
||||
time64 gnc_timegm (struct tm* time);
|
||||
|
||||
/** \brief Return a string representation of a date from a 64-bit time value
|
||||
* \param secs: Seconds since 00:00:01 UTC 01 January 1970 (negative values
|
||||
@@ -199,15 +206,23 @@ gint64 gnc_timegm (struct tm* time);
|
||||
* Thu Nov 24 18:22:48 1986\n\0
|
||||
* This is equivalent to the strftime format %a %b %H:%M:%S %Y.
|
||||
*/
|
||||
gchar* gnc_ctime (const gint64 *secs);
|
||||
gchar* gnc_ctime (const time64 *secs);
|
||||
|
||||
/** \brief get the current local time
|
||||
* \param A gint64* which, if not NULL, will be filled in with the same
|
||||
* \param A time64* which, if not NULL, will be filled in with the same
|
||||
* value as is returned.
|
||||
* \return Seconds since 00:00:01 UTC 01 January 1970 (negative values
|
||||
* are seconds before that moment)
|
||||
*/
|
||||
gint64 gnc_time (gint64 *tbuf);
|
||||
time64 gnc_time (time64 *tbuf);
|
||||
|
||||
/** \brief get the current utc time
|
||||
* \param A time64* which, if not NULL, will be filled in with the same
|
||||
* value as is returned.
|
||||
* \return Seconds since 00:00:01 UTC 01 January 1970 (negative values
|
||||
* are seconds before that moment)
|
||||
*/
|
||||
time64 gnc_time_utc (time64 *tbuf);
|
||||
|
||||
/** \brief Find the difference in seconds between two time values
|
||||
* \param secs1: The first time value, in Seconds since
|
||||
@@ -217,7 +232,7 @@ gint64 gnc_time (gint64 *tbuf);
|
||||
* \return The difference in seconds between secs1 and secs2. If secs1 is
|
||||
* later than secs2 the value will be negative.
|
||||
*/
|
||||
gdouble gnc_difftime (const gint64 secs1, const gint64 secs2);
|
||||
gdouble gnc_difftime (const time64 secs1, const time64 secs2);
|
||||
|
||||
/** \brief free a struct tm* created with gnc_localtime() or gnc_gmtime()
|
||||
* \param time: The struct tm* to be freed.
|
||||
@@ -273,7 +288,7 @@ gboolean gnc_date_string_to_monthformat(const gchar *format_string,
|
||||
#ifndef SWIG /* swig 1.1p5 can't hack the long long type */
|
||||
struct timespec64
|
||||
{
|
||||
gint64 tv_sec;
|
||||
time64 tv_sec;
|
||||
glong tv_nsec;
|
||||
};
|
||||
#endif /* SWIG */
|
||||
@@ -307,11 +322,11 @@ Timespec timespecCanonicalDayTime(Timespec t);
|
||||
/** Returns the current clock time as a Timespec, taken from time(2). */
|
||||
Timespec timespec_now (void);
|
||||
|
||||
/** Turns a gint64 into a Timespec */
|
||||
void timespecFromTime_t( Timespec *ts, gint64 t );
|
||||
/** Turns a time64 into a Timespec */
|
||||
void timespecFromTime_t( Timespec *ts, time64 t );
|
||||
|
||||
/** Turns a Timespec into a gint64 */
|
||||
gint64 timespecToTime_t (Timespec ts);
|
||||
/** Turns a Timespec into a time64 */
|
||||
time64 timespecToTime_t (Timespec ts);
|
||||
|
||||
/** Returns a newly allocated date of the current clock time, taken from
|
||||
* time(2). The caller must g_date_free() the object afterwards. */
|
||||
@@ -504,7 +519,7 @@ gsize qof_strftime(gchar *buf, gsize max, const gchar *format,
|
||||
size_t qof_print_date_dmy_buff (gchar * buff, size_t buflen, int day, int month, int year);
|
||||
|
||||
/** Convenience: calls through to qof_print_date_dmy_buff(). **/
|
||||
size_t qof_print_date_buff (char * buff, size_t buflen, gint64 secs);
|
||||
size_t qof_print_date_buff (char * buff, size_t buflen, time64 secs);
|
||||
|
||||
/** Convenience; calls through to qof_print_date_dmy_buff(). **/
|
||||
size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd);
|
||||
@@ -512,7 +527,7 @@ size_t qof_print_gdate(char *buf, size_t bufflen, const GDate *gd);
|
||||
/** Convenience; calls through to qof_print_date_dmy_buff().
|
||||
* Return: string, which should be freed when no longer needed.
|
||||
* **/
|
||||
char * qof_print_date (gint64 secs);
|
||||
char * qof_print_date (time64 secs);
|
||||
|
||||
/** Convenience; calls through to qof_print_date_dmy_buff().
|
||||
* Return: static global string.
|
||||
@@ -529,7 +544,7 @@ const char * gnc_print_date(Timespec ts);
|
||||
* Returns the number of bytes printed.
|
||||
*/
|
||||
|
||||
size_t qof_print_date_time_buff (char * buff, size_t len, gint64 secs);
|
||||
size_t qof_print_date_time_buff (char * buff, size_t len, time64 secs);
|
||||
|
||||
/** qof_scan_date
|
||||
* Convert a string into day / month / year integers according to
|
||||
@@ -599,11 +614,11 @@ void gnc_tm_set_day_end (struct tm *tm)
|
||||
|
||||
/** The gnc_timet_get_day_start() routine will take the given time in
|
||||
* seconds and adjust it to the last second of that day. */
|
||||
gint64 gnc_timet_get_day_start(gint64 time_val);
|
||||
time64 gnc_timet_get_day_start(time64 time_val);
|
||||
|
||||
/** The gnc_timet_get_day_end() routine will take the given time in
|
||||
* seconds and adjust it to the last second of that day. */
|
||||
gint64 gnc_timet_get_day_end(gint64 time_val);
|
||||
time64 gnc_timet_get_day_end(time64 time_val);
|
||||
|
||||
/** Get the numerical last date of the month. (28, 29, 30, 31) */
|
||||
int gnc_date_get_last_mday (int month, int year);
|
||||
@@ -622,13 +637,13 @@ void gnc_tm_get_today_start(struct tm *tm);
|
||||
* tm and fills it in with the last second of the today. */
|
||||
void gnc_tm_get_today_end(struct tm *tm);
|
||||
|
||||
/** The gnc_timet_get_today_start() routine returns a gint64 value
|
||||
/** The gnc_timet_get_today_start() routine returns a time64 value
|
||||
* corresponding to the first second of today. */
|
||||
gint64 gnc_timet_get_today_start(void);
|
||||
time64 gnc_timet_get_today_start(void);
|
||||
|
||||
/** The gnc_timet_get_today_end() routine returns a gint64 value
|
||||
/** The gnc_timet_get_today_end() routine returns a time64 value
|
||||
* corresponding to the last second of today. */
|
||||
gint64 gnc_timet_get_today_end(void);
|
||||
time64 gnc_timet_get_today_end(void);
|
||||
|
||||
/** \brief Make a timestamp in YYYYMMDDHHMMSS format.
|
||||
* @return A pointer to the generated string.
|
||||
|
||||
Reference in New Issue
Block a user