troglobit / zoo

public domain zoo archive tool
The Unlicense
14 stars 5 forks source link

Adding an argument to gettz() #6

Open Rhialto opened 7 months ago

Rhialto commented 7 months ago

Hi! I was going through some patches for zoo that are present in pkgsrc, to see if they are still needed or not. Many changes relate to removing duplicate declarations of standard functions, and including the appropriate standard header instead. Many of those seem to be left. But of course I got stuck in the third file or so that I looked at with a less trivial change.

There was a patch that changes the body of tzadj() to

void tzadj(direntry)
struct direntry *direntry;
{
    long diff_tz;
    long longtime;
    long t;

    if (direntry->tz == NO_TZ)   /* none stored */
        return;

    t = mstonix (direntry->date, direntry->time);
    diff_tz = (long) direntry->tz * (3600/4) - gettz(t); /* diff. in seconds */
    longtime = t + diff_tz; /* adj tz */
    mstime(longtime, &direntry->date, &direntry->time);
}

The main difference is that gettz() gets an argument. Presumably so that it can calculate the time zone offset related to that particular time, and not that of the current time. That sounds sensible to me.

However in the same patch set I didn't find anything to add this argument to the existing gettz() functions... which is a bit weird.

Since I didn't want to invent new things with this effort, but just contribute still sensible existing patches, I'm bouncing this one to you. It probably makes sense to incorporate this change and create the properly changed gettz() too. And it also likely makes sense to remove the duplicate versions of that function and just settle on one version that simply works for all variants...

Rhialto commented 7 months ago

Another patch related to this:

$NetBSD: patch-ag,v 1.2 2009/04/25 23:46:47 gdt Exp $

--- zooadd2.c.orig  1991-07-20 01:38:10.000000000 +0200
+++ zooadd2.c
@@ -258,12 +258,15 @@ void newdir (direntry)
 register struct direntry *direntry;
 {
 #ifdef GETTZ
+   long mstonix();
    long gettz();
+   long t;
 #endif
    direntry->zoo_tag = ZOO_TAG;
    direntry->type = 2;                  /* type is now 2 */
 #ifdef GETTZ
-   direntry->tz = gettz() / (15 * 60); /* seconds => 15-min units */
+   t = mstonix (direntry->date, direntry->time);
+   direntry->tz = gettz(t) / (15 * 60); /* seconds => 15-min units */
 #else
    direntry->tz = NO_TZ;                /* timezone unknown */
 #endif

and related one for zoolist.c:

@@ -539,10 +549,12 @@ int file_tz;
 {
    long gettz();
    int diff_tz;                /* timezone difference */
+   time_t t;
    if (file_tz == NO_TZ)   /* if no timezone stored ..*/
        printf ("   ");         /* .. just pad with blanks */
    else {
-       diff_tz = (file_tz / 4) - (int) (gettz() / 3600);
+       time(&t);
+       diff_tz = (file_tz / 4) - (int) (gettz(t) / 3600);
        if (diff_tz == 0)
            printf ("   ");                 /* print nothing if same */
        else if (diff_tz > 0)           /* else print signed difference */