//	Zinc Application Framework - Z_DATE.HPP
//	COPYRIGHT (C) 1990-1999.  All Rights Reserved.
//	Zinc Software Incorporated.  Pleasant Grove, Utah  USA

#if !defined(Z_DATE_HPP)
#define Z_DATE_HPP
#include <z_utime.hpp>

// --------------------------------------------------------------------------
// ----- ZafDateData --------------------------------------------------------
// --------------------------------------------------------------------------

class ZAF_EXPORT ZafDateData : public ZafUTimeData
{
public:
	// -- General members ---
	ZafDateData(void);
	ZafDateData(int year, int month, int day);
	ZafDateData(const ZafIChar *string, const ZafIChar *format = ZAF_NULLP(ZafIChar));
	ZafDateData(const ZafDateData &copy);
	ZafDateData(const ZafUTimeData &copy);
	virtual ~ZafDateData(void);

	// --- Persistence ---
	virtual ZafData *Duplicate(void);
#if defined(USE_ZAF_PERSISTENCE)
	ZafDateData(const ZafIChar *name, ZafDataPersistence &persist);
	static ZafElement *Read(const ZafIChar *name, ZafDataPersistence &persist);
	virtual void Write(ZafDataPersistence &persist);
#endif

	// --- Attributes & data access ---
	// get
	virtual void Date(int *year, int *month, int *day, int *dayOfWeek = ZAF_NULLP(int));
	virtual int FormattedText(ZafIChar *buffer, int maxLength, const ZafIChar *format = 0) const;
	virtual long Value(void) const;
	// set
	virtual void Clear(void);
	virtual ZafError SetDate(int year, int month, int day);
	virtual ZafError SetDate(const ZafIChar *buffer, const ZafIChar *format);
	virtual ZafError SetDate(const ZafDateData &number);
	virtual ZafError SetIncrementDate(int year, int month, int day);

	// --- Class identification ---
	static ZafClassID classID;
	static ZafClassNameChar ZAF_FARDATA className[];
	virtual ZafClassID ClassID(void) const { return (classID); }
	virtual ZafClassName ClassName(void) const { return (className); }
	virtual bool IsA(ZafClassID compareID) const;
	virtual bool IsA(ZafClassName compareName) const;

	// --- Operators ---
	ZafDateData operator+(long days);
	ZafDateData operator-(long days);
	ZafDateData &operator+=(const ZafUTimeData &utime);
	ZafDateData &operator+=(long days);
	ZafDateData &operator-=(const ZafUTimeData &utime);
	ZafDateData &operator-=(long days);

	ZafDateData operator++(void);
	ZafDateData operator++(int);
	ZafDateData operator--(void);
	ZafDateData operator--(int);

protected:
#if defined(USE_ZAF_PERSISTENCE)
	// --- Persistent members --
	virtual ZafDataConstructor ReadFunction(void) { return (ZafDateData::Read); }
#endif

	virtual void Add(const ZafUTimeData &utime);
	virtual void Subtract(const ZafUTimeData &utime);
};

inline ZafDateData &ZafDateData::operator+=(long days) { return (*this += ZafDateData(0, 0, (int)days)); }
inline ZafDateData &ZafDateData::operator-=(long days) { return (*this -= ZafDateData(0, 0, (int)days)); }

#endif // Z_DATE_HPP

