Oracle actually has the most elegant Gregorian time manipulation
implementation I've seen. The only operations it really supports are
add_months and add_days. Year +/- can be implemented with add_months*12.
All of add_<week|hour|minute|second|ms|us|ns> can be synthesized from
add_days. This scarcity of operations yields the elegance, and is
perfect for an instruction set. Based on that model, I'd suggest:
gmclock(out Nx)
UTC clock in seconds since 0000 hrs Jan 1, 2000, ignoring leap
seconds.
gmtime(out Px, in Nx)
Splits date up like Perl 5 gmtime. (But without annoying y -=
1900 and m -= 1?)
localtime(out Px, in Nx)
Splits date up like Perl 5 localtime. (But without annoying y -=
1900 and m -= 1?)
add_months(out Nx, in Ny, in Nz)
Sets x to y + z months.
That's the minimal core set of operations.
But the redundancy of gmtime and localtime has always bothered me, so I
could see this instead:
gmclock(out Nx)
UTC clock in seconds since 0000 hrs Jan 1, 2000, ignoring leap
seconds.
tolocal out Nx, out Iy, in Nz
x is set to z converted to the local time zone. y <- 1 if
Daylight Savings Time was in effect at z; y <- 0 otherwise.
splittime Px, Nx
Splits date up like Perl 5 gmtime. (But without annoying y -=
1900 and m -= 1?)
add_months(out Nx, in Ny, in Nz)
Sets x to y + z months.
By contrast, date manipulation in Perl 5 is truly horrid. I've seen
modules which turned a gmtime array back into an epoch-base value by
using localtime to converge on the correct value using progressive
approximation, as if finding the root of an arbitrary mathematical
function. Doing the same using the above instructions can easily be
implemented in 17 instructions flat with no branches:
# out Nx: clock-style seconds-since-epoch
# in Py: splittime-style array
# Nz: temp
Nx = 0
# years
Nz = Py[5]
Nz = Nz - 2000 # epoch based at year 2000
Nz = Nz * 12 # = months per year
add_months Nx, Nx, Nz
# months
Nz = Py[4]
add_months Nx, Nx, Nz
# days
Nz = Py[3]
Nz = Nz * 86400 # = 24 * 60 * 60 seconds per day
Nx = Nx + Nz
# hours
Nz = Py[2]
Nz = Nz * 3600 # = 60 * 60 seconds per hour
Nx = Nx + Nz
# minutes
Nz = Py[1]
Nz = Nz * 60 # = 60 seconds per minute
Nx = Nx + Nz
# seconds
Nz = Py[0]
Nx = Nx + Nz
Leave parsing and formatting entirely to libraries. Absolutely no need
for that in the instruction set.
--
Gordon Henriksen
IT Manager
ICLUBcentral Inc.
[EMAIL PROTECTED]