Skip to content

Commit

Permalink
Merge branch 'feature/#757-Add-time-date-classes' of https://github.c…
Browse files Browse the repository at this point in the history
…om/ETLCPP/etl into feature/#757-Add-time-date-classes
  • Loading branch information
John Wellbelove committed Sep 17, 2023
2 parents 5c6d32d + 4affd4f commit c509333
Show file tree
Hide file tree
Showing 14 changed files with 1,251 additions and 375 deletions.
2 changes: 2 additions & 0 deletions include/etl/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ SOFTWARE.

#include "private/chrono/duration.h"
#include "private/chrono/day.h"
#include "private/chrono/weekday.h"
#include "private/chrono/month.h"
#include "private/chrono/year.h"


#endif
33 changes: 30 additions & 3 deletions include/etl/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,35 @@ SOFTWARE.
#endif

//*************************************
// Indicate if etl::literals::chrono_literals has month (_m)
#if defined(ETL_ENABLE_CHRONO_LITERALS_MONTH)
#define ETL_HAS_CHRONO_LITERALS_MONTH 1
// Indicate if etl::literals::chrono_literals has weekdays (_day)
#if defined(ETL_DISABLE_CHRONO_LITERALS_WEEKDAY)
#define ETL_HAS_CHRONO_LITERALS_DAY 0
#else
#define ETL_HAS_CHRONO_LITERALS_DAY 1
#endif

//*************************************
// Indicate if etl::literals::chrono_literals has weekdays (_weekday)
#if defined(ETL_DISABLE_CHRONO_LITERALS_WEEKDAY)
#define ETL_HAS_CHRONO_LITERALS_WEEKDAY 0
#else
#define ETL_HAS_CHRONO_LITERALS_WEEKDAY 1
#endif

//*************************************
// Indicate if etl::literals::chrono_literals has month (_month)
#if defined(ETL_DISABLE_CHRONO_LITERALS_MONTH)
#define ETL_HAS_CHRONO_LITERALS_MONTH 0
#else
#define ETL_HAS_CHRONO_LITERALS_MONTH 1
#endif

//*************************************
// Indicate if etl::literals::chrono_literals has year (_year)
#if defined(ETL_DISABLE_CHRONO_LITERALS_YEAR)
#define ETL_HAS_CHRONO_LITERALS_YEAR 0
#else
#define ETL_HAS_CHRONO_LITERALS_YEAR 1
#endif

//*************************************
Expand Down Expand Up @@ -484,7 +508,10 @@ namespace etl
static ETL_CONSTANT bool has_mutable_array_view = (ETL_HAS_MUTABLE_ARRAY_VIEW == 1);
static ETL_CONSTANT bool has_ideque_repair = (ETL_HAS_IDEQUE_REPAIR == 1);
static ETL_CONSTANT bool has_virtual_messages = (ETL_HAS_VIRTUAL_MESSAGES == 1);
static ETL_CONSTANT bool has_chrono_literals_day = (ETL_HAS_CHRONO_LITERALS_DAY == 1);
static ETL_CONSTANT bool has_chrono_literals_weekday = (ETL_HAS_CHRONO_LITERALS_WEEKDAY == 1);
static ETL_CONSTANT bool has_chrono_literals_month = (ETL_HAS_CHRONO_LITERALS_MONTH == 1);
static ETL_CONSTANT bool has_chrono_literals_year = (ETL_HAS_CHRONO_LITERALS_YEAR == 1);

// Is...
static ETL_CONSTANT bool is_debug_build = (ETL_IS_DEBUG_BUILD == 1);
Expand Down
102 changes: 52 additions & 50 deletions include/etl/private/chrono/day.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,55 +182,6 @@ namespace etl
unsigned char value;
};

//***********************************************************************
/// Add etl::chrono::days to etl::chrono::day
///\return etl::chrono::day
//***********************************************************************
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
{
etl::chrono::day result(d);

result += ds;

return result;
}

//***********************************************************************
/// Add etl::chrono::day to etl::chrono::days
///\return etl::chrono::day
//***********************************************************************
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT
{
etl::chrono::day result(d);

result += ds;

return result;
}

//***********************************************************************
/// Subtract etl::chrono::days from etl::chrono::day
///\return etl::chrono::day
//***********************************************************************
ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
{
etl::chrono::day result(d);

result -= ds;

return result;
}

//***********************************************************************
/// Subtract etl::chrono::day from etl::chrono::day
///\return etl::chrono::days
//***********************************************************************
ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return etl::chrono::days(static_cast<int>(static_cast<unsigned>(d1)) -
static_cast<int>(static_cast<unsigned>(d2)));
}

//***********************************************************************
/// Equality operator
//***********************************************************************
Expand Down Expand Up @@ -288,6 +239,55 @@ namespace etl
return (static_cast<unsigned>(d1) <=> static_cast<unsigned>(d2));
}
#endif

//***********************************************************************
/// Add etl::chrono::days to etl::chrono::day
///\return etl::chrono::day
//***********************************************************************
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
{
etl::chrono::day result(d);

result += ds;

return result;
}

//***********************************************************************
/// Add etl::chrono::day to etl::chrono::days
///\return etl::chrono::day
//***********************************************************************
ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT
{
etl::chrono::day result(d);

result += ds;

return result;
}

