0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-19 19:33:45 +02:00

ircd: Add hours/minutes to lex_cast specialization suite.

This commit is contained in:
Jason Volk 2022-05-22 20:30:51 -07:00
parent c4bc8d1cc0
commit f5d3da8d3f
2 changed files with 60 additions and 0 deletions

View file

@ -60,6 +60,8 @@ namespace ircd
template<> bool lex_castable<uint8_t>(const string_view &) noexcept;
template<> bool lex_castable<int8_t>(const string_view &) noexcept;
template<> bool lex_castable<bool>(const string_view &) noexcept;
template<> bool lex_castable<hours>(const string_view &) noexcept;
template<> bool lex_castable<minutes>(const string_view &) noexcept;
template<> bool lex_castable<seconds>(const string_view &) noexcept;
template<> bool lex_castable<milliseconds>(const string_view &) noexcept;
template<> bool lex_castable<microseconds>(const string_view &) noexcept;
@ -81,6 +83,8 @@ namespace ircd
template<> uint8_t lex_cast(const string_view &);
template<> int8_t lex_cast(const string_view &);
template<> bool lex_cast(const string_view &);
template<> hours lex_cast(const string_view &);
template<> minutes lex_cast(const string_view &);
template<> seconds lex_cast(const string_view &);
template<> milliseconds lex_cast(const string_view &);
template<> microseconds lex_cast(const string_view &);
@ -89,6 +93,8 @@ namespace ircd
template<> string_view lex_cast(const std::string &, const mutable_buffer &buf);
template<> string_view lex_cast(const std::string_view &, const mutable_buffer &buf);
template<> string_view lex_cast(const string_view &, const mutable_buffer &buf);
template<> string_view lex_cast(hours, const mutable_buffer &buf);
template<> string_view lex_cast(minutes, const mutable_buffer &buf);
template<> string_view lex_cast(seconds, const mutable_buffer &buf);
template<> string_view lex_cast(milliseconds, const mutable_buffer &buf);
template<> string_view lex_cast(microseconds, const mutable_buffer &buf);

View file

@ -801,6 +801,60 @@ noexcept
return lex::test<long double, lex::is_long_double>(s);
}
//
// hours
//
template<> ircd::string_view
ircd::lex_cast(hours i,
const mutable_buffer &buf)
{
return lex::cast<time_t, lex::from_long>(buf, i.count());
}
template<> ircd::hours
ircd::lex_cast(const string_view &s)
{
return std::chrono::duration<time_t, std::ratio<3600L, 1L>>
(
lex::cast<time_t, lex::to_long>(s)
);
}
template<> bool
ircd::lex_castable<ircd::hours>(const string_view &s)
noexcept
{
return lex::test<time_t, lex::is_long>(s);
}
//
// minutes
//
template<> ircd::string_view
ircd::lex_cast(minutes i,
const mutable_buffer &buf)
{
return lex::cast<time_t, lex::from_long>(buf, i.count());
}
template<> ircd::minutes
ircd::lex_cast(const string_view &s)
{
return std::chrono::duration<time_t, std::ratio<60L, 1L>>
(
lex::cast<time_t, lex::to_long>(s)
);
}
template<> bool
ircd::lex_castable<ircd::minutes>(const string_view &s)
noexcept
{
return lex::test<time_t, lex::is_long>(s);
}
//
// seconds
//