Category : Recently Uploaded Files
Archive   : DOSUIT07.ZIP
Filename : TIME.HPP

 
Output of file : TIME.HPP contained in archive : DOSUIT07.ZIP

/*
* Compact Time/Date class
*/
#ifndef TIME_HPP
#define TIME_HPP

/*
Holds a date and time, to the nearest second. Uses the C library time
functions.
*/
class Time {
public:
Time(long daysSinceJan1_1970); // As returned by time().
Time(); // System clock date & time.
Time(const Time &t);
Time(unsigned dosdate, unsigned dostime);
// Conversion from DOS file date & time.
Time(const char *filename);
// The time and date of the specified file (zero if file not found).

//~ Time & Date setting functions
// The integer functions return 0 if the time or date was invalid.
void set(long secsSinceJan1_1970) { tim = secsSinceJan1_1970; }
int setdate(unsigned int d, unsigned int m, unsigned int y);
int setdate(const char *string);
void setdate(unsigned daysSinceJan1_1970);
int settime(unsigned int h, unsigned int m, unsigned int s = 0);
int settime(long secsSinceMidnight);
int settime(const char *string);
void systemtime(); // Set time to system clock.
int setdostime(unsigned date,unsigned time);
// Convert from DOS directory date & time.
int filetime(const char *filename);
// File date & time - return 0 if file not found.

//~ Get parts of Time
long time() const { return tim; }
unsigned int dayno() const; // Days since Jan 1 1970.
long secsSinceMidnight() const;

unsigned dostime() const; // Convert to DOS directory time.
unsigned dosdate() const; // Convert to DOS directory date.

unsigned hour() const; // 0-23.
unsigned minute() const; // 0-59.
unsigned second() const; // 0-59.

unsigned year() const; // In full e.g. 1993.
unsigned month() const; // 1-12.
unsigned day() const; // 1-31.

//~ String formatting functions
// These functions return a string created by form(), so it
// won't last forever.
const char *formattime(const char *format);
// See strftime C library function.
const char *strdate() // DD/MM/YY
{ return formattime("%d/%m/%y"); }
const char *strtime() // hh:mm:ss
{ return formattime("%H:%M:%S"); }
const char *strdatetime() // DD/MM/YY hh:mm:ss
{ return formattime("%d/%m/%y %H:%M:%S"); }

//~ Operators
int operator==(const Time &t) const { return (tim == t.tim); }
int operator!=(const Time &t) const { return (tim != t.tim); }
int operator<(const Time &t) const { return (tim < t.tim); }
int operator>(const Time &t) const { return (tim > t.tim); }
int operator<=(const Time &t) const { return (tim <= t.tim); }
int operator>=(const Time &t) const { return (tim >= t.tim); }

Time &operator=(const Time &t) { tim = t.tim; return *this; }
Time &operator=(long l) { tim = l; return *this; }
Time &operator+=(long l) { tim += l; return *this; }
Time &operator-=(long l) { tim -= l; return *this; }
long operator-(const Time &t) { return tim - t.tim; }

static Time &zero; // Time representing Jan 1 1970.

private:
long tim;
};

#endif