Rick Welykochy was once rumoured to have said:
> John Clarke wrote:
> > 
> > On Fri, Feb 16, 2001 at 12:02:41AM +1100, Rick Welykochy wrote:
> > 
> > > output program using INTERCAL (see http://intercal.com).
> > 
> > You're a very disturbed individual ...
> 
> Agreed. It is insane trying to convince a well-informed troup like
> the Penguinillas that a bash script is actually INTERCAL.
> 
> Of course, the real solution for the giga-second in INTERCAL
> is as follows:

Nononono.  You should do *everything* in Postscript.

---BEGIN----
% datecalc.ps
% - Chris Collins <[EMAIL PROTECTED]>

/mins { 60 mul } bind def
/hours { 60 mins mul } bind def
/days { 24 hours mul } bind def

/months [
  31 days % jan
  28 days % feb
  31 days % mar
  30 days % apr
  31 days % may
  30 days % jun
  31 days % jul
  31 days % aug
  30 days % sep
  31 days % oct
  30 days % nov
  31 days % dec
] def

/leapmonths [
  31 days % jan
  29 days % feb
  31 days % mar
  30 days % apr
  31 days % may
  30 days % jun
  31 days % jul
  31 days % aug
  30 days % sep
  31 days % oct
  30 days % nov
  31 days % dec
] def

/secyear 365 days def
/secleapyear 366 days def

% year leapyear bool
/leapyear {
    % is it a leap year?
    dup 4 mod 0 eq exch
    dup 100 mod 0 ne exch
    400 mod 0 eq 
    or and
} def

% time_t calcdate year month day hours minutes seconds
/calcdate {
  % build a small dictionary for us to use as variable space
  8 dict begin
  /year 1970 def
  /month 1 def
  /day 1 def
  /hour 0 def
  /minute 0 def
  /second 0 def

  % do years first.
  {
    year leapyear {secleapyear} {secyear} ifelse % time_t seconds
    1 index 1 index lt {exit} if
    sub /year year 1 add store
  } loop % will exit with: time_t seconds
  pop

  % now months.
  year leapyear {leapmonths} {months} ifelse % time_t [arry]
  /monarray exch store
  {
    monarray month 1 sub get % time_t month_secs
    1 index 1 index lt {exit} if
    sub /month month 1 add store
  } loop % will exit with: time_t monthsecs
  pop

  % days, hours, minutes and seconds are realtively easy now.

  % days
  dup 1 days idiv dup day add /day exch store
  1 days mul sub
  % hours
  dup 1 hours idiv dup hour add /hour exch store
  1 hours mul sub
  % minutes
  dup 1 mins idiv dup minute add /minute exch store
  1 mins mul sub
  % seconds are whatever is left
  /second exch store

  [ year month day hour minute second ]
  end
} def

% [year month day hours minutes seconds printdate] -
/printdate {
  dup 2 get 2 string cvs print ( ) print
  dup 1 get [(Jan) (Feb) (Mar) (Apr) (May) (Jun) (Jul) (Aug) (Sep) (Oct) (Nov) (Dec)] 
exch 1 sub get print ( ) print
  dup 0 get 4 string cvs print (, ) print
  dup 3 get 2 string cvs print (:) print
  dup 4 get 2 string cvs dup length 1 eq {(0) print} if print (:) print
  dup 5 get 2 string cvs dup length 1 eq {(0) print} if print ( GMT\n) print
} def

1000000000 calcdate printdate

quit
---END---

C.
-- 
--==============================================--
  Crossfire      | This email was brought to you
  [EMAIL PROTECTED] | on 100% Recycled Electrons
--==============================================--

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug

Reply via email to