🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: best.bugs
Article #46

Re: UNIX date command bug?

#46
From: Smith and O'Halloran
Date: Fri, 23 Oct 1998 00:00
57 lines
3049 bytes
In article <362BDFE5.20DD@---yahoo.com>,
Brian Moriguchi  <freewayjam---@---yahoo.com> wrote:
>Smith and O'Halloran wrote:
>> I don't understand why you reposted this.  As it has been explained
>> before, it is *NOT* a bug.
>
>I know it's not a bug. I wanted to find "go-around" solution for this.

Why didn't you say so in the first place?  It would have helped if you
had said what you were trying to accomplish instead of calling it a bug.

To avoid the Daylight Savings switch, simply calculate the time corresponding
to noon today, and use that as a basis.  Times 24 hours in the future may
correspond to 11am or 1pm, but it will be in the same day.

There is no need to call the Unix `date` command since perl can do all that.

#!/usr/local/bin/perl5
$days = $ARGV[0] || 10;		# Number of days to display
$time_now = time;
($ss,$mm,$hh,$day,$mon0,$year1900,$wday) = localtime($time_now);
# Note: $mon0 ranges from 0 to 11, $wday ranges from 0 to 6.
$seconds_per_hour = 60 * 60;
$seconds_per_day = 24 * $seconds_per_hour;
$time_noon = $time_now - ($hh-12) * $seconds_per_hour - $mm*60 - $ss;

foreach $n (-3 .. $days) {	# 3 days in the past to 10 days in future
  $time_then = $time_noon + $n * $seconds_per_day;
  ($ss,$mm,$hh,$day,$mon0,$year1900,$wday) = localtime($time_then);
  $string = localtime($time_then);	# Returns a string in scalar context
  printf "%02d %02d %02d %d = %s (%d)\n",
	$year1900, $mon0+1, $day, $wday, $string, $n;
}



inwap@shell3% perl5 temp
98 10 20 2 = Tue Oct 20 12:00:00 1998 (-3)
98 10 21 3 = Wed Oct 21 12:00:00 1998 (-2)
98 10 22 4 = Thu Oct 22 12:00:00 1998 (-1)
98 10 23 5 = Fri Oct 23 12:00:00 1998 (0)
98 10 24 6 = Sat Oct 24 12:00:00 1998 (1)
98 10 25 0 = Sun Oct 25 11:00:00 1998 (2)
98 10 26 1 = Mon Oct 26 11:00:00 1998 (3)
98 10 27 2 = Tue Oct 27 11:00:00 1998 (4)
98 10 28 3 = Wed Oct 28 11:00:00 1998 (5)
98 10 29 4 = Thu Oct 29 11:00:00 1998 (6)
98 10 30 5 = Fri Oct 30 11:00:00 1998 (7)
98 10 31 6 = Sat Oct 31 11:00:00 1998 (8)
98 11 01 0 = Sun Nov  1 11:00:00 1998 (9)
98 11 02 1 = Mon Nov  2 11:00:00 1998 (10)

[I've changed the follow-ups to just best.unix since it's not a bug.]
	-Joe
-- 
INWAP.COM is Joe and Sally Smith, John and Chris O'Halloran and our cats
See http://www.inwap.com/ for PDP-10, "ReBoot", "Shadow Raiders"/"War Planets"
Technical Details
Message-ID: <70qjqc$m5$1@shell3.ba.best.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3626F443.73B9@---yahoo.com> <3628494D.6A42@---yahoo.com> <70c9al$or$1@shell3.ba.best.com> <362BDFE5.20DD@---yahoo.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f669e,c2df06ddaa6ba580,start
X-Google-Attributes: gidf669e,public
X-Google-Thread: 112e82,c2df06ddaa6ba580,start
X-Google-Attributes: gid112e82,public
From: inwap@best.com (Smith and O'Halloran)
Subject: Re: UNIX date command bug?
Date: 1998/10/23
Message-ID: <70qjqc$m5$1@shell3.ba.best.com>
X-Deja-AN: 404378411
Distribution: best
References: <3626F443.73B9@---yahoo.com> <3628494D.6A42@---yahoo.com> <70c9al$or$1@shell3.ba.best.com> <362BDFE5.20DD@---yahoo.com>
Followup-To: best.unix
X-Trace: 909169297 6402 inwap 206.184.139.134
Organization: Chez INWAP (people, computers, cats)
Newsgroups: best.bugs,best.unix