|
// mydate.h
// defines a date type
// Date: 28 Aug 2003 12:04 AM
// Last Modified: 28 Aug 2003 12:04 AM
// Author: Vijay Mathew Pandyalakal
/* Copyright 2000 - 2005 Vijay Mathew Pandyalakal. All rights reserved.
*
* This software may be used or modified for any purpose, personal or
* commercial. Open Source redistributions are permitted.
*
* Redistributions qualify as "Open Source" under one of the following terms:
*
* Redistributions are made at no charge beyond the reasonable cost of
* materials and delivery.
*
* Redistributions are accompanied by a copy of the Source Code or by an
* irrevocable offer to provide a copy of the Source Code for up to three
* years at the cost of materials and delivery. Such redistributions
* must allow further use, modification, and redistribution of the Source
* Code under substantially the same terms as this license.
*
* Redistributions of source code must retain the copyright notices as they
* appear in each source code file, these license terms, and the
* disclaimer/limitation of liability set forth as paragraph 6 below.
*
* Redistributions in binary form must reproduce this Copyright Notice,
* these license terms, and the disclaimer/limitation of liability set
* forth as paragraph 6 below, in the documentation and/or other materials
* provided with the distribution.
*
* The Software is provided on an "AS IS" basis. No warranty is
* provided that the Software is free of defects, or fit for a
* particular purpose.
*
* Limitation of Liability. The Author shall not be liable
* for any damages suffered by the Licensee or any third party resulting
* from use of the Software.
*/
#ifndef _MYDATE_H
#define _MYDATE_H
#define _MYDATE_VERSION 2
namespace openutils {
class MyDate {
private:
int m_nYear;
int m_nMonth;
int m_nDay;
int m_nOldYear;
int m_nOldMonth;
int m_nOldDay;
public:
// constrcutors
MyDate();
MyDate(const char* date);
MyDate(int d,int m,int y);
// set value functions
void setDate(const char* date);
void setYear(int y);
void setMonth(int m);
void setDay(int d);
// get functions
int getYear();
int getMonth();
int getDay();
string getShortMonth();
void getFullMonth(char* ret);
string getDate();
string getDate(const char* format);
// arithmetic functions
void addDays(int d);
void addMonths(int m);
void addYears(int y);
void lessDays(int d);
void lessMonths(int m);
void lessYears(int y);
int differenceInDays(MyDate d);
int differenceInMonths(MyDate d);
int differenceInYears(MyDate d);
// operators
bool operator > (MyDate d);
bool operator < (MyDate d);
bool operator == (MyDate d);
bool operator != (MyDate d);
void operator = (MyDate d);
void operator = (char* c);
// overloaded comparison functions
bool lesserThan(MyDate d) {
return (*this < d);
}
bool greaterThan(MyDate d) {
return (*this > d);
}
bool equals(MyDate d) {
return (*this == d);
}
bool notEquals(MyDate d) {
return (*this != d);
}
// utilities
bool isLeapYear();
private:
void validate();
int getDaysInMonth();
void correctDays();
void restore();
};
class MyDateException {
private:
string m_strErr;
public:
MyDateException() { m_strErr = ""; }
MyDateException(string s) { m_strErr = s; }
string getMessage() { return m_strErr; }
protected:
void setMessage(string s) { m_strErr = s; }
};
} // namespace myutils
#endif
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.