mirror of
https://github.com/HowardHinnant/date.git
synced 2024-12-27 08:31:03 +08:00
Lots of minor changes motivated by reviews of the draft proposal
This commit is contained in:
parent
501609bacf
commit
806c29fddc
16
date.h
16
date.h
@ -3873,7 +3873,7 @@ template <class Rep, class Period,
|
||||
CONSTCD11
|
||||
inline
|
||||
time_of_day<std::chrono::duration<Rep, Period>>
|
||||
make_time(std::chrono::duration<Rep, Period> d) NOEXCEPT
|
||||
make_time(const std::chrono::duration<Rep, Period>& d)
|
||||
{
|
||||
return time_of_day<std::chrono::duration<Rep, Period>>(d);
|
||||
}
|
||||
@ -3881,7 +3881,7 @@ make_time(std::chrono::duration<Rep, Period> d) NOEXCEPT
|
||||
CONSTCD11
|
||||
inline
|
||||
time_of_day<std::chrono::hours>
|
||||
make_time(std::chrono::hours h, unsigned md) NOEXCEPT
|
||||
make_time(const std::chrono::hours& h, unsigned md)
|
||||
{
|
||||
return time_of_day<std::chrono::hours>(h, md);
|
||||
}
|
||||
@ -3889,7 +3889,8 @@ make_time(std::chrono::hours h, unsigned md) NOEXCEPT
|
||||
CONSTCD11
|
||||
inline
|
||||
time_of_day<std::chrono::minutes>
|
||||
make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) NOEXCEPT
|
||||
make_time(const std::chrono::hours& h, const std::chrono::minutes& m,
|
||||
unsigned md)
|
||||
{
|
||||
return time_of_day<std::chrono::minutes>(h, m, md);
|
||||
}
|
||||
@ -3897,8 +3898,8 @@ make_time(std::chrono::hours h, std::chrono::minutes m, unsigned md) NOEXCEPT
|
||||
CONSTCD11
|
||||
inline
|
||||
time_of_day<std::chrono::seconds>
|
||||
make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
|
||||
unsigned md) NOEXCEPT
|
||||
make_time(const std::chrono::hours& h, const std::chrono::minutes& m,
|
||||
const std::chrono::seconds& s, unsigned md)
|
||||
{
|
||||
return time_of_day<std::chrono::seconds>(h, m, s, md);
|
||||
}
|
||||
@ -3909,8 +3910,9 @@ template <class Rep, class Period,
|
||||
CONSTCD11
|
||||
inline
|
||||
time_of_day<std::chrono::duration<Rep, Period>>
|
||||
make_time(std::chrono::hours h, std::chrono::minutes m, std::chrono::seconds s,
|
||||
std::chrono::duration<Rep, Period> sub_s, unsigned md) NOEXCEPT
|
||||
make_time(const std::chrono::hours& h, const std::chrono::minutes& m,
|
||||
const std::chrono::seconds& s, const std::chrono::duration<Rep, Period>& sub_s,
|
||||
unsigned md)
|
||||
{
|
||||
return time_of_day<std::chrono::duration<Rep, Period>>(h, m, s, sub_s, md);
|
||||
}
|
||||
|
27
tz.cpp
27
tz.cpp
@ -2977,33 +2977,6 @@ operator<<(std::ostream& os, const TZ_DB& db)
|
||||
|
||||
// -----------------------
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const sys_info& r)
|
||||
{
|
||||
os << r.begin << '\n';
|
||||
os << r.end << '\n';
|
||||
os << make_time(r.offset) << "\n";
|
||||
os << make_time(r.save) << "\n";
|
||||
os << r.abbrev << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream& os, const local_info& r)
|
||||
{
|
||||
if (r.result == local_info::nonexistent)
|
||||
os << "nonexistent between\n";
|
||||
else if (r.result == local_info::ambiguous)
|
||||
os << "ambiguous between\n";
|
||||
os << r.first;
|
||||
if (r.result != local_info::unique)
|
||||
{
|
||||
os << "and\n";
|
||||
os << r.second;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
const time_zone*
|
||||
|
116
tz.h
116
tz.h
@ -212,7 +212,17 @@ struct sys_info
|
||||
std::string abbrev;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const sys_info& r);
|
||||
template<class CharT, class Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
operator<<(std::basic_ostream<CharT, Traits>& os, const sys_info& r)
|
||||
{
|
||||
os << r.begin << '\n';
|
||||
os << r.end << '\n';
|
||||
os << make_time(r.offset) << "\n";
|
||||
os << make_time(r.save) << "\n";
|
||||
os << r.abbrev << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
struct local_info
|
||||
{
|
||||
@ -221,7 +231,22 @@ struct local_info
|
||||
sys_info second;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const local_info& r);
|
||||
template<class CharT, class Traits>
|
||||
std::basic_ostream<CharT, Traits>&
|
||||
operator<<(std::basic_ostream<CharT, Traits>& os, const local_info& r)
|
||||
{
|
||||
if (r.result == local_info::nonexistent)
|
||||
os << "nonexistent between\n";
|
||||
else if (r.result == local_info::ambiguous)
|
||||
os << "ambiguous between\n";
|
||||
os << r.first;
|
||||
if (r.result != local_info::unique)
|
||||
{
|
||||
os << "and\n";
|
||||
os << r.second;
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
class time_zone;
|
||||
|
||||
@ -232,7 +257,7 @@ class zoned_time
|
||||
sys_time<Duration> tp_;
|
||||
|
||||
public:
|
||||
zoned_time(sys_time<Duration> st);
|
||||
zoned_time(const sys_time<Duration>& st);
|
||||
explicit zoned_time(const time_zone* z);
|
||||
explicit zoned_time(const std::string& name);
|
||||
|
||||
@ -244,10 +269,10 @@ public:
|
||||
>::type>
|
||||
zoned_time(const zoned_time<Duration2>& zt) NOEXCEPT;
|
||||
|
||||
zoned_time(const time_zone* z, local_time<Duration> tp);
|
||||
zoned_time(const std::string& name, local_time<Duration> tp);
|
||||
zoned_time(const time_zone* z, local_time<Duration> tp, choose c);
|
||||
zoned_time(const std::string& name, local_time<Duration> tp, choose c);
|
||||
zoned_time(const time_zone* z, const local_time<Duration>& tp);
|
||||
zoned_time(const std::string& name, const local_time<Duration>& tp);
|
||||
zoned_time(const time_zone* z, const local_time<Duration>& tp, choose c);
|
||||
zoned_time(const std::string& name, const local_time<Duration>& tp, choose c);
|
||||
|
||||
zoned_time(const time_zone* z, const zoned_time<Duration>& zt);
|
||||
zoned_time(const std::string& name, const zoned_time<Duration>& zt);
|
||||
@ -257,8 +282,8 @@ public:
|
||||
zoned_time(const time_zone* z, const sys_time<Duration>& st);
|
||||
zoned_time(const std::string& name, const sys_time<Duration>& st);
|
||||
|
||||
zoned_time& operator=(sys_time<Duration> st);
|
||||
zoned_time& operator=(local_time<Duration> ut);
|
||||
zoned_time& operator=(const sys_time<Duration>& st);
|
||||
zoned_time& operator=(const local_time<Duration>& ut);
|
||||
|
||||
operator sys_time<Duration>() const;
|
||||
explicit operator local_time<Duration>() const;
|
||||
@ -328,7 +353,7 @@ public:
|
||||
|
||||
explicit time_zone(const std::string& s, detail::undocumented);
|
||||
|
||||
const std::string& name() const;
|
||||
const std::string& name() const NOEXCEPT;
|
||||
|
||||
template <class Duration> sys_info get_info(sys_time<Duration> st) const;
|
||||
template <class Duration> local_info get_info(local_time<Duration> tp) const;
|
||||
@ -345,8 +370,8 @@ public:
|
||||
local_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_local(sys_time<Duration> tp) const;
|
||||
|
||||
friend bool operator==(const time_zone& x, const time_zone& y);
|
||||
friend bool operator< (const time_zone& x, const time_zone& y);
|
||||
friend bool operator==(const time_zone& x, const time_zone& y) NOEXCEPT;
|
||||
friend bool operator< (const time_zone& x, const time_zone& y) NOEXCEPT;
|
||||
friend std::ostream& operator<<(std::ostream& os, const time_zone& z);
|
||||
|
||||
void add(const std::string& s);
|
||||
@ -394,7 +419,7 @@ time_zone::operator=(time_zone&& src)
|
||||
|
||||
inline
|
||||
const std::string&
|
||||
time_zone::name() const
|
||||
time_zone::name() const NOEXCEPT
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
@ -443,13 +468,13 @@ time_zone::to_local(sys_time<Duration> tp) const
|
||||
return LT{(tp + i.offset).time_since_epoch()};
|
||||
}
|
||||
|
||||
inline bool operator==(const time_zone& x, const time_zone& y) {return x.name_ == y.name_;}
|
||||
inline bool operator< (const time_zone& x, const time_zone& y) {return x.name_ < y.name_;}
|
||||
inline bool operator==(const time_zone& x, const time_zone& y) NOEXCEPT {return x.name_ == y.name_;}
|
||||
inline bool operator< (const time_zone& x, const time_zone& y) NOEXCEPT {return x.name_ < y.name_;}
|
||||
|
||||
inline bool operator!=(const time_zone& x, const time_zone& y) {return !(x == y);}
|
||||
inline bool operator> (const time_zone& x, const time_zone& y) {return y < x;}
|
||||
inline bool operator<=(const time_zone& x, const time_zone& y) {return !(y < x);}
|
||||
inline bool operator>=(const time_zone& x, const time_zone& y) {return !(x < y);}
|
||||
inline bool operator!=(const time_zone& x, const time_zone& y) NOEXCEPT {return !(x == y);}
|
||||
inline bool operator> (const time_zone& x, const time_zone& y) NOEXCEPT {return y < x;}
|
||||
inline bool operator<=(const time_zone& x, const time_zone& y) NOEXCEPT {return !(y < x);}
|
||||
inline bool operator>=(const time_zone& x, const time_zone& y) NOEXCEPT {return !(x < y);}
|
||||
|
||||
template <class Duration>
|
||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
@ -750,7 +775,7 @@ const time_zone* current_zone();
|
||||
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<Duration>::zoned_time(sys_time<Duration> st)
|
||||
zoned_time<Duration>::zoned_time(const sys_time<Duration>& st)
|
||||
: zone_(locate_zone("UTC"))
|
||||
, tp_(st)
|
||||
{}
|
||||
@ -769,27 +794,28 @@ zoned_time<Duration>::zoned_time(const std::string& name)
|
||||
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, local_time<Duration> t)
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, const local_time<Duration>& t)
|
||||
: zone_(z)
|
||||
, tp_(z->to_sys(t))
|
||||
{}
|
||||
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, local_time<Duration> t)
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, const local_time<Duration>& t)
|
||||
: zoned_time(locate_zone(name), t)
|
||||
{}
|
||||
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, local_time<Duration> t, choose c)
|
||||
zoned_time<Duration>::zoned_time(const time_zone* z, const local_time<Duration>& t,
|
||||
choose c)
|
||||
: zone_(z)
|
||||
, tp_(z->to_sys(t, c))
|
||||
{}
|
||||
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, local_time<Duration> t,
|
||||
zoned_time<Duration>::zoned_time(const std::string& name, const local_time<Duration>& t,
|
||||
choose c)
|
||||
: zoned_time(locate_zone(name), t, c)
|
||||
{}
|
||||
@ -845,7 +871,7 @@ zoned_time<Duration>::zoned_time(const std::string& name, const sys_time<Duratio
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<Duration>&
|
||||
zoned_time<Duration>::operator=(sys_time<Duration> st)
|
||||
zoned_time<Duration>::operator=(const sys_time<Duration>& st)
|
||||
{
|
||||
tp_ = st;
|
||||
return *this;
|
||||
@ -854,7 +880,7 @@ zoned_time<Duration>::operator=(sys_time<Duration> st)
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<Duration>&
|
||||
zoned_time<Duration>::operator=(local_time<Duration> ut)
|
||||
zoned_time<Duration>::operator=(const local_time<Duration>& ut)
|
||||
{
|
||||
tp_ = zone_->to_sys(ut);
|
||||
return *this;
|
||||
@ -911,7 +937,7 @@ zoned_time<Duration>::get_info() const
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
make_zoned(sys_time<Duration> tp)
|
||||
make_zoned(const sys_time<Duration>& tp)
|
||||
{
|
||||
return {tp};
|
||||
}
|
||||
@ -919,7 +945,7 @@ make_zoned(sys_time<Duration> tp)
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
make_zoned(const time_zone* zone, local_time<Duration> tp)
|
||||
make_zoned(const time_zone* zone, const local_time<Duration>& tp)
|
||||
{
|
||||
return {zone, tp};
|
||||
}
|
||||
@ -927,7 +953,7 @@ make_zoned(const time_zone* zone, local_time<Duration> tp)
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
make_zoned(const std::string& name, local_time<Duration> tp)
|
||||
make_zoned(const std::string& name, const local_time<Duration>& tp)
|
||||
{
|
||||
return {name, tp};
|
||||
}
|
||||
@ -935,7 +961,7 @@ make_zoned(const std::string& name, local_time<Duration> tp)
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
make_zoned(const time_zone* zone, local_time<Duration> tp, choose c)
|
||||
make_zoned(const time_zone* zone, const local_time<Duration>& tp, choose c)
|
||||
{
|
||||
return {zone, tp, c};
|
||||
}
|
||||
@ -943,7 +969,7 @@ make_zoned(const time_zone* zone, local_time<Duration> tp, choose c)
|
||||
template <class Duration>
|
||||
inline
|
||||
zoned_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
make_zoned(const std::string& name, local_time<Duration> tp, choose c)
|
||||
make_zoned(const std::string& name, const local_time<Duration>& tp, choose c)
|
||||
{
|
||||
return {name, tp, c};
|
||||
}
|
||||
@ -1015,7 +1041,7 @@ public:
|
||||
using time_point = std::chrono::time_point<utc_clock>;
|
||||
static CONSTDATA bool is_steady = false;
|
||||
|
||||
static time_point now() NOEXCEPT;
|
||||
static time_point now();
|
||||
};
|
||||
|
||||
template <class Duration>
|
||||
@ -1026,7 +1052,7 @@ using utc_seconds = utc_time<std::chrono::seconds>;
|
||||
template <class Duration>
|
||||
inline
|
||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_utc_time(sys_time<Duration> st)
|
||||
to_utc_time(const sys_time<Duration>& st)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using duration = typename std::common_type<Duration, seconds>::type;
|
||||
@ -1038,7 +1064,7 @@ to_utc_time(sys_time<Duration> st)
|
||||
template <class Duration>
|
||||
inline
|
||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_sys_time(utc_time<Duration> ut)
|
||||
to_sys_time(const utc_time<Duration>& ut)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using duration = typename std::common_type<Duration, seconds>::type;
|
||||
@ -1061,7 +1087,7 @@ to_sys_time(utc_time<Duration> ut)
|
||||
|
||||
inline
|
||||
utc_clock::time_point
|
||||
utc_clock::now() NOEXCEPT
|
||||
utc_clock::now()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
return to_utc_time(system_clock::now());
|
||||
@ -1117,7 +1143,7 @@ using tai_seconds = tai_time<std::chrono::seconds>;
|
||||
template <class Duration>
|
||||
inline
|
||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_utc_time(tai_time<Duration> t) NOEXCEPT
|
||||
to_utc_time(const tai_time<Duration>& t) NOEXCEPT
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using duration = typename std::common_type<Duration, seconds>::type;
|
||||
@ -1128,7 +1154,7 @@ to_utc_time(tai_time<Duration> t) NOEXCEPT
|
||||
template <class Duration>
|
||||
inline
|
||||
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_tai_time(utc_time<Duration> t) NOEXCEPT
|
||||
to_tai_time(const utc_time<Duration>& t) NOEXCEPT
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using duration = typename std::common_type<Duration, seconds>::type;
|
||||
@ -1139,7 +1165,7 @@ to_tai_time(utc_time<Duration> t) NOEXCEPT
|
||||
template <class Duration>
|
||||
inline
|
||||
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_tai_time(sys_time<Duration> t)
|
||||
to_tai_time(const sys_time<Duration>& t)
|
||||
{
|
||||
return to_tai_time(to_utc_time(t));
|
||||
}
|
||||
@ -1185,7 +1211,7 @@ using gps_seconds = gps_time<std::chrono::seconds>;
|
||||
template <class Duration>
|
||||
inline
|
||||
utc_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_utc_time(gps_time<Duration> t) NOEXCEPT
|
||||
to_utc_time(const gps_time<Duration>& t) NOEXCEPT
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using duration = typename std::common_type<Duration, seconds>::type;
|
||||
@ -1196,7 +1222,7 @@ to_utc_time(gps_time<Duration> t) NOEXCEPT
|
||||
template <class Duration>
|
||||
inline
|
||||
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_gps_time(utc_time<Duration> t)
|
||||
to_gps_time(const utc_time<Duration>& t)
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using duration = typename std::common_type<Duration, seconds>::type;
|
||||
@ -1207,7 +1233,7 @@ to_gps_time(utc_time<Duration> t)
|
||||
template <class Duration>
|
||||
inline
|
||||
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_gps_time(sys_time<Duration> t)
|
||||
to_gps_time(const sys_time<Duration>& t)
|
||||
{
|
||||
return to_gps_time(to_utc_time(t));
|
||||
}
|
||||
@ -1234,7 +1260,7 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const gps_time<Duration>& t)
|
||||
template <class Duration>
|
||||
inline
|
||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_sys_time(tai_time<Duration> t)
|
||||
to_sys_time(const tai_time<Duration>& t)
|
||||
{
|
||||
return to_sys_time(to_utc_time(t));
|
||||
}
|
||||
@ -1242,7 +1268,7 @@ to_sys_time(tai_time<Duration> t)
|
||||
template <class Duration>
|
||||
inline
|
||||
sys_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_sys_time(gps_time<Duration> t)
|
||||
to_sys_time(const gps_time<Duration>& t)
|
||||
{
|
||||
return to_sys_time(to_utc_time(t));
|
||||
}
|
||||
@ -1250,7 +1276,7 @@ to_sys_time(gps_time<Duration> t)
|
||||
template <class Duration>
|
||||
inline
|
||||
tai_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_tai_time(gps_time<Duration> t) NOEXCEPT
|
||||
to_tai_time(const gps_time<Duration>& t) NOEXCEPT
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using duration = typename std::common_type<Duration, seconds>::type;
|
||||
@ -1261,7 +1287,7 @@ to_tai_time(gps_time<Duration> t) NOEXCEPT
|
||||
template <class Duration>
|
||||
inline
|
||||
gps_time<typename std::common_type<Duration, std::chrono::seconds>::type>
|
||||
to_gps_time(tai_time<Duration> t) NOEXCEPT
|
||||
to_gps_time(const tai_time<Duration>& t) NOEXCEPT
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using duration = typename std::common_type<Duration, seconds>::type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user