Add inline/constexpr to more functions in chrono lib
This commit is contained in:
parent
bc9e05ccb7
commit
0feb7d667e
|
@ -50,7 +50,6 @@ template <typename num1, typename num2, typename num3> constexpr bool inRangeExc
|
|||
* - Add method for printing to custom string formats.
|
||||
* - Allow to determine the date part for each compontent at once to prevent multiple
|
||||
* invocations of getDatePart().
|
||||
* - Make more methods constexpr.
|
||||
*/
|
||||
|
||||
/*!
|
||||
|
@ -59,7 +58,7 @@ template <typename num1, typename num2, typename num3> constexpr bool inRangeExc
|
|||
DateTime DateTime::fromTimeStamp(time_t timeStamp)
|
||||
{
|
||||
if (timeStamp) {
|
||||
struct tm *timeinfo = localtime(&timeStamp);
|
||||
struct tm *const timeinfo = localtime(&timeStamp);
|
||||
return DateTime::fromDateAndTime(timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min,
|
||||
timeinfo->tm_sec < 60 ? timeinfo->tm_sec : 59, 0);
|
||||
} else {
|
||||
|
@ -67,14 +66,6 @@ DateTime DateTime::fromTimeStamp(time_t timeStamp)
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new DateTime object with the GMT time from the specified UNIX \a timeStamp.
|
||||
*/
|
||||
DateTime DateTime::fromTimeStampGmt(time_t timeStamp)
|
||||
{
|
||||
return DateTime(DateTime::unixEpochStart().totalTicks() + static_cast<std::uint64_t>(timeStamp) * TimeSpan::ticksPerSecond);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Parses the given C-style string as DateTime.
|
||||
* \throws Throws a ConversionException if the specified \a str does not match the expected time format.
|
||||
|
@ -189,18 +180,6 @@ std::pair<DateTime, TimeSpan> DateTime::fromIsoString(const char *str)
|
|||
return make_pair(DateTime::fromDateAndTime(values[0], values[1], *dayIndex, *hourIndex, values[4], *secondsIndex, miliSeconds), delta);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the string representation of the current instance using the specified \a format.
|
||||
* \remarks If \a noMilliseconds is true the date will be rounded to full seconds.
|
||||
* \sa toIsoString() for ISO format
|
||||
*/
|
||||
string DateTime::toString(DateTimeOutputFormat format, bool noMilliseconds) const
|
||||
{
|
||||
string result;
|
||||
toString(result, format, noMilliseconds);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the string representation of the current instance using the specified \a format.
|
||||
* \remarks If \a noMilliseconds is true the date will be rounded to full seconds.
|
||||
|
|
|
@ -61,9 +61,9 @@ public:
|
|||
static DateTime fromIsoStringGmt(const char *str);
|
||||
static DateTime fromIsoStringLocal(const char *str);
|
||||
static DateTime fromTimeStamp(time_t timeStamp);
|
||||
static DateTime fromTimeStampGmt(time_t timeStamp);
|
||||
constexpr static DateTime fromTimeStampGmt(time_t timeStamp);
|
||||
|
||||
std::uint64_t &ticks();
|
||||
constexpr std::uint64_t &ticks();
|
||||
constexpr std::uint64_t totalTicks() const;
|
||||
int year() const;
|
||||
int month() const;
|
||||
|
@ -212,10 +212,18 @@ inline DateTime DateTime::fromIsoStringLocal(const char *str)
|
|||
return fromIsoString(str).first;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new DateTime object with the GMT time from the specified UNIX \a timeStamp.
|
||||
*/
|
||||
constexpr inline DateTime DateTime::fromTimeStampGmt(std::time_t timeStamp)
|
||||
{
|
||||
return DateTime(DateTime::unixEpochStart().totalTicks() + static_cast<std::uint64_t>(timeStamp) * TimeSpan::ticksPerSecond);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a mutable reference to the total ticks.
|
||||
*/
|
||||
inline std::uint64_t &DateTime::ticks()
|
||||
constexpr inline std::uint64_t &DateTime::ticks()
|
||||
{
|
||||
return m_ticks;
|
||||
}
|
||||
|
@ -304,7 +312,7 @@ constexpr inline int DateTime::millisecond() const
|
|||
/*!
|
||||
* \brief Returns the microsecond component of the date represented by this instance.
|
||||
*/
|
||||
constexpr int DateTime::microsecond() const
|
||||
constexpr inline int DateTime::microsecond() const
|
||||
{
|
||||
return m_ticks / TimeSpan::ticksPerMicrosecond % 1000ul;
|
||||
}
|
||||
|
@ -314,7 +322,7 @@ constexpr int DateTime::microsecond() const
|
|||
* \remarks The accuracy of the DateTime class is 100-nanoseconds. Hence the returned value
|
||||
* will always have two zeros at the end (in decimal representation).
|
||||
*/
|
||||
constexpr int DateTime::nanosecond() const
|
||||
constexpr inline int DateTime::nanosecond() const
|
||||
{
|
||||
return m_ticks % 10ul * TimeSpan::nanosecondsPerTick;
|
||||
}
|
||||
|
@ -376,6 +384,18 @@ constexpr inline bool DateTime::isSameDay(const DateTime &other) const
|
|||
return (m_ticks / TimeSpan::ticksPerDay) == (other.m_ticks / TimeSpan::ticksPerDay);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the string representation of the current instance using the specified \a format.
|
||||
* \remarks If \a noMilliseconds is true the date will be rounded to full seconds.
|
||||
* \sa toIsoString() for ISO format
|
||||
*/
|
||||
inline std::string DateTime::toString(DateTimeOutputFormat format, bool noMilliseconds) const
|
||||
{
|
||||
std::string result;
|
||||
toString(result, format, noMilliseconds);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new instance of the DateTime class with the maximal number of ticks.
|
||||
*/
|
||||
|
|
|
@ -70,19 +70,6 @@ TimeSpan TimeSpan::fromString(const char *str, char separator)
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the value of the current TimeSpan object to its equivalent std::string representation
|
||||
* according the given \a format.
|
||||
*
|
||||
* If \a fullSeconds is true the time interval will be rounded to full seconds.
|
||||
*/
|
||||
string TimeSpan::toString(TimeSpanOutputFormat format, bool fullSeconds) const
|
||||
{
|
||||
string result;
|
||||
toString(result, format, fullSeconds);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the value of the current TimeSpan object to its equivalent std::string representation
|
||||
* according the given \a format.
|
||||
|
|
|
@ -375,6 +375,19 @@ inline TimeSpan &TimeSpan::operator-=(const TimeSpan &other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the value of the current TimeSpan object to its equivalent std::string representation
|
||||
* according the given \a format.
|
||||
*
|
||||
* If \a fullSeconds is true the time interval will be rounded to full seconds.
|
||||
*/
|
||||
inline std::string TimeSpan::toString(TimeSpanOutputFormat format, bool fullSeconds) const
|
||||
{
|
||||
std::string result;
|
||||
toString(result, format, fullSeconds);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns ture if the time interval represented by the current TimeSpan class is null.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue