// Duration Days and Date classes (Copyright 1994, Information Disciplines, Inc.) // ------------------------------ #ifndef DAYS #define DAYS const Days #define DATE const Date // Duration (extent) class in number of days // ----------------------- class Days { long value; // Internal representation friend class Date; // Allow Date methods to retrieve value // Constructors // ------------ public: Days(LONG x = 0) : value(x) {} // Compiler will supply acceptable copy constructor, destructor, // and assignment operator // Arithmetic Operators // -------------------- #define Class Days #define PureType long #include "Additive.hpp" /* Additive pattern for binary operators */ DAYS& operator++() {++value; return *this;} DAYS& operator--() {--value; return *this;} DAYS operator++(int) {DAYS result = *this; ++value; return result;} DAYS operator--(int) {DAYS result = *this; --value; return result;} // Relational operators // --------------------- bool operator== (DAYS rs) const {return value == rs.value;} bool operator< (DAYS rs) const {return value < rs.value;} // I-O operations // -------------- static char* unit; // Unit name ("day") for messages ostream& put(ostream& s) const; istream& get(istream& s); }; // ************ End of class definition // Inline member and non-member functions // -------------------------------------- inline ostream& operator<< (ostream& ls, DAYS rs) {return rs.put(ls);} inline istream& operator>> (istream& ls, Days& rs){return rs.get(ls);} inline Days& Days::operator+=(DAYS rs) {value += rs.value; return *this; } inline Days& Days::operator-=(DAYS rs) {value -= rs.value; return *this; } inline Days& Days::operator*=(LONG rs) {value *= rs; return *this; } inline Days& Days::operator/=(LONG rs) {value /= rs; return *this; } inline long Days::operator/ (DAYS rs) const { return value / rs.value; } inline Days& Days::operator%=(DAYS rs) {value %= rs.value; return *this; } inline Days& Days::operator%=(LONG rs) {value %= rs; return *this; } inline Days Days::operator- () const {return Days(-value); } // Date class // ---------- // This class defines date objects. Although it assumes the // Gregorian calendar, dependencies on the calendar are minimized // through the CalendarInfo pseudo-class. #include "CalendarInfo.hpp" /* Tables, constants, and calendar functions */ class Date { long value; // Internal representation // The value is the number of days since the origin defined by: static LONG BIAS; // (See IDIDATE.CPP for value) // This representation is compatible with some database and spreadsheet // software products. Note that: // 1. Some conversion functions assume the Gregorian calendar, // even for dates before that calendar was adopted. // 2. B.C. dates can be generated by arithmetic operations, but // may not be supported by conversion functions. static SHORT BIAS_WEEKDAY; // Day of week of // origin date static long yyyy; // Storage for result of static short mm; // component date fields static short dd; // (see set_ymd() function) static short ddd; static long cur_value; // Date corresponding to // above components public: Date() {} // (No default value) Date(LONG yyyy, UINT ddd); // Year and day number Date(LONG yyyy, SHORT mm, SHORT dd); // Year-month-day Date(CHAR YYMMDD[6]); // ANSI 6-character repr. static short century_break; // Break point for // 2-digit year // Compiler will supply acceptable copy constructor, destructor, // and assignment operator void set_ymd() const; // Extract date subfields long year() const {set_ymd(); return yyyy;} short month() const {set_ymd(); return mm;} short day() const {set_ymd(); return dd;} short dayno() const {set_ymd(); return ddd;} short weekday() const {return (((value + BIAS_WEEKDAY) % 7) + 7) % 7;} // Arithmetic Operators #define PointClass Date #include "PointExt.hpp" DATE& operator++() {++value; return *this;} DATE& operator--() {--value; return *this;} DATE operator++(int) {DATE result = *this; ++value; return result;} DATE operator--(int) {DATE result = *this; --value; return result;} // Relational operators // -------------------- bool operator== (DATE rs) const {return value == rs.value;} bool operator< (DATE rs) const {return value < rs.value;} // I-O operations // -------------- ostream& put(ostream& s) const; istream& get(istream& s); }; // Inline member and non-member functions inline ostream& operator<< (ostream& ls, DATE rs) {return rs.put(ls);} inline istream& operator>> (istream& ls, Date& rs){return rs.get(ls);} inline Date& Date::operator+= (DAYS rs) {value += rs.value; return *this;} inline Date& Date::operator-= (DAYS rs) {value -= rs.value; return *this;} #undef Class #undef PointClass #endif