Skip to content
Merged
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
137 changes: 124 additions & 13 deletions 3rd-party/date/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,8 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const year_month_weekday_last&
inline namespace literals
{

CONSTCD11 date::day operator "" _d(unsigned long long d) NOEXCEPT;
CONSTCD11 date::year operator "" _y(unsigned long long y) NOEXCEPT;
CONSTCD11 date::day operator ""_d(unsigned long long d) NOEXCEPT;
CONSTCD11 date::year operator ""_y(unsigned long long y) NOEXCEPT;

} // inline namespace literals
#endif // !defined(_MSC_VER) || (_MSC_VER >= 1900)
Expand Down Expand Up @@ -1972,15 +1972,15 @@ inline namespace literals
CONSTCD11
inline
date::day
operator "" _d(unsigned long long d) NOEXCEPT
operator ""_d(unsigned long long d) NOEXCEPT
{
return date::day{static_cast<unsigned>(d)};
}

CONSTCD11
inline
date::year
operator "" _y(unsigned long long y) NOEXCEPT
operator ""_y(unsigned long long y) NOEXCEPT
{
return date::year(static_cast<int>(y));
}
Expand Down Expand Up @@ -6784,7 +6784,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
checked_set(m, static_cast<int>(i % 12 + 1), not_a_month, is);
ws(is);
int td = not_a_day;
read(is, rs{td, 1, 2});
read(is, ru{td, 1, 2});
checked_set(d, td, not_a_day, is);
ws(is);
using dfs = detail::decimal_format_seconds<Duration>;
Expand All @@ -6800,7 +6800,9 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
not_a_second, is);
ws(is);
int tY = not_a_year;
read(is, rs{tY, 1, 4u});
// No need for `rs` here, negative years can't parse
// with "%c" since `width` is hardcoded to 4
read(is, ru{tY, 1, 4u});
checked_set(Y, tY, not_a_year, is);
#endif
}
Expand Down Expand Up @@ -6834,7 +6836,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
int tm = not_a_month;
int td = not_a_day;
read(is, ru{tm, 1, 2}, CharT{'/'}, ru{td, 1, 2}, CharT{'/'},
rs{ty, 1, 2});
ru{ty, 1, 2});
checked_set(y, ty, not_a_2digit_year, is);
checked_set(m, tm, not_a_month, is);
checked_set(d, td, not_a_day, is);
Expand Down Expand Up @@ -6930,7 +6932,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
int ty = not_a_2digit_year;
read(is, ru{tn, 1, 2}, CharT{'\0'}, CharT{'/'}, CharT{'\0'},
ru{td, 1, 2}, CharT{'\0'}, CharT{'/'}, CharT{'\0'},
rs{ty, 1, 2});
ru{ty, 1, 2});
checked_set(y, ty, not_a_2digit_year, is);
checked_set(m, tn, not_a_month, is);
checked_set(d, td, not_a_day, is);
Expand Down Expand Up @@ -6978,7 +6980,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#endif
{
int td = not_a_day;
read(is, rs{td, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
read(is, ru{td, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
checked_set(d, td, not_a_day, is);
}
#if !ONLY_C_LOCALE
Expand Down Expand Up @@ -7042,7 +7044,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
{
int tI = not_a_hour_12_value;
// reads in an hour into I, but most be in [1, 12]
read(is, rs{tI, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
read(is, ru{tI, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
if (!(1 <= tI && tI <= 12))
is.setstate(ios::failbit);
checked_set(I, tI, not_a_hour_12_value, is);
Expand Down Expand Up @@ -7116,7 +7118,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
#endif
{
int tn = not_a_month;
read(is, rs{tn, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
read(is, ru{tn, 1, width == -1 ? 2u : static_cast<unsigned>(width)});
checked_set(m, tn, not_a_month, is);
}
#if !ONLY_C_LOCALE
Expand Down Expand Up @@ -7536,7 +7538,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
}
if (modified == CharT{})
{
read(is, rs{tH, 2, 2});
read(is, ru{tH, 2, 2});
if (!is.fail())
toff = hours{std::abs(tH)};
if (is.good())
Expand All @@ -7556,7 +7558,7 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt,
}
else
{
read(is, rs{tH, 1, 2});
read(is, ru{tH, 1, 2});
if (!is.fail())
toff = hours{std::abs(tH)};
if (is.good())
Expand Down Expand Up @@ -8117,6 +8119,8 @@ struct parse_manip
#endif // HAS_STRING_VIEW
};

#ifdef _MSC_VER

template <class Parsable, class CharT, class Traits, class Alloc>
std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is,
Expand Down Expand Up @@ -8220,6 +8224,113 @@ parse(const CharT* format, Parsable& tp,
return {format, tp, &abbrev, &offset};
}

#else // !defined _MSC_VER

template <class Parsable, class CharT, class Traits, class Alloc>
std::basic_istream<CharT, Traits>&
operator>>(std::basic_istream<CharT, Traits>& is,
const parse_manip<Parsable, CharT, Traits, Alloc>& x)
{
return date::from_stream(is, x.format_.c_str(), x.tp_, x.abbrev_, x.offset_);
}

template <class Parsable, class CharT, class Traits, class Alloc>
inline
auto
parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp)
-> decltype(date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
format.c_str(), tp),
parse_manip<Parsable, CharT, Traits, Alloc>{format, tp})
{
return {format, tp};
}

template <class Parsable, class CharT, class Traits, class Alloc>
inline
auto
parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
std::basic_string<CharT, Traits, Alloc>& abbrev)
-> decltype(date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
format.c_str(), tp, &abbrev),
parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev})
{
return {format, tp, &abbrev};
}

template <class Parsable, class CharT, class Traits, class Alloc>
inline
auto
parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
std::chrono::minutes& offset)
-> decltype(date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
format.c_str(), tp,
std::declval<std::basic_string<CharT, Traits, Alloc>*>(),
&offset),
parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, nullptr, &offset})
{
return {format, tp, nullptr, &offset};
}

template <class Parsable, class CharT, class Traits, class Alloc>
inline
auto
parse(const std::basic_string<CharT, Traits, Alloc>& format, Parsable& tp,
std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
-> decltype(date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(),
format.c_str(), tp, &abbrev, &offset),
parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev, &offset})
{
return {format, tp, &abbrev, &offset};
}

// const CharT* formats

template <class Parsable, class CharT>
inline
auto
parse(const CharT* format, Parsable& tp)
-> decltype(date::from_stream(std::declval<std::basic_istream<CharT>&>(), format, tp),
parse_manip<Parsable, CharT>{format, tp})
{
return {format, tp};
}

template <class Parsable, class CharT, class Traits, class Alloc>
inline
auto
parse(const CharT* format, Parsable& tp, std::basic_string<CharT, Traits, Alloc>& abbrev)
-> decltype(date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format,
tp, &abbrev),
parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev})
{
return {format, tp, &abbrev};
}

template <class Parsable, class CharT>
inline
auto
parse(const CharT* format, Parsable& tp, std::chrono::minutes& offset)
-> decltype(date::from_stream(std::declval<std::basic_istream<CharT>&>(), format,
tp, std::declval<std::basic_string<CharT>*>(), &offset),
parse_manip<Parsable, CharT>{format, tp, nullptr, &offset})
{
return {format, tp, nullptr, &offset};
}

template <class Parsable, class CharT, class Traits, class Alloc>
inline
auto
parse(const CharT* format, Parsable& tp,
std::basic_string<CharT, Traits, Alloc>& abbrev, std::chrono::minutes& offset)
-> decltype(date::from_stream(std::declval<std::basic_istream<CharT, Traits>&>(), format,
tp, &abbrev, &offset),
parse_manip<Parsable, CharT, Traits, Alloc>{format, tp, &abbrev, &offset})
{
return {format, tp, &abbrev, &offset};
}

#endif // !defined _MSC_VER

// duration streaming

template <class CharT, class Traits, class Rep, class Period>
Expand Down