Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost.Chrono vs. Boost.Date_Time

Tags:

c++

boost

With Boost version 1.47, the Chrono library was introduced. Is Boost.Chrono meant as a replacement for Boost.Date_Time?

If not, what are the differences between them and when should I use which?

When should I consider replacing Boost.Date_Time by Boost.Chrono in an existing project?

like image 898
Robert Hegner Avatar asked Jul 18 '11 08:07

Robert Hegner


1 Answers

From Boost.Chrono's documentation:

Boost.Chrono aims to implement the new time facilities in C++0x, as proposed in N2661 - A Foundation to Sleep On. That document provides background and motivation for key design decisions and is the source of a good deal of information in this documentation.

More specifically, Boost.DateTime is about, well, dates and times. It has lots of functions for formatting dates for display according to locales and various other things. But there are also functions for getting dates and times, as well as operating on them.

Boost.Chrono seems focused on dealing with time intervals. It has no measurement higher than "hours", and it has no concept of date at all. Indeed, moments in time are only supported as offsets to a particular moment in time (time since process started, time since a fixed "epoch" like Jan 1, 1970, etc).

The two seem complementary, rather than competing, though there is some overlap. There is a lot that DateTime does that Chrono doesn't, and there are some things that Chrono does that DateTime doesn't. Sadly, there doesn't seem to be any interop between the two, so one will have to hand-convert Chrono's durations into DateType's equivalent.

like image 112
Nicol Bolas Avatar answered Oct 06 '22 01:10

Nicol Bolas