Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

boost::posix_time::time_period alternative or advice?

49 views
Skip to first unread message

Christopher Pisz

unread,
Apr 24, 2015, 2:35:18 PM4/24/15
to

The problem I am trying to solve is that I need to determine if any
given datetime falls within a certain scheduled week.

I am already using boost::posix_time::ptime in my project. I thought it
would be natural to use boost::posix_time::time_period and its
boost::posix_time::time_period::contains method.

However, it seems fruity... I wrote the following test:

// Boost Includes
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

// Standard Includes
#include <iostream>
#include <ostream>
#include <memory>
#include <vector>

int main()
{
boost::posix_time::ptime start(boost::gregorian::date(2015, 4, 24),
boost::posix_time::time_duration(0,
0, 0));


boost::posix_time::ptime end(boost::gregorian::date(2015, 4, 24),
boost::posix_time::time_duration(11,
59, 59));

boost::posix_time::time_period period(start, end);

if( period.contains(start) )
{
std::cout << "Start is Inclusive\n";
}
else
{
std::cout << "Start is Exclusive\n";
}

if( period.contains(end) )
{
std::cout << "End is Inclusive\n";
}
else
{
std::cout << "End is Exclusive\n";
}
}

and the output says the start is inclusive and the end is exclusive.
Seems very odd to me. Was there something wrong with my thinking?

Also, is there some alternative in the standard, and is that standard
available in msvc11?













--
I have chosen to troll filter/ignore all subthreads containing the
words: "Rick C. Hodgins", "Flibble", and "Islam"
So, I won't be able to see or respond to any such messages
---

Scott Lurndal

unread,
Apr 24, 2015, 4:24:21 PM4/24/15
to
Christopher Pisz <nos...@notanaddress.com> writes:
>
>The problem I am trying to solve is that I need to determine if any
>given datetime falls within a certain scheduled week.

[code elided]
>
>and the output says the start is inclusive and the end is exclusive.
>Seems very odd to me. Was there something wrong with my thinking?

You programmed a duration of 11:59:59. Consider the start
time as zero, then the time 11:59:59 is one second beyond
the end of the interval.

0 new messages