-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_datetime.cpp
More file actions
54 lines (45 loc) · 979 Bytes
/
test_datetime.cpp
File metadata and controls
54 lines (45 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "date_and_time.h"
#include <cassert>
#include <iostream>
#include <stdexcept>
#include <ctime>
#include <cstdio>
int main()
{
DateTime * pDT1;
try
{
pDT1 = new DateTime;
}
catch (const std::exception & _e)
{
std::cout << _e.what() << std::endl;
}
const char * str1 = pDT1->ToString();
std::cout << str1 << "\n";
DateTime * pDT2;
try
{
pDT2 = new DateTime("2016/02/29 22:50", '/', ' ', ':');
}
catch (const std::exception & _e2)
{
std::cout << _e2.what() << std::endl;
}
const char * str2 = pDT2->ToString();
std::cout << str2 << "\n";
DateTime * pDT3 = DateTime::MakeDT(2015, 6, 15, 11, 00);
const char * str3 = pDT3->ToString();
std::cout << str3 << "\n";
DateTime * pDT4 = new DateTime("2016/02/29 22:50", '/', ' ', ':');
assert(*pDT3 < *pDT1);
assert(*pDT4 > *pDT1);
assert(*pDT4 == *pDT2);
assert(*pDT4 <= *pDT2);
assert(*pDT4 >= *pDT2);
assert(*pDT1 != *pDT2);
delete pDT4;
delete pDT3;
delete pDT2;
delete pDT1;
}