* timezone offsets
@ 2006-06-22 15:57 Aaron VanDevender
2006-06-22 16:28 ` Aaron VanDevender
0 siblings, 1 reply; 4+ messages in thread
From: Aaron VanDevender @ 2006-06-22 15:57 UTC (permalink / raw)
Cc: guile-sources
I notice that if I run:
$ guile -c '(display (strftime "%c %z\n" (localtime (current-time))))'
Thu Jun 22 10:51:21 2006 +0500
But I live at -0500 (CDT), not +500. The following patch fixes it:
Index: stime.c
===================================================================
RCS file: /sources/guile/guile/guile-core/libguile/stime.c,v
retrieving revision 1.108
diff -u -r1.108 stime.c
--- stime.c 17 Apr 2006 00:05:41 -0000 1.108
+++ stime.c 22 Jun 2006 15:53:13 -0000
@@ -498,7 +498,7 @@
lt->tm_yday = scm_to_int (SCM_SIMPLE_VECTOR_REF (sbd_time, 7));
lt->tm_isdst = scm_to_int (SCM_SIMPLE_VECTOR_REF (sbd_time, 8));
#ifdef HAVE_TM_ZONE
- lt->tm_gmtoff = scm_to_int (SCM_SIMPLE_VECTOR_REF (sbd_time, 9));
+ lt->tm_gmtoff = - scm_to_int (SCM_SIMPLE_VECTOR_REF (sbd_time, 9));
if (scm_is_false (SCM_SIMPLE_VECTOR_REF (sbd_time, 10)))
lt->tm_zone = NULL;
else
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: timezone offsets
2006-06-22 15:57 timezone offsets Aaron VanDevender
@ 2006-06-22 16:28 ` Aaron VanDevender
2007-01-29 18:38 ` clemens fischer
0 siblings, 1 reply; 4+ messages in thread
From: Aaron VanDevender @ 2006-06-22 16:28 UTC (permalink / raw)
Cc: guile-sources
On Thu, 2006-06-22 at 10:57 -0500, Aaron VanDevender wrote:
> I notice that if I run:
>
> $ guile -c '(display (strftime "%c %z\n" (localtime (current-time))))'
> Thu Jun 22 10:51:21 2006 +0500
On second thought, I think this patch is better since in keeps the
scheme and C representations of the tm structure consistent, and it also
removes the offset calculation redundancy.
Index: stime.c
===================================================================
RCS file: /sources/guile/guile/guile-core/libguile/stime.c,v
retrieving revision 1.108
diff -u -r1.108 stime.c
--- stime.c 17 Apr 2006 00:05:41 -0000 1.108
+++ stime.c 22 Jun 2006 16:26:36 -0000
@@ -355,6 +355,24 @@
}
}
+/* Calculate timezone offset in seconds east of UTC */
+static int
+getzoff (struct tm *lt, struct tm *utc)
+{
+ int zoff;
+ zoff = (lt->tm_hour - utc->tm_hour) * 3600 + (lt->tm_min - utc->tm_min) * 60
+ + lt->tm_sec - utc->tm_sec;
+ if (utc->tm_year < lt->tm_year)
+ zoff += 24 * 60 * 60;
+ else if (utc->tm_year > lt->tm_year)
+ zoff -= 24 * 60 * 60;
+ else if (utc->tm_yday < lt->tm_yday)
+ zoff += 24 * 60 * 60;
+ else if (utc->tm_yday > lt->tm_yday)
+ zoff -= 24 * 60 * 60;
+ return zoff;
+}
+
SCM_DEFINE (scm_localtime, "localtime", 1, 1, 0,
(SCM time, SCM zone),
"Return an object representing the broken down components of\n"
@@ -367,7 +385,6 @@
timet itime;
struct tm *ltptr, lt, *utc;
SCM result;
- int zoff;
char *zname = 0;
char **oldenv;
int err;
@@ -416,19 +433,7 @@
if (utc == NULL || ltptr == NULL)
SCM_SYSERROR;
- /* calculate timezone offset in seconds west of UTC. */
- zoff = (utc->tm_hour - lt.tm_hour) * 3600 + (utc->tm_min - lt.tm_min) * 60
- + utc->tm_sec - lt.tm_sec;
- if (utc->tm_year < lt.tm_year)
- zoff -= 24 * 60 * 60;
- else if (utc->tm_year > lt.tm_year)
- zoff += 24 * 60 * 60;
- else if (utc->tm_yday < lt.tm_yday)
- zoff -= 24 * 60 * 60;
- else if (utc->tm_yday > lt.tm_yday)
- zoff += 24 * 60 * 60;
-
- result = filltime (<, zoff, zname);
+ result = filltime (<, getzoff(<, utc), zname);
SCM_CRITICAL_SECTION_END;
if (zname)
free (zname);
@@ -520,7 +525,6 @@
timet itime;
struct tm lt, *utc;
SCM result;
- int zoff;
char *zname = 0;
char **oldenv;
int err;
@@ -559,7 +563,6 @@
strcpy (zname, ptr);
}
- /* get timezone offset in seconds west of UTC. */
/* POSIX says gmtime sets errno, but C99 doesn't say that.
Give a sensible default value in case gmtime doesn't set it. */
errno = EINVAL;
@@ -573,19 +576,8 @@
if (utc == NULL || itime == -1)
SCM_SYSERROR;
- zoff = (utc->tm_hour - lt.tm_hour) * 3600 + (utc->tm_min - lt.tm_min) * 60
- + utc->tm_sec - lt.tm_sec;
- if (utc->tm_year < lt.tm_year)
- zoff -= 24 * 60 * 60;
- else if (utc->tm_year > lt.tm_year)
- zoff += 24 * 60 * 60;
- else if (utc->tm_yday < lt.tm_yday)
- zoff -= 24 * 60 * 60;
- else if (utc->tm_yday > lt.tm_yday)
- zoff += 24 * 60 * 60;
-
result = scm_cons (scm_from_long (itime),
- filltime (<, zoff, zname));
+ filltime (<, getzoff(<, utc), zname));
if (zname)
free (zname);
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: timezone offsets
2006-06-22 16:28 ` Aaron VanDevender
@ 2007-01-29 18:38 ` clemens fischer
2007-01-30 0:07 ` Kevin Ryde
0 siblings, 1 reply; 4+ messages in thread
From: clemens fischer @ 2007-01-29 18:38 UTC (permalink / raw)
To: guile-user
On Thu, 22 Jun 2006 11:28:04 -0500 Aaron VanDevender wrote:
> On Thu, 2006-06-22 at 10:57 -0500, Aaron VanDevender wrote:
>> I notice that if I run:
>>
>> $ guile -c '(display (strftime "%c %z\n" (localtime (current-time))))'
>> Thu Jun 22 10:51:21 2006 +0500
>
> On second thought, I think this patch is better since in keeps the
> scheme and C representations of the tm structure consistent, and it also
> removes the offset calculation redundancy.
>
> Index: stime.c
> ===================================================================
> RCS file: /sources/guile/guile/guile-core/libguile/stime.c,v
> retrieving revision 1.108
> diff -u -r1.108 stime.c
> --- stime.c 17 Apr 2006 00:05:41 -0000 1.108
> +++ stime.c 22 Jun 2006 16:26:36 -0000
i just checked "guile-1.8.1/libguile/stime.c", which doesn't have this
patch, although the bug didn't get fixed:
$ guile -c '(display (strftime "%c %z\n" (localtime (current-time))))'
Mon Jan 29 19:31:28 2007 -0100
$ date
Mon Jan 29 19:33:27 CET 2007
CET == +0100 in winter.
regards, clemens
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: timezone offsets
2007-01-29 18:38 ` clemens fischer
@ 2007-01-30 0:07 ` Kevin Ryde
0 siblings, 0 replies; 4+ messages in thread
From: Kevin Ryde @ 2007-01-30 0:07 UTC (permalink / raw)
To: clemens fischer; +Cc: guile-user
ino-news@spotteswoode.dnsalias.org (clemens fischer) writes:
>
> i just checked "guile-1.8.1/libguile/stime.c", which doesn't have this
> patch,
I applied Aaron VanDevender's prior one.
> $ guile -c '(display (strftime "%c %z\n" (localtime (current-time))))'
> Mon Jan 29 19:31:28 2007 -0100
I believe it's in 1.8.1, if you'd like to check the version you're
running.
(I suppose I should put it in the 1.6 branch too. And I think it
missed out on an NEWS entry either way.)
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-01-30 0:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-22 15:57 timezone offsets Aaron VanDevender
2006-06-22 16:28 ` Aaron VanDevender
2007-01-29 18:38 ` clemens fischer
2007-01-30 0:07 ` Kevin Ryde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).