/* Name : TIMEDATE.H Date : May 10th, 1991 Author : Kim Moser System : Borland C++ 3.0 Descrip: Low-level time and date functions */ //------------------------------------------------------------------------- // "Forward": class hhmmss; class timedate; class duration; class mmddyy { protected: inline void adjustday(void); inline mmddyy& borrowyear(void); inline mmddyy& borrowmonth(void); inline mmddyy& borrowday(void); public: int year; int month; int day; // Constructors: mmddyy(void) { } mmddyy(const mmddyy& d) { *this = d; } mmddyy(int y, int m, int d) { year = y; month = m; day = d; } mmddyy& now(void); int isvalid(void) const; int compare(const mmddyy &d2) const; operator <(const mmddyy& d2) const { return (compare(d2) < 0); } operator <=(const mmddyy& d2) const { return (compare(d2) <= 0); } operator >(const mmddyy& d2) const { return (compare(d2) > 0); } operator >=(const mmddyy& d2) const { return (compare(d2) >= 0); } mmddyy& addyear(int i); mmddyy& addmonth(int i); mmddyy& addday(int i); mmddyy& subtractyear(int i); mmddyy& subtractmonth(int i); mmddyy& subtractday(int i); int weekday(void) const; // Returns 0==Sunday, 1==Monday, etc. friend ostream& operator <<(ostream& os, const mmddyy& d) { int old_width = os.width(); int old_fill = os.fill('0'); os.width(2); os << d.month << '/'; os.width(2); os << d.day << '/'; os.width(4); os << d.year; os.width(old_width); os.fill(old_fill); return (os); } }; extern mmddyy& now(mmddyy& d); //------------------------------------------------------------------------- class hhmmss { protected: inline hhmmss& borrowhours(void); inline hhmmss& borrowminutes(void); inline hhmmss& borrowseconds(void); inline hhmmss& borrowhundredths(void); public: int hours; int minutes; int seconds; int hundredths; // Constructors: hhmmss(void) { } hhmmss(hhmmss& t) { *this = t; } hhmmss(int h, int m, int s, int hu) { hours = h; minutes = m; seconds = s; hundredths = hu; } hhmmss& now(void); int isvalid(void); int compare(hhmmss& t2); operator <(hhmmss& t2) { return (compare(t2) < 0); } operator <=(hhmmss& t2) { return (compare(t2) <= 0); } operator >(hhmmss& t2) { return (compare(t2) > 0); } operator >=(hhmmss& t2) { return (compare(t2) >= 0); } hhmmss& addhours(int i); hhmmss& addminutes(int i); hhmmss& addseconds(int i); hhmmss& addhundredths(int i); hhmmss& subtracthours(int i); hhmmss& subtractminutes(int i); hhmmss& subtractseconds(int i); hhmmss& subtracthundredths(int i); friend ostream& operator <<(ostream& os, hhmmss& t) { int old_width = os.width(); int old_fill = os.fill('0'); os.width(2); os << t.hours << ':'; os.width(2); os << t.minutes << ':'; os.width(2); os << t.seconds << '.'; os.width(2); os << t.hundredths; os.width(old_width); os.fill(old_fill); return (os); } }; extern hhmmss& now(hhmmss& d); //------------------------------------------------------------------------- class timedate : public mmddyy, public hhmmss { protected: inline void adjustday(void); inline timedate& borrowyear(void); inline timedate& borrowmonth(void); inline timedate& borrowday(void); inline timedate& borrowhours(void); inline timedate& borrowminutes(void); inline timedate& borrowseconds(void); inline timedate& borrowhundredths(void); public: // Constructors: timedate(void) { } timedate(timedate& td) { *this = td; } timedate(int y, int m, int d, int h, int mi, int s, int hu) { mmddyy::mmddyy(y, m, d); hhmmss::hhmmss(h, mi, s, hu); } timedate& now(void); int isvalid(void); int compare(timedate& td2); operator <(timedate& td2) { return (compare(td2) < 0); } operator <=(timedate& td2) { return (compare(td2) <= 0); } operator >(timedate& td2) { return (compare(td2) > 0); } operator >=(timedate& td2) { return (compare(td2) >= 0); } timedate& addyear(int i); timedate& addmonth(int i); timedate& addday(int i); timedate& addhours(int i); timedate& addminutes(int i); timedate& addseconds(int i); timedate& addhundredths(int i); timedate& subtractyear(int i); timedate& subtractmonth(int i); timedate& subtractday(int i); timedate& subtracthours(int i); timedate& subtractminutes(int i); timedate& subtractseconds(int i); timedate& subtracthundredths(int i); timedate& add(int year, int month, int day, int hours, int minutes, int seconds, int hundredths); timedate& subtract(int year, int month, int day, int hours, int minutes, int seconds, int hundredths); duration& operator -(timedate& td2); // d = this - td2 timedate& operator +(duration& d); // td = this + d timedate& operator -(duration& d); // td = this - d int weekday(void); // Returns 0==Sunday, 1==Monday, etc. friend ostream& operator <<(ostream& os, timedate& td) { os << mmddyy(td); os << ' '; os << hhmmss(td); return (os); } }; //------------------------------------------------------------------------- class duration : public timedate { public: // Constructors: duration(void) { } duration(duration& d) { *this = d; } operator double(void); // Duration to seconds friend ostream& operator <<(ostream& os, duration& d) { os << timedate(d); return (os); } }; //------------------------------------------------------------------------- /*************************************************************************/ inline int m_isleapyear(int year); inline int m_daysinmonth(int month, int year); inline int m_daysinyear(int year); extern int isleapyear(int year); extern int daysinmonth(int month, int year); extern int daysinyear(int year); /*************************************************************************/