Convert all time_t to time64: core-utils

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@22618 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
John Ralls 2012-12-01 22:44:22 +00:00
parent 10b567a79a
commit f23eccfcd0
3 changed files with 33 additions and 19 deletions

View File

@ -23,7 +23,6 @@
#include "config.h" #include "config.h"
#include <glib.h> #include <glib.h>
#include <gnc-date.h>
#include "gnc-gdate-utils.h" #include "gnc-gdate-utils.h"
@ -63,25 +62,25 @@ gnc_gdate_hash( gconstpointer gd )
} }
time_t time64
gnc_timet_get_day_start_gdate (GDate *date) gnc_time64_get_day_start_gdate (const GDate *date)
{ {
struct tm stm; struct tm stm;
time_t secs; time64 secs;
/* First convert to a 'struct tm' */ /* First convert to a 'struct tm' */
g_date_to_struct_tm (date, &stm); g_date_to_struct_tm (date, &stm);
/* Then convert to number of seconds */ /* Then convert to number of seconds */
secs = mktime (&stm); secs = gnc_mktime (&stm);
return secs; return secs;
} }
time_t time64
gnc_timet_get_day_end_gdate (GDate *date) gnc_time64_get_day_end_gdate (const GDate *date)
{ {
struct tm stm; struct tm stm;
time_t secs; time64 secs;
/* First convert to a 'struct tm' */ /* First convert to a 'struct tm' */
g_date_to_struct_tm(date, &stm); g_date_to_struct_tm(date, &stm);
@ -93,7 +92,7 @@ gnc_timet_get_day_end_gdate (GDate *date)
stm.tm_isdst = -1; stm.tm_isdst = -1;
/* Then convert to number of seconds */ /* Then convert to number of seconds */
secs = mktime (&stm); secs = gnc_mktime (&stm);
return secs; return secs;
} }

View File

@ -38,6 +38,22 @@
#ifndef GNC_GDATE_UTILS_H #ifndef GNC_GDATE_UTILS_H
#define GNC_GDATE_UTILS_H #define GNC_GDATE_UTILS_H
#include <gnc-date.h>
/** @name GDate time64 setters
@{ */
/** Set a GDate to the current day
* @param theGDate: The date to act on
*/
void gnc_gdate_set_today (GDate* gd);
/** Set a GDate to a time64
* @param theGDate: the date to act on
* @param time: the time to set it to.
*/
void gnc_gdate_set_time64 (GDate* gd, time64 time);
/** @} */
/** @name GDate hash table support /** @name GDate hash table support
@{ */ @{ */
@ -53,18 +69,18 @@ guint gnc_gdate_hash( gconstpointer gd );
/** @} */ /** @} */
/** @name GDate to time_t conversions /** @name GDate to time64 conversions
@{ */ @{ */
/** The gnc_timet_get_day_start() routine will take the given time in /** The gnc_time64_get_day_start() routine will take the given time in
* GLib GDate format and adjust it to the first second of that day. * GLib GDate format and adjust it to the first second of that day.
*/ */
time_t gnc_timet_get_day_start_gdate (GDate *date); time64 gnc_time64_get_day_start_gdate (const GDate *date);
/** The gnc_timet_get_day_end() routine will take the given time in /** The gnc_time64_get_day_end() routine will take the given time in
* GLib GDate format and adjust it to the last second of that day. * GLib GDate format and adjust it to the last second of that day.
*/ */
time_t gnc_timet_get_day_end_gdate (GDate *date); time64 gnc_time64_get_day_end_gdate (const GDate *date);
/** @} */ /** @} */

View File

@ -42,7 +42,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <glib.h> #include <glib.h>
int g_days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int g_days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
@ -179,11 +178,11 @@ int
main(void) main(void)
{ {
int y, m, d; int y, m, d;
time_t bin_time; time64 bin_time;
struct tm *br_time; struct tm *br_time;
time(&bin_time); gnc_time (&bin_time);
br_time = localtime(&bin_time); br_time = gnc_localtime (&bin_time);
gregorian_to_jalali(&y, &m, &d, gregorian_to_jalali(&y, &m, &d,
1900 + br_time->tm_year, 1900 + br_time->tm_year,