mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
2001-05-30 Dave Peticolas <dave@krondo.com>
* src/engine/sixtp-utils.c (timespec_secs_to_given_string): use gnc_timezone * src/engine/date.c (gnc_timezone): new func (gnc_iso8601_to_timespec): use gnc_timezone (gnc_timespec_to_iso8601_buff): use gnc_timezone git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4334 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
7d39624cd9
commit
690c0a78db
@ -1,3 +1,12 @@
|
||||
2001-05-30 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* src/engine/sixtp-utils.c (timespec_secs_to_given_string): use
|
||||
gnc_timezone
|
||||
|
||||
* src/engine/date.c (gnc_timezone): new func
|
||||
(gnc_iso8601_to_timespec): use gnc_timezone
|
||||
(gnc_timespec_to_iso8601_buff): use gnc_timezone
|
||||
|
||||
2001-05-29 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* configure.in: call new macro below
|
||||
|
@ -469,7 +469,6 @@ gnc_iso8601_to_timespec(const char *str, int do_localtime)
|
||||
}
|
||||
stm.tm_isdst = -1;
|
||||
|
||||
|
||||
/* timezone format can be +hh or +hhmm or +hh.mm (or -) */
|
||||
str += strcspn (str, "+-");
|
||||
buf[0] = str[0];
|
||||
@ -495,11 +494,13 @@ gnc_iso8601_to_timespec(const char *str, int do_localtime)
|
||||
/* adjust for the local timezone */
|
||||
if (do_localtime)
|
||||
{
|
||||
struct tm *tm;
|
||||
time_t tz_hour = 0;
|
||||
localtime (&tz_hour); /* bogus call, forces 'timezone' to be set */
|
||||
tz_hour = timezone/3600;
|
||||
|
||||
tm = localtime (&tz_hour); /* bogus call, forces 'timezone' to be set */
|
||||
tz_hour = gnc_timezone(tm)/3600;
|
||||
stm.tm_hour -= tz_hour;
|
||||
stm.tm_min -= (timezone - 3600*tz_hour)/60;
|
||||
stm.tm_min -= (gnc_timezone(tm) - 3600*tz_hour)/60;
|
||||
}
|
||||
|
||||
/* compute number of seconds */
|
||||
@ -536,8 +537,8 @@ gnc_timespec_to_iso8601_buff (Timespec ts, char * buff)
|
||||
tmp = ts.tv_sec;
|
||||
localtime_r(&tmp, &parsed);
|
||||
|
||||
tz_hour = timezone/3600;
|
||||
tz_min = (timezone - 3600*tz_hour)/60;
|
||||
tz_hour = gnc_timezone (&parsed) / 3600;
|
||||
tz_min = (gnc_timezone (&parsed) - 3600*tz_hour) / 60;
|
||||
if (0>tz_min) { tz_min +=60; tz_hour --; }
|
||||
|
||||
/* we also have to print the sign by hand, to work around a bug
|
||||
@ -663,5 +664,25 @@ gnc_dmy2timespec_end (int day, int month, int year)
|
||||
return gnc_dmy2timespec_internal (day, month, year, FALSE);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
long int
|
||||
gnc_timezone (struct tm *tm)
|
||||
{
|
||||
g_return_val_if_fail (tm != NULL, 0);
|
||||
|
||||
#ifdef HAVE_STRUCT_TM_GMTOFF
|
||||
/* tm_gmtoff is seconds *east* of UTC and is
|
||||
* already adjusted for daylight savings time. */
|
||||
return -(tm->tm_gmtoff);
|
||||
#else
|
||||
/* timezone is seconds *west* of UTC and is
|
||||
* not adjusted for daylight savings time.
|
||||
* In Spring, we spring forward, wheee! */
|
||||
return timezone - (tm->tm_isdst > 0 ? 60 * 60 : 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/********************** END OF FILE *********************************\
|
||||
\********************************************************************/
|
||||
|
@ -182,4 +182,18 @@ Timespec gnc_iso8601_to_timespec_local(const char *);
|
||||
Timespec gnc_iso8601_to_timespec_gmt(const char *);
|
||||
char * gnc_timespec_to_iso8601_buff (Timespec ts, char * buff);
|
||||
|
||||
/* The gnc_timezone function returns the number of seconds *west*
|
||||
* of UTC represented by the tm argument, adjusted for daylight
|
||||
* savings time.
|
||||
*
|
||||
* This function requires a tm argument returned by localtime or set
|
||||
* by mktime. This is a strange function! It requires that localtime
|
||||
* or mktime be called before use. Subsequent calls to localtime or
|
||||
* mktime *may* invalidate the result! The actual contents of tm *may*
|
||||
* be used for both timezone offset and daylight savings time, or only
|
||||
* daylight savings time! Timezone stuff under unix is not
|
||||
* standardized and is a big mess.
|
||||
*/
|
||||
long int gnc_timezone (struct tm *tm);
|
||||
|
||||
#endif /* __XACC_DATE_H__ */
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "sixtp.h"
|
||||
#include "sixtp-utils.h"
|
||||
|
||||
#include "date.h"
|
||||
#include "guid.h"
|
||||
#include "gnc-numeric.h"
|
||||
|
||||
@ -463,6 +464,7 @@ timespec_secs_to_given_string (const Timespec *ts, gchar *str)
|
||||
struct tm parsed_time;
|
||||
size_t num_chars;
|
||||
time_t tmp_time;
|
||||
long int tz;
|
||||
int minutes;
|
||||
int hours;
|
||||
int sign;
|
||||
@ -482,24 +484,15 @@ timespec_secs_to_given_string (const Timespec *ts, gchar *str)
|
||||
|
||||
str += num_chars;
|
||||
|
||||
/* timezone is reversed */
|
||||
sign = (timezone > 0) ? -1 : 1;
|
||||
tz = gnc_timezone (&parsed_time);
|
||||
|
||||
minutes = ABS (timezone) / 60;
|
||||
/* gnc_timezone is seconds west of UTC */
|
||||
sign = (tz > 0) ? -1 : 1;
|
||||
|
||||
minutes = ABS (tz) / 60;
|
||||
hours = minutes / 60;
|
||||
minutes -= hours * 60;
|
||||
|
||||
if (parsed_time.tm_isdst > 0)
|
||||
hours += sign;
|
||||
|
||||
/* check for rollover */
|
||||
if (hours == -1)
|
||||
{
|
||||
hours = 0;
|
||||
minutes = 60 - minutes;
|
||||
sign *= -1;
|
||||
}
|
||||
|
||||
g_snprintf (str, TIMESPEC_SEC_FORMAT_MAX - num_chars,
|
||||
" %c%02d%02d", (sign > 0) ? '+' : '-', hours, minutes);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user