Time.h
Classes
- Time -- date and time enquiry functions, with some operations. (full description)
Interface
- Public Members
- Time ()
- Time (double jdn)
- Time (uInt year, uInt month, uInt day, uInt hour=0, uInt min=0, double sec=0.0)
- Time (const Time& time)
- double julianDay () const
- double modifiedJulianDay () const
- Time& operator = (const Time& time)
- double operator - (const Time& begin)
- Time operator + (const double plus)
- Bool operator == (const Time& other) const
- Bool operator != (const Time& other) const
- Bool operator > (const Time& other) const
- Bool operator < (const Time& other) const
- friend ostream& operator << (ostream&, const Time&)
- friend istream& operator >> (istream&, Time&)
- void now ()
- void setDate (uInt year, uInt month, uInt day, uInt hour=0, uInt min=0, double sec=0.0)
- double age ()
- uInt seconds ()
- uInt minutes ()
- uInt hours ()
- uInt dayOfMonth ()
- uInt month ()
- uInt year ()
- uInt dayOfWeek ()
- uInt dayOfYear ()
- static uInt howManyDaysInMonth ()
- static uInt howManyDaysInMonth (uInt month)
- static uInt howManyDaysInMonth (uInt month,uInt year)
- static Bool isLeapYear ()
- static Bool isLeapYear (uInt year)
- static Int timeZoneSeconds ()
- static Double timeZoneDays ()
- static String timeZoneName ()
Review Status
- Reviewed By:
- Paul Shannon
- Date Reviewed:
- 1995/03/01
- Programs:
- Tests:
This class might be better named a Date object, especially given that
more accurate Time classes are going to be required.
Prerequisite
- you should understand the difference between "Julian" and
"modified Julian" date
Synopsis
This class provides convenient date objects for the programmer.
Once constructed, they may be compared, read and written, and
queried for a wide variety of re-expressions. In a typical (?) use
you might create a Time object, and then query it to find out
the current month, day of the week, and whether it is a leap
year. You can also find out the number of seconds which have elapsed
since a specific Time.
This class should not be used for very high precision
work. The time from epoch (1970.0) in seconds is
interconverted between computer "double" values, and
some loss of accuracy might result.
Example
Time startTime;
Time moonLanding (1969,7,14);
cout << "date and time of moon landing: " << moonLanding << endl;
cout << "day of week: " << moonLanding.dayOfWeek () << endl;
cout << "day of year: " << moonLanding.dayOfYear () << endl;
cout << "seconds since moon landing: " << moonLanding.age () << endl;
cout << "weeks since moon landing: " <<
moonLanding.age () / (60 * 60 * 24 * 7) << endl;
cout << "seconds elapsed since start: " << startTime.age () << endl;
To Do
- member function 'age' might be renamed 'elapsedTime'
- A reference to the source of each algorithm should be provided.
Member Description
the default constructor returns an object with the present date and time
Time (double jdn)
Construct time with Julian day number
Time (uInt year, uInt month, uInt day, uInt hour=0, uInt min=0, double sec=0.0)
Construct Time with Gregorian calendar
- seconds after the minute [0,59.999] (include milliseconds)
- minutes after the hour [0,59]
- hours after midnight [0,23]
- day of the month [1,31]
- month of the year [1,12]
- year. Beware, because '94' refers to the early Christian era, not
the 20th century.
Time (const Time& time)
Copy constructor
return the Julian day
return the modified Julian day
Time& operator = (const Time& time)
initialise the julian day data with Time class
double operator - (const Time& begin)
Time operator + (const double plus)
Bool operator == (const Time& other) const
Bool operator != (const Time& other) const
Bool operator > (const Time& other) const
Bool operator < (const Time& other) const
friend ostream& operator << (ostream&, const Time&)
write the current time, GMT, in format
Tue Mar 22 16:40:24 1994
friend istream& operator >> (istream&, Time&)
read in date, which must be in the following format
month/day/year,hour:min:sec
where month,day,year,hour,min and sec are uInt.
void now ()
reset date to the present instant
void setDate (uInt year, uInt month, uInt day, uInt hour=0, uInt min=0, double sec=0.0)
double age ()
number of seconds which have elapsed since Time object was created
or reset
static Bool isLeapYear (uInt year)
Returns the difference, in seconds, between UTC and local time.
Negative values are west of GMT, positive are east.
Same as timeZoneSeconds(), but returns fractional days rather
than seconds.
Returns a string, e.g. "EST" or "MDT", describing the current
local time zone.