/////////////////////////////////////////////////////////// // Softwarebauelemente I, Aufgabe M6.2. // // author: Stephan Brumme // last changes: December 29, 2000 // include the header file #include "MDate.h" // standard timer library #include // needed to display data in MDate::Show(..) #include // initializes a TDate struct with the current date void MDate::Today(TDate& TheDate) { // the following code is taken from MSDN // use system functions to get the current date as UTC time_t secondsSince1970; time(&secondsSince1970); // convert UTC to local time zone struct tm *localTime; localTime = localtime(&secondsSince1970); // store retrieved data TheDate.Day = localTime->tm_mday; TheDate.Month = localTime->tm_mon + 1; TheDate.Year = localTime->tm_year + 1900; } // initializes a TDate struct with a specified date // !!! does not verify for validity !!! void MDate::InitDate(TDate& TheDate, Ordinal TheDay, Ordinal TheMonth, Ordinal TheYear) { // nothing special ... TheDate.Day = TheDay; TheDate.Month = TheMonth; TheDate.Year = TheYear; } // compares two dates Boolean MDate::EqualValue(const TDate& Date1, const TDate& Date2) { return ((Date1.Day == Date2.Day ) && (Date1.Month == Date2.Month) && (Date1.Year == Date2.Year)); } // copy a date Boolean MDate::Copy(TDate& Date1, const TDate& Date2) { // both dates must differ if (EqualValue(Date1, Date2)) return false; Date1.Day = Date2.Day; Date1.Month = Date2.Month; Date1.Year = Date2.Year; // successfully done return true; } // displays a TDate void MDate::Show(const TDate& TheDate) { std::cout << TheDate.Day << "." << TheDate.Month << "." << TheDate.Year << std::endl; }