//***********************************************************************
/// Subtract etl::chrono::days from etl::chrono::day
///\return etl::chrono::day
//***********************************************************************
ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT
{
etl::chrono::day result(d);

result -= ds;

return result;
}

//***********************************************************************
/// Subtract etl::chrono::day from etl::chrono::day
///\return etl::chrono::days
//***********************************************************************
ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT
{
return etl::chrono::days(static_cast<int>(static_cast<unsigned>(d1)) -
static_cast<int>(static_cast<unsigned>(d2)));
}
}

//*************************************************************************
Expand All @@ -308,6 +308,7 @@ namespace etl
#endif
}

#if ETL_HAS_CHRONO_LITERALS_DAY
#if ETL_USING_CPP11
namespace etl
{
Expand All @@ -318,13 +319,14 @@ namespace etl
//***********************************************************************
/// Literal for days
//***********************************************************************
ETL_CONSTEXPR etl::chrono::day operator ""_d(unsigned long long d) ETL_NOEXCEPT
ETL_CONSTEXPR etl::chrono::day operator ""_day(unsigned long long d) ETL_NOEXCEPT
{
return etl::chrono::day(static_cast<unsigned>(d));
}
}
}
}
#endif
#endif

#endif
126 changes: 62 additions & 64 deletions include/etl/private/chrono/month.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,69 @@ namespace etl
unsigned char value;
};

//***********************************************************************
/// Equality operator
//***********************************************************************
ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) == static_cast<unsigned>(d2));
}

//***********************************************************************
/// Inequality operator
//***********************************************************************
ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return !(d1 == d2);
}

//***********************************************************************
/// Less-than operator
//***********************************************************************
ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) < static_cast<unsigned>(d2));
}

//***********************************************************************
/// Less-than-or-equal operator
//***********************************************************************
ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) <= static_cast<unsigned>(d2));
}

//***********************************************************************
/// Greater-than operator
//***********************************************************************
ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) > static_cast<unsigned>(d2));
}

//***********************************************************************
/// Greater-than-or-equal operator
//***********************************************************************
ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) >= static_cast<unsigned>(d2));
}

//***********************************************************************
/// Spaceship operator
//***********************************************************************
#if ETL_USING_CPP20
constexpr auto operator <=>(const etl::chrono::month& d1, const etl::chrono::month& d2) noexcept
{
return (static_cast<unsigned>(d1) <=> static_cast<unsigned>(d2));
}
#endif

//***********************************************************************
/// Add etl::chrono::months to etl::chrono::month
///\return etl::chrono::month
//***********************************************************************
ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT
ETL_CONSTEXPR14 etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT
{
unsigned int value = static_cast<unsigned int>(m);

Expand Down Expand Up @@ -238,7 +296,7 @@ namespace etl
/// Subtract etl::chrono::month from etl::chrono::month
///\return etl::chrono::months
//***********************************************************************
ETL_CONSTEXPR etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT
ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT
{
if (m1.ok() && m2.ok())
{
Expand All @@ -251,68 +309,9 @@ namespace etl
}
}


return etl::chrono::months();
}

//***********************************************************************
/// Equality operator
//***********************************************************************
ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) == static_cast<unsigned>(d2));
}

//***********************************************************************
/// Inequality operator
//***********************************************************************
ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return !(d1 == d2);
}

//***********************************************************************
/// Less-than operator
//***********************************************************************
ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) < static_cast<unsigned>(d2));
}

//***********************************************************************
/// Less-than-or-equal operator
//***********************************************************************
ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) <= static_cast<unsigned>(d2));
}

//***********************************************************************
/// Greater-than operator
//***********************************************************************
ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) > static_cast<unsigned>(d2));
}

//***********************************************************************
/// Greater-than-or-equal operator
//***********************************************************************
ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT
{
return (static_cast<unsigned>(d1) >= static_cast<unsigned>(d2));
}

//***********************************************************************
/// Spaceship operator
//***********************************************************************
#if ETL_USING_CPP20
constexpr auto operator <=>(const etl::chrono::month& d1, const etl::chrono::month& d2) noexcept
{
return (static_cast<unsigned>(d1) <=> static_cast<unsigned>(d2));
}
#endif

#if ETL_USING_CPP17
inline constexpr etl::chrono::month January{ 1 };
inline constexpr etl::chrono::month February{ 2 };
Expand All @@ -326,8 +325,7 @@ namespace etl
inline constexpr etl::chrono::month October{ 10 };
inline constexpr etl::chrono::month November{ 11 };
inline constexpr etl::chrono::month December{ 12 };
#else

#else
static ETL_CONSTANT etl::chrono::month January{ 1 };
static ETL_CONSTANT etl::chrono::month February{ 2 };
static ETL_CONSTANT etl::chrono::month March{ 3 };
Expand Down Expand Up @@ -372,7 +370,7 @@ namespace etl
//***********************************************************************
/// Literal for months
//***********************************************************************
ETL_CONSTEXPR etl::chrono::month operator ""_m(unsigned long long m) ETL_NOEXCEPT
ETL_CONSTEXPR etl::chrono::month operator ""_month(unsigned long long m) ETL_NOEXCEPT
{
return etl::chrono::month(m);
}
Expand Down
Loading

0 comments on commit c509333

Please sign in to comment.