Skip to content

Added the ability to parse and emit the NT Epoch 1601-01-01T00:00:00Z #1571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions Release/include/cpprest/asyncrt_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,21 @@ class datetime
}
}

datetime() : m_interval(0) {}
datetime() : m_interval(0) { }

/// <summary>
/// Creates <c>datetime</c> from a string representing time in UTC in RFC 1123 format.
/// Creates <c>datetime</c> from a string representing time in UTC in RFC 1123 or ISO 8601 format.
/// </summary>
/// <returns>Returns a <c>datetime</c> of zero if not successful.</returns>
static _ASYNCRTIMP datetime __cdecl from_string(const utility::string_t& timestring, date_format format = RFC_1123);

/// <summary>
/// Creates <c>datetime</c> from a string representing time in UTC in RFC 1123 or ISO 8601 format.
/// </summary>
/// <returns>Returns <c>datetime::maximum()</c> if not successful.</returns>
static _ASYNCRTIMP datetime __cdecl from_string_maximum_error(const utility::string_t& timestring,
date_format format = RFC_1123);

/// <summary>
/// Returns a string representation of the <c>datetime</c>.
/// </summary>
Expand All @@ -621,20 +628,22 @@ class datetime
/// </summary>
interval_type to_interval() const { return m_interval; }

static datetime from_interval(interval_type interval) { return datetime(interval); }

datetime operator-(interval_type value) const { return datetime(m_interval - value); }

datetime operator+(interval_type value) const { return datetime(m_interval + value); }

bool operator==(datetime dt) const { return m_interval == dt.m_interval; }

bool operator!=(const datetime& dt) const { return !(*this == dt); }

bool operator>(const datetime& dt) const { return this->m_interval > dt.m_interval; }

bool operator<(const datetime& dt) const { return this->m_interval < dt.m_interval; }

bool operator>=(const datetime& dt) const { return this->m_interval >= dt.m_interval; }

bool operator<=(const datetime& dt) const { return this->m_interval <= dt.m_interval; }

static interval_type from_milliseconds(unsigned int milliseconds) { return milliseconds * _msTicks; }
Expand All @@ -649,6 +658,8 @@ class datetime

bool is_initialized() const { return m_interval != 0; }

static datetime maximum() { return datetime(static_cast<interval_type>(-1)); }

private:
friend int operator-(datetime t1, datetime t2);

Expand All @@ -659,7 +670,7 @@ class datetime
static const interval_type _dayTicks = 24 * 60 * 60 * _secondTicks;

// Private constructor. Use static methods to create an instance.
datetime(interval_type interval) : m_interval(interval) {}
datetime(interval_type interval) : m_interval(interval) { }

// Storing as hundreds of nanoseconds 10e-7, i.e. 1 here equals 100ns.
interval_type m_interval;
Expand Down
7 changes: 5 additions & 2 deletions Release/include/cpprest/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "cpprest/astreambuf.h"
#include <iosfwd>
#include <cstdio>

namespace Concurrency
{
Expand Down Expand Up @@ -1434,7 +1435,8 @@ static pplx::task<FloatingPoint> _extract_result(std::shared_ptr<_double_state<F

if (state->exponent_number >= 0)
{
result *= pow(FloatingPoint(10.0), state->exponent_number);
result *= static_cast<FloatingPoint>(
std::pow(static_cast<FloatingPoint>(10.0), static_cast<FloatingPoint>(state->exponent_number)));

#pragma push_macro("max")
#undef max
Expand All @@ -1447,7 +1449,8 @@ static pplx::task<FloatingPoint> _extract_result(std::shared_ptr<_double_state<F
{
bool is_zero = (result == 0);

result /= pow(FloatingPoint(10.0), -state->exponent_number);
result /= static_cast<FloatingPoint>(
std::pow(static_cast<FloatingPoint>(10.0), static_cast<FloatingPoint>(-state->exponent_number)));

if (!is_zero && result > -std::numeric_limits<FloatingPoint>::denorm_min() &&
result < std::numeric_limits<FloatingPoint>::denorm_min())
Expand Down
Loading