0

Note: I saw the question: What is the C++11 equivalent to boost::date_time::not_a_date_time?. There is no rectification. So I want to be more specific about my problem to get an answer.

I have a boost::system_time, that will be cleared occasionally by assigning boost::date_time::not_a_date_time.

class Data
{
    boost::system_time dateTime;
    void clear(void)
    {
        dateTime = boost::date_time::not_a_date_time;
    }
    const boost::system_time &getDateTime() const
    {
        return dateTime;
    }
};
void main()
{
    Data obj;
    // Some processing of Data obj
    if ( obj.getDateTime() >= now )
    {
        // inform some other module
    }
}

Now, is there anything in STL, that can be assigned some value (let's say now()) and cleared to be an invalid value?

Tried creating time_point with empty constructor. It is pointing to Epoch time. I see in some odd scenarios, the time_point will have null value. Is there any way to achieve it (If it is safe)

Community
  • 1
  • 1
Naresh T
  • 309
  • 2
  • 14
  • Last time I checked the standard library has no datetime types at all. Can you make it clear what you are talking about? – sehe May 12 '15 at 07:59
  • The code I mentioned is a part of my application. It is using boost::date_time object. I want to replace boost features with STL. As an initializer, they're clearing the date_time object by assigning not_a_date_time. I can replace this date_time with system_clock or time_point. But there is nothing in STL to clear system-clock or time_point. – Naresh T May 12 '15 at 08:20
  • The STL has no concepts of dates or times, so it isn't clear what you're after. – juanchopanza May 12 '15 at 09:30
  • That's a big statement... std::chrono has almost all solutions to the dates and times. I just couldn't find the exact replacement of not_a_date_time. I can simply replace it with high_resolution_clock::time_point – Naresh T May 12 '15 at 09:33
  • @Neo Which statement? If you mean mine, the STL had no chrono functionality. – juanchopanza May 12 '15 at 10:48
  • The cited SO question is answered perfectly. There is no search-and-replace solution. read that answer and try to understand it. – stefan May 12 '15 at 10:49
  • @juanchopanza, sorry if I'm being rude. STL has chrono header file. In my application, I'm using std::chrono::high_resolution_clock::time_point. I believe that this can serve my purpose of dealing with dates and times (with the combination of std::chrono::duration) – Naresh T May 12 '15 at 15:02
  • @stefan, I do understand that there is no search and replace solution for this problem. I'm not expecting one as well. But I just thought if there is a way of representing invalid time in STL (like time_t value with some invalid value or time_point being invalid value) – Naresh T May 12 '15 at 15:04
  • @Neo No, the STL doesn't have that unless it has been recently back-ported. `std::chrono` is C++ standard library since C++11. It isn't even based on any STL code. And you're not being rude by the way! – juanchopanza May 12 '15 at 15:22

0 Answers0