Dates and Times
Beta Draft - Do not distribute
© 2001, By Randall Hyde
This chapter discusses dates and times as a data type.
, this chapter discusses the data/time
data structures the HLA Standard Library defi
nes and it also discusses date arithmetic and other operations
on dates and times.
or the fi
rst 50 years, or so, of the computer’
xistence, programmers did not gi
e much thought to date
y either used a date/time package pro
vided with their programming language, or the
kludged together their o
wn date processing libraries.
t until the
problem came along that pro
an to gi
e dates serious consideration in their programs.
The purpose of this chapter is
First, this chapter teaches that date manipulation is not as tri
vial as most people w
e – it tak
es a lot of w
ork to properly compute v
arious date functions.
Second, this chapter presents the
HLA date and time formats found in the “datetime.hhf” library module.
Hopefully this chapter will con
vince you that considerable thought has gone into the HLA datetime.hhf module so you’
ll be inclined to use
it rather than trying
to create your o
wn date/time formats and routines.
Although date and time calculations may seem lik
y should be tri
y are, in f
act, quite com
Just remember the
Y2K problem to get a good idea of the kinds of problems your programs may create
t calculate date and time v
, you don’
e to deal with the comple
ties of date and time calculations, the HLA Standard Library does the hard stuf
f for you.
The HLA Standard Library date routines produce v
alid results for dates between January 1, 1583 and
December 31, 9999
HLA represents dates using the follo
wing record defi
nition (in the
This format (
) compactly represents all le
al dates using only four bytes.
Note that this is
the same date format that the chapter on Data Representation presents for the e
xtended data format (see
Fields and P
ed Data” on page
ou should use the
data type when declaring date objects
in your HLA programs, e.g.,
date.daterec := date.daterec:[ 1, 1, 2001 ]; // note: d, m ,y
As the second e
xample above demonstrates,
the first field is the day field and the second field is the month
you use a
constant to initialize a static
Don’t fall into the trap of
using the mm/dd/yy or yy/mm/dd organization common in most countries.
1. For those who missed it, the Y2K (or Year 2000) problem occurred when programmers used two digits for the date and