DatesAndTimes - Dates and Times Dates and Times 6.1 Chapter...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Dates and Times Beta Draft - Do not distribute © 2001, By Randall Hyde Page 501 Dates and Times Chapter Six 6.1 Chapter Overview This chapter discusses dates and times as a data type. In particular , 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. 6.2 Dates F or the fi rst 50 years, or so, of the computer’ s e xistence, programmers did not gi v e much thought to date calculations. The y either used a date/time package pro vided with their programming language, or the y kludged together their o wn date processing libraries. It w asn’ t until the Y2K 1 problem came along that pro - grammers be g an to gi v e dates serious consideration in their programs. The purpose of this chapter is tw o-fold. First, this chapter teaches that date manipulation is not as tri vial as most people w ould lik e to belie v 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 e the y should be tri vial, the y are, in f act, quite com - ple x. Just remember the Y2K problem to get a good idea of the kinds of problems your programs may create if the y don’ t calculate date and time v alues correctly . F ortunately , you don’ t ha v e to deal with the comple xi - 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 2 . HLA represents dates using the follo wing record defi nition (in the date namespace): type daterec: record day:uns8; month:uns8; year:uns16; endrecord; This format ( date .dater ec ) compactly represents all le g 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 “Bit Fields and P ack ed Data” on page 81 ). Y ou should use the date .dater ec data type when declaring date objects in your HLA programs, e.g., static TodaysDate: date.daterec; Century21: 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 field if you use a date.daterec constant to initialize a static date.daterec object. 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
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 16

DatesAndTimes - Dates and Times Dates and Times 6.1 Chapter...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online