5#pragma warning(disable:4996)
11time::time(
unsigned char _h,
unsigned _min,
unsigned char _sec)
12 : h(_h), minutes(_min), sec(_sec)
17date::date(
unsigned short _year,
unsigned char _month,
unsigned char _day)
18 : year(_year), month(_month), day(_day)
22date_time::date_time(
const time& t,
const date& d)
26date_time::date_time(
const date& d)
32time_t convert_to_time(
const date_time& dt)
36 t.tm_min = dt.minutes;
39 t.tm_mon = dt.month-1;
46date_time convert_to_date_time(time_t ti)
48 const tm& t = *gmtime(&ti);
49 return date_time(time(t.tm_hour,t.tm_min,t.tm_sec),date(t.tm_year,t.tm_mon+1,t.tm_mday+1));
53long date_time::operator - (
const date_time& dt)
const
55 return (
long)convert_to_time(*
this)-(long)convert_to_time(dt);
61 return convert_to_date_time(convert_to_time(*
this)+secs);
67 return convert_to_date_time(convert_to_time(*
this)-secs);
72 return convert_to_date_time(::time(NULL));
75std::ostream& operator << (std::ostream& os,
const time& T)
77 return os << int(T.h) <<
':' << int(T.minutes) <<
':' << int(T.sec);
80std::ostream& operator << (std::ostream& os,
const date& D)
82 return os << int(D.day) <<
'.' << int(D.month) <<
'.' << int(D.year);
85std::ostream& operator << (std::ostream& os,
const date_time& DT)
87 return os << static_cast<const time&>(DT) <<
' ' <<
static_cast<const date&
>(DT);