Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
a1d58630
Commit
a1d58630
authored
Oct 17, 2021
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor cleanup
parent
7a604cdd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
43 deletions
+44
-43
include/fmt/chrono.h
include/fmt/chrono.h
+44
-43
No files found.
include/fmt/chrono.h
View file @
a1d58630
...
@@ -1400,6 +1400,7 @@ struct tm_format_checker : null_chrono_spec_handler<tm_format_checker> {
...
@@ -1400,6 +1400,7 @@ struct tm_format_checker : null_chrono_spec_handler<tm_format_checker> {
};
};
template
<
typename
OutputIt
,
typename
Char
>
class
tm_writer
{
template
<
typename
OutputIt
,
typename
Char
>
class
tm_writer
{
private:
static
constexpr
int
days_per_week
=
7
;
static
constexpr
int
days_per_week
=
7
;
OutputIt
out_
;
OutputIt
out_
;
...
@@ -1413,10 +1414,7 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1413,10 +1414,7 @@ template <typename OutputIt, typename Char> class tm_writer {
// least 4 characters, with more only if necessary.
// least 4 characters, with more only if necessary.
auto
split_year_lower
(
int
year
)
const
noexcept
->
int
{
auto
split_year_lower
(
int
year
)
const
noexcept
->
int
{
auto
l
=
year
%
100
;
auto
l
=
year
%
100
;
if
(
l
<
0
)
{
if
(
l
<
0
)
l
=
-
l
;
// l in [0, 99]
// l in [0, 99]
l
=
-
l
;
}
return
l
;
return
l
;
}
}
...
@@ -1462,12 +1460,13 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1462,12 +1460,13 @@ template <typename OutputIt, typename Char> class tm_writer {
*
out_
++
=
*
d
++
;
*
out_
++
=
*
d
++
;
*
out_
++
=
*
d
;
*
out_
++
=
*
d
;
}
}
void
write_year
(
int
year
)
{
void
write_year
(
int
year
)
{
if
(
year
>=
0
&&
year
<
10000
)
{
if
(
year
>=
0
&&
year
<
10000
)
{
write2
(
to_unsigned
(
year
/
100
));
write2
(
to_unsigned
(
year
/
100
));
write2
(
to_unsigned
(
year
%
100
));
write2
(
to_unsigned
(
year
%
100
));
}
else
{
}
else
{
//
at least 4 characters
//
At least 4 characters.
int
width
=
4
;
int
width
=
4
;
if
(
year
<
0
)
{
if
(
year
<
0
)
{
*
out_
++
=
'-'
;
*
out_
++
=
'-'
;
...
@@ -1517,6 +1516,7 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1517,6 +1516,7 @@ template <typename OutputIt, typename Char> class tm_writer {
FMT_CONSTEXPR
void
on_text
(
const
Char
*
begin
,
const
Char
*
end
)
{
FMT_CONSTEXPR
void
on_text
(
const
Char
*
begin
,
const
Char
*
end
)
{
out_
=
copy_str
<
Char
>
(
begin
,
end
,
out_
);
out_
=
copy_str
<
Char
>
(
begin
,
end
,
out_
);
}
}
void
on_abbr_weekday
()
{
format_localized
(
'a'
);
}
void
on_abbr_weekday
()
{
format_localized
(
'a'
);
}
void
on_full_weekday
()
{
format_localized
(
'A'
);
}
void
on_full_weekday
()
{
format_localized
(
'A'
);
}
void
on_dec0_weekday
(
numeric_system
ns
)
{
void
on_dec0_weekday
(
numeric_system
ns
)
{
...
@@ -1531,6 +1531,7 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1531,6 +1531,7 @@ template <typename OutputIt, typename Char> class tm_writer {
else
else
format_localized
(
'u'
,
'O'
);
format_localized
(
'u'
,
'O'
);
}
}
void
on_abbr_month
()
{
format_localized
(
'b'
);
}
void
on_abbr_month
()
{
format_localized
(
'b'
);
}
void
on_full_month
()
{
format_localized
(
'B'
);
}
void
on_full_month
()
{
format_localized
(
'B'
);
}
...
@@ -1565,8 +1566,10 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1565,8 +1566,10 @@ template <typename OutputIt, typename Char> class tm_writer {
to_unsigned
(
tm_
.
tm_mday
),
'-'
);
to_unsigned
(
tm_
.
tm_mday
),
'-'
);
out_
=
copy_str
<
Char
>
(
std
::
begin
(
buf
)
+
offset
,
std
::
end
(
buf
),
out_
);
out_
=
copy_str
<
Char
>
(
std
::
begin
(
buf
)
+
offset
,
std
::
end
(
buf
),
out_
);
}
}
void
on_utc_offset
()
{
format_localized
(
'z'
);
}
void
on_utc_offset
()
{
format_localized
(
'z'
);
}
void
on_tz_name
()
{
format_localized
(
'Z'
);
}
void
on_tz_name
()
{
format_localized
(
'Z'
);
}
void
on_year
(
numeric_system
ns
)
{
void
on_year
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
if
(
ns
==
numeric_system
::
standard
)
write_year
(
tm_year
());
write_year
(
tm_year
());
...
@@ -1580,42 +1583,40 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1580,42 +1583,40 @@ template <typename OutputIt, typename Char> class tm_writer {
format_localized
(
'y'
,
'O'
);
format_localized
(
'y'
,
'O'
);
}
}
void
on_offset_year
()
{
format_localized
(
'y'
,
'E'
);
}
void
on_offset_year
()
{
format_localized
(
'y'
,
'E'
);
}
void
on_century
(
numeric_system
ns
)
{
void
on_century
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
{
if
(
ns
!=
numeric_system
::
standard
)
return
format_localized
(
'C'
,
'E'
);
auto
year
=
tm_year
();
auto
year
=
tm_year
();
auto
upper
=
year
/
100
;
auto
upper
=
year
/
100
;
if
(
year
>=
-
99
&&
year
<
0
)
{
if
(
year
>=
-
99
&&
year
<
0
)
{
// zero upper on negative year
// Zero upper on negative year.
*
out_
++
=
'-'
;
*
out_
++
=
'-'
;
*
out_
++
=
'0'
;
*
out_
++
=
'0'
;
}
else
if
(
upper
>=
0
&&
upper
<
100
)
}
else
if
(
upper
>=
0
&&
upper
<
100
)
{
write2
(
to_unsigned
(
upper
));
write2
(
to_unsigned
(
upper
));
else
}
else
{
out_
=
write
<
Char
>
(
out_
,
upper
);
out_
=
write
<
Char
>
(
out_
,
upper
);
}
else
}
format_localized
(
'C'
,
'E'
);
}
}
void
on_dec_month
(
numeric_system
ns
)
{
void
on_dec_month
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
if
(
ns
==
numeric_system
::
standard
)
write2
(
to_unsigned
(
tm_
.
tm_mon
+
1
));
write2
(
to_unsigned
(
tm_
.
tm_mon
+
1
));
else
else
format_localized
(
'm'
,
'O'
);
format_localized
(
'm'
,
'O'
);
}
}
void
on_dec0_week_of_year
(
numeric_system
ns
)
{
void
on_dec0_week_of_year
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
if
(
ns
!=
numeric_system
::
standard
)
return
format_localized
(
'U'
,
'O'
);
write2
(
to_unsigned
((
tm_
.
tm_yday
+
days_per_week
-
tm_
.
tm_wday
)
/
write2
(
to_unsigned
((
tm_
.
tm_yday
+
days_per_week
-
tm_
.
tm_wday
)
/
days_per_week
));
days_per_week
));
else
format_localized
(
'U'
,
'O'
);
}
}
void
on_dec1_week_of_year
(
numeric_system
ns
)
{
void
on_dec1_week_of_year
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
if
(
ns
!=
numeric_system
::
standard
)
return
format_localized
(
'W'
,
'O'
);
write2
(
to_unsigned
(
write2
(
to_unsigned
(
(
tm_
.
tm_yday
+
days_per_week
-
(
tm_
.
tm_yday
+
days_per_week
-
(
tm_
.
tm_wday
==
0
?
(
days_per_week
-
1
)
:
(
tm_
.
tm_wday
-
1
)))
/
(
tm_
.
tm_wday
==
0
?
(
days_per_week
-
1
)
:
(
tm_
.
tm_wday
-
1
)))
/
days_per_week
));
days_per_week
));
else
format_localized
(
'W'
,
'O'
);
}
}
void
on_iso_week_of_year
(
numeric_system
ns
)
{
void
on_iso_week_of_year
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
if
(
ns
==
numeric_system
::
standard
)
...
@@ -1623,10 +1624,12 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1623,10 +1624,12 @@ template <typename OutputIt, typename Char> class tm_writer {
else
else
format_localized
(
'V'
,
'O'
);
format_localized
(
'V'
,
'O'
);
}
}
void
on_iso_week_based_year
()
{
write_year
(
tm_iso_week_year
());
}
void
on_iso_week_based_year
()
{
write_year
(
tm_iso_week_year
());
}
void
on_iso_week_based_short_year
()
{
void
on_iso_week_based_short_year
()
{
write2
(
to_unsigned
(
split_year_lower
(
tm_iso_week_year
())));
write2
(
to_unsigned
(
split_year_lower
(
tm_iso_week_year
())));
}
}
void
on_day_of_year
()
{
void
on_day_of_year
()
{
auto
yday
=
tm_
.
tm_yday
+
1
;
auto
yday
=
tm_
.
tm_yday
+
1
;
write1
(
to_unsigned
(
yday
/
100
));
write1
(
to_unsigned
(
yday
/
100
));
...
@@ -1639,13 +1642,12 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1639,13 +1642,12 @@ template <typename OutputIt, typename Char> class tm_writer {
format_localized
(
'd'
,
'O'
);
format_localized
(
'd'
,
'O'
);
}
}
void
on_day_of_month_space
(
numeric_system
ns
)
{
void
on_day_of_month_space
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
{
if
(
ns
!=
numeric_system
::
standard
)
return
format_localized
(
'e'
,
'O'
);
const
char
*
d2
=
digits2
(
to_unsigned
(
tm_
.
tm_mday
));
const
char
*
d2
=
digits2
(
to_unsigned
(
tm_
.
tm_mday
));
*
out_
++
=
tm_
.
tm_mday
<
10
?
' '
:
d2
[
0
];
*
out_
++
=
tm_
.
tm_mday
<
10
?
' '
:
d2
[
0
];
*
out_
++
=
d2
[
1
];
*
out_
++
=
d2
[
1
];
}
else
format_localized
(
'e'
,
'O'
);
}
}
void
on_24_hour
(
numeric_system
ns
)
{
void
on_24_hour
(
numeric_system
ns
)
{
if
(
ns
==
numeric_system
::
standard
)
if
(
ns
==
numeric_system
::
standard
)
write2
(
to_unsigned
(
tm_
.
tm_hour
));
write2
(
to_unsigned
(
tm_
.
tm_hour
));
...
@@ -1670,6 +1672,7 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1670,6 +1672,7 @@ template <typename OutputIt, typename Char> class tm_writer {
else
else
format_localized
(
'S'
,
'O'
);
format_localized
(
'S'
,
'O'
);
}
}
void
on_12_hour_time
()
{
format_localized
(
'r'
);
}
void
on_12_hour_time
()
{
format_localized
(
'r'
);
}
void
on_24_hour_time
()
{
void
on_24_hour_time
()
{
write2
(
to_unsigned
(
tm_
.
tm_hour
));
write2
(
to_unsigned
(
tm_
.
tm_hour
));
...
@@ -1683,6 +1686,7 @@ template <typename OutputIt, typename Char> class tm_writer {
...
@@ -1683,6 +1686,7 @@ template <typename OutputIt, typename Char> class tm_writer {
':'
);
':'
);
out_
=
copy_str
<
Char
>
(
std
::
begin
(
buf
),
std
::
end
(
buf
),
out_
);
out_
=
copy_str
<
Char
>
(
std
::
begin
(
buf
),
std
::
end
(
buf
),
out_
);
}
}
void
on_am_pm
()
{
format_localized
(
'p'
);
}
void
on_am_pm
()
{
format_localized
(
'p'
);
}
// These apply to chrono durations but not tm.
// These apply to chrono durations but not tm.
...
@@ -1697,7 +1701,7 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
...
@@ -1697,7 +1701,7 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
Char
>
:
formatter
<
std
::
tm
,
Char
>
{
Char
>
:
formatter
<
std
::
tm
,
Char
>
{
FMT_CONSTEXPR
formatter
()
{
FMT_CONSTEXPR
formatter
()
{
this
->
do_parse
(
default_specs
,
this
->
do_parse
(
default_specs
,
default_specs
+
(
sizeof
(
default_specs
)
/
sizeof
(
Char
)
));
default_specs
+
sizeof
(
default_specs
)
/
sizeof
(
Char
));
}
}
template
<
typename
ParseContext
>
template
<
typename
ParseContext
>
...
@@ -1708,12 +1712,10 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
...
@@ -1708,12 +1712,10 @@ struct formatter<std::chrono::time_point<std::chrono::system_clock, Duration>,
template
<
typename
FormatContext
>
template
<
typename
FormatContext
>
auto
format
(
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
>
val
,
auto
format
(
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
>
val
,
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
FormatContext
&
ctx
)
->
decltype
(
ctx
.
out
())
{
std
::
tm
time
=
localtime
(
val
);
return
formatter
<
std
::
tm
,
Char
>::
format
(
localtime
(
val
),
ctx
);
return
formatter
<
std
::
tm
,
Char
>::
format
(
time
,
ctx
);
}
}
// '}' - for detail::parse_chrono_format.
static
constexpr
const
Char
default_specs
[]
=
{
'%'
,
'F'
,
' '
,
'%'
,
'T'
};
static
constexpr
const
Char
default_specs
[]
=
{
'%'
,
'F'
,
' '
,
'%'
,
'T'
,
'}'
};
};
};
template
<
typename
Char
,
typename
Duration
>
template
<
typename
Char
,
typename
Duration
>
...
@@ -1737,9 +1739,8 @@ template <typename Char> struct formatter<std::tm, Char> {
...
@@ -1737,9 +1739,8 @@ template <typename Char> struct formatter<std::tm, Char> {
->
It
{
->
It
{
if
(
begin
!=
end
&&
*
begin
==
':'
)
++
begin
;
if
(
begin
!=
end
&&
*
begin
==
':'
)
++
begin
;
end
=
detail
::
parse_chrono_format
(
begin
,
end
,
detail
::
tm_format_checker
());
end
=
detail
::
parse_chrono_format
(
begin
,
end
,
detail
::
tm_format_checker
());
if
(
!
with_default
||
end
!=
begin
)
{
if
(
!
with_default
||
end
!=
begin
)
specs
=
{
begin
,
detail
::
to_unsigned
(
end
-
begin
)};
specs
=
{
begin
,
detail
::
to_unsigned
(
end
-
begin
)};
}
// basic_string_view<>::compare isn't constexpr before C++17
// basic_string_view<>::compare isn't constexpr before C++17
if
(
specs
.
size
()
==
2
&&
specs
[
0
]
==
Char
(
'%'
))
{
if
(
specs
.
size
()
==
2
&&
specs
[
0
]
==
Char
(
'%'
))
{
if
(
specs
[
1
]
==
Char
(
'F'
))
if
(
specs
[
1
]
==
Char
(
'F'
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment