mirror of
https://github.com/boostorg/date_time.git
synced 2026-01-30 07:42:57 +00:00
73 lines
2.1 KiB
C++
73 lines
2.1 KiB
C++
|
|
|
|
#include <iostream>
|
|
#include "boost/date_time/posix_time/posix_time.hpp"
|
|
#include "boost/date_time/testfrmwk.hpp"
|
|
#include "boost/date_time/gregorian/formatters.hpp"
|
|
|
|
|
|
int
|
|
main()
|
|
{
|
|
using namespace boost::posix_time;
|
|
using namespace boost::gregorian;
|
|
|
|
date d(2000,Jan,20);
|
|
ptime start(d);
|
|
const ptime answer1[] = {ptime(d), ptime(d,seconds(1)),
|
|
ptime(d,seconds(2)), ptime(d,seconds(3))};
|
|
int i=0;
|
|
time_iterator titr(start,seconds(1));
|
|
for (; titr < ptime(d,seconds(4)); ++titr) {
|
|
std::cout << to_simple_string(*titr) << std::endl;
|
|
check("iterator -- 1 sec", answer1[i] == *titr);
|
|
i++;
|
|
}
|
|
check("iterator -- 1 sec", i == 4); // check the number of iterations
|
|
|
|
|
|
//iterate by hours
|
|
const ptime answer2[] = {ptime(d), ptime(d,hours(1)),
|
|
ptime(d,hours(2)), ptime(d,hours(3))};
|
|
i=0;
|
|
time_iterator titr2(start,hours(1));
|
|
for (; titr2 < ptime(d,hours(4)); ++titr2) {
|
|
std::cout << to_simple_string(*titr2) << std::endl;
|
|
check("iterator -- 1 hour", answer2[i] == *titr2);
|
|
i++;
|
|
}
|
|
check("iterator -- 1 hour", i == 4); // check the number of iterations
|
|
|
|
|
|
//iterate by 15 mintues
|
|
const ptime answer3[] = {ptime(d), ptime(d,minutes(15)),
|
|
ptime(d,minutes(30)), ptime(d,minutes(45)),
|
|
ptime(d,minutes(60)), ptime(d,minutes(75))};
|
|
i=0;
|
|
time_iterator titr3(start,minutes(15));
|
|
for (; titr3 < ptime(d,time_duration(1,20,0)); ++titr3) {
|
|
std::cout << to_simple_string(*titr3) << std::endl;
|
|
check("iterator -- 15 min", answer3[i] == *titr3);
|
|
i++;
|
|
}
|
|
check("iterator -- 15 min", i == 6); // check the number of iterations
|
|
|
|
//iterate by .1 seconds
|
|
const ptime answer4[] = {ptime(d), ptime(d,time_duration(0,0,0,1000)),
|
|
ptime(d,time_duration(0,0,0,2000)),
|
|
ptime(d,time_duration(0,0,0,3000))};
|
|
i=0;
|
|
time_iterator titr4(start,time_duration(0,0,0,1000));
|
|
for (; titr4 < ptime(d,time_duration(0,0,0,4000)); ++titr4) {
|
|
std::cout << to_simple_string(*titr4) << std::endl;
|
|
check("iterator -- tenth sec", answer4[i] == *titr4);
|
|
i++;
|
|
}
|
|
check("iterator -- tenth sec", i == 4); // check the number of iterations
|
|
|
|
|
|
|
|
printTestStats();
|
|
return 0;
|
|
}
|