00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef DEBUG
00019 #define DEBUG
00020 #endif
00021
00022 #include <ucommon-config.h>
00023 #include <ucommon/ucommon.h>
00024
00025 #include <stdio.h>
00026
00027 using namespace UCOMMON_NAMESPACE;
00028
00029 int main(int argc, char **argv)
00030 {
00031 Date date = Date(2003, 1, 6);
00032 int exp_year = 2003;
00033 unsigned exp_month = 1;
00034 unsigned exp_day = 6;
00035 unsigned exp_dayofweek = 1;
00036 String exp_stringdate;
00037 tm_t exp_dt;
00038 time_t exp_ctime;
00039 char buf[20];
00040
00041 snprintf(buf, sizeof(buf),
00042 "%04d-%02d-%02d", exp_year, exp_month, exp_day);
00043
00044 memset(&exp_dt, 0, sizeof(exp_dt));
00045 exp_dt.tm_year = exp_year - 1900;
00046 exp_dt.tm_mon = exp_month - 1;
00047 exp_dt.tm_mday = exp_day;
00048 exp_ctime = mktime(&exp_dt);
00049
00050 assert(exp_year == date.year());
00051 assert(exp_month == date.month());
00052 assert(exp_day == date.day());
00053 assert(exp_dayofweek == date.dow());
00054
00055
00056 exp_stringdate = date();
00057 assert(eq(*exp_stringdate, "2003-01-06"));
00058 date.put(buf);
00059 assert(eq(buf, "2003-01-06"));
00060 assert(exp_ctime == date.timeref());
00061
00062
00063 Date aday = date;
00064 Date nextday(2003, 1, 7);
00065 assert(aday == date);
00066 assert((++aday) == nextday);
00067 assert(aday != date);
00068 assert(date <= aday);
00069 assert(date < aday);
00070
00071
00072 Date newday = nextday + 5l;
00073 assert((long)newday == 20030112l);
00074 assert((long)nextday == 20030107l);
00075 assert(newday - nextday == 5);
00076
00077
00078 assert(20030106l == date.get());
00079 date -= 6;
00080 assert(20021231l == date.get());
00081
00082
00083 date = "20031306";
00084 assert(!is(date));
00085
00086
00087 date = "2003-08-04";
00088 assert((long)date == 20030804l);
00089
00090 DateTimeString dts("2003-02-28 23:59:55");
00091 eq((const char *)dts, "2003-02-28 23:59:55");
00092
00093 DateTime tmp("2003-02-28 23:59:55");
00094 snprintf(buf, sizeof(buf), "%.5f", (double)tmp);
00095 assert(eq(buf, "2452699.99994"));
00096 assert((long)tmp == 20030228l);
00097 tmp += 5;
00098 assert((long)tmp == 20030301l);
00099
00100 return 0;
00101 }
00102