Skip to content

Instantly share code, notes, and snippets.

@arunk-s
Created July 18, 2014 08:49
Show Gist options
  • Save arunk-s/21218a7262ce663dd1ac to your computer and use it in GitHub Desktop.
Save arunk-s/21218a7262ce663dd1ac to your computer and use it in GitHub Desktop.
Integration with the prototype
#include <tuple>
#include <boost/chrono/date/algorithms/weekday_from_days.hpp>
#include <boost/chrono/date/algorithms/days_from_civil.hpp>
#include <boost/chrono/date/algorithms/civil_from_days.hpp>
days_date::days_date(chrono::year y, chrono::month m, chrono::day d) BOOST_NOEXCEPT
{
x_ = days_from_civil(y,m,d) //Passing opaque has better performance results
//But the days_from_civil algorithm start calculating from 1970-01-01
}
// BOOST_VERIFY(std::get<0>(d_1) == y);
// BOOST_VERIFY(std::get<1>(d_1) == m);
// BOOST_VERIFY(std::get<2>(d_1) == i);
BOOST_FORCEINLINE chrono::day to_day() const BOOST_NOEXCEPT
{
return chrono::day(std::get<2>(civil_from_days(x_))) ;
//The 3rd value from civil from days tuple is the day value
//But the x_ should be generated from days_from_civil as civil_from_days also takes dates from 1970-01-01
// return chrono::day(day_from_day_number(), no_check);
}
BOOST_FORCEINLINE chrono::month to_month() const BOOST_NOEXCEPT
{
return chrono::month(std::get<1>(civil_from_days(x_))) ;
//The 2nd value from civil from days tuple is the month value
//But the x_ should be generated from days_from_civil as civil_from_days also takes dates from 1970-01-01
// return chrono::month(month_from_day_number(), no_check);
}
BOOST_FORCEINLINE chrono::year to_year() const BOOST_NOEXCEPT
{
return chrono::year(std::get<0>(civil_from_days(x_))) ;
//The 1st value from civil from days tuple is the year value
//But the x_ should be generated from days_from_civil as civil_from_days also takes dates from 1970-01-01
// return chrono::year(year_from_day_number());
}
bool
days_date::leap_from_day_number() const BOOST_NOEXCEPT {
return is_leap(std::get<0>(civil_from_days(x_)));
//The x_ should be generated from days_from_civil as civil_from_days also takes dates from 1970-01-01
// return is_leap(year_from_day_number());
}
/**
* @Returns: A weekday constructed with an int corresponding to *this
* days_date's day of the week (a value in the range of [0 - 6], 0 is Sunday).
*/
BOOST_FORCEINLINE BOOST_CONSTEXPR chrono::weekday to_weekday() const BOOST_NOEXCEPT
{
return chrono::weekday(weekday_from_days(x_));
//But the x_ should be generated from days_from_civil as weekday_from_days takes dates from 1970-01-01
// return chrono::weekday((x_ + 1) % weekday::size);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment