]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/date_time/example/posix_time/time_periods.cpp
1 /* Some simple examples of constructing and calculating with times
3 * [2002-Feb-01 00:00:00/2002-Feb-01 23:59:59.999999999] contains 2002-Feb-01 03:00:05
4 * [2002-Feb-01 00:00:00/2002-Feb-01 23:59:59.999999999] intersected with
5 * [2002-Feb-01 00:00:00/2002-Feb-01 03:00:04.999999999] is
6 * [2002-Feb-01 00:00:00/2002-Feb-01 03:00:04.999999999]
9 #include "boost/date_time/posix_time/posix_time.hpp"
12 using namespace boost::posix_time
;
13 using namespace boost::gregorian
;
15 //Create a simple period class to contain all the times in a day
16 class day_period
: public time_period
19 day_period(date d
) : time_period(ptime(d
),//midnight
29 date
d(2002,Feb
,1); //an arbitrary date
30 //a period that represents a day
32 ptime
t(d
, hours(3)+seconds(5)); //an arbitray time on that day
34 std::cout
<< to_simple_string(dp
) << " contains "
35 << to_simple_string(t
) << std::endl
;
37 //a period that represents part of the day
38 time_period
part_of_day(ptime(d
, hours(0)), t
);
39 //intersect the 2 periods and print the results
40 if (part_of_day
.intersects(dp
)) {
41 time_period result
= part_of_day
.intersection(dp
);
42 std::cout
<< to_simple_string(dp
) << " intersected with\n"
43 << to_simple_string(part_of_day
) << " is \n"
44 << to_simple_string(result
) << std::endl
;
52 /* Copyright 2001-2004: CrystalClear Software, Inc
53 * http://www.crystalclearsoftware.com
55 * Subject to the Boost Software License, Version 1.0.
56 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)