mirror of
https://github.com/HowardHinnant/date.git
synced 2025-01-14 01:37:57 +08:00
Have Posix::time_zone::name() put <> around non-alpha abbreviations
This commit is contained in:
parent
28972d72b4
commit
15e0c84e42
@ -62,6 +62,7 @@
|
|||||||
// have to have Posix time zones, you're welcome to use this one.
|
// have to have Posix time zones, you're welcome to use this one.
|
||||||
|
|
||||||
#include "date/tz.h"
|
#include "date/tz.h"
|
||||||
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -651,7 +652,18 @@ time_zone::name() const
|
|||||||
{
|
{
|
||||||
using namespace date;
|
using namespace date;
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
auto nm = std_abbrev_;
|
auto print_abbrev = [](std::string const& nm)
|
||||||
|
{
|
||||||
|
if (std::any_of(nm.begin(), nm.end(),
|
||||||
|
[](char c)
|
||||||
|
{
|
||||||
|
return !std::isalpha(c);
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
return '<' + nm + '>';
|
||||||
|
}
|
||||||
|
return nm;
|
||||||
|
};
|
||||||
auto print_offset = [](seconds off)
|
auto print_offset = [](seconds off)
|
||||||
{
|
{
|
||||||
std::string nm;
|
std::string nm;
|
||||||
@ -675,10 +687,11 @@ time_zone::name() const
|
|||||||
}
|
}
|
||||||
return nm;
|
return nm;
|
||||||
};
|
};
|
||||||
|
auto nm = print_abbrev(std_abbrev_);
|
||||||
nm += print_offset(offset_);
|
nm += print_offset(offset_);
|
||||||
if (!dst_abbrev_.empty())
|
if (!dst_abbrev_.empty())
|
||||||
{
|
{
|
||||||
nm += dst_abbrev_;
|
nm += print_abbrev(dst_abbrev_);
|
||||||
if (save_ != hours{1})
|
if (save_ != hours{1})
|
||||||
nm += print_offset(offset_+save_);
|
nm += print_offset(offset_+save_);
|
||||||
if (start_rule_.ok())
|
if (start_rule_.ok())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user