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
4707373d
Commit
4707373d
authored
Oct 10, 2021
by
Vladislav Shchapov
Committed by
Victor Zverovich
Oct 16, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix year formatter
parent
79c00ad8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
+15
-4
include/fmt/chrono.h
include/fmt/chrono.h
+10
-4
test/chrono-test.cc
test/chrono-test.cc
+5
-0
No files found.
include/fmt/chrono.h
View file @
4707373d
...
@@ -1460,6 +1460,14 @@ template <typename FormatContext, typename OutputIt> struct tm_formatter {
...
@@ -1460,6 +1460,14 @@ template <typename FormatContext, typename OutputIt> struct tm_formatter {
void
write2
(
size_t
value
)
{
void
write2
(
size_t
value
)
{
out
=
std
::
copy_n
(
detail
::
digits2
(
value
),
2
,
out
);
out
=
std
::
copy_n
(
detail
::
digits2
(
value
),
2
,
out
);
}
}
void
write_year
(
int
year
)
{
if
(
year
>=
0
&&
year
<
10000
)
{
write2
(
to_unsigned
(
year
/
100
));
write2
(
to_unsigned
(
year
%
100
));
}
else
{
out
=
detail
::
write
<
char_type
>
(
out
,
year
);
}
}
explicit
tm_formatter
(
FormatContext
&
ctx_
,
OutputIt
out_
,
const
std
::
tm
&
tm_
)
explicit
tm_formatter
(
FormatContext
&
ctx_
,
OutputIt
out_
,
const
std
::
tm
&
tm_
)
:
ctx
(
ctx_
),
out
(
out_
),
tm
(
tm_
)
{}
:
ctx
(
ctx_
),
out
(
out_
),
tm
(
tm_
)
{}
...
@@ -1550,7 +1558,7 @@ template <typename FormatContext, typename OutputIt> struct tm_formatter {
...
@@ -1550,7 +1558,7 @@ template <typename FormatContext, typename OutputIt> struct tm_formatter {
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
)
{
out
=
detail
::
write
<
char_type
>
(
out
,
tm_year
());
write_year
(
tm_year
());
}
else
{
}
else
{
format_localized
(
'Y'
,
'E'
);
format_localized
(
'Y'
,
'E'
);
}
}
...
@@ -1607,9 +1615,7 @@ template <typename FormatContext, typename OutputIt> struct tm_formatter {
...
@@ -1607,9 +1615,7 @@ template <typename FormatContext, typename OutputIt> struct tm_formatter {
format_localized
(
'V'
,
'O'
);
format_localized
(
'V'
,
'O'
);
}
}
}
}
void
on_iso_week_based_year
()
{
void
on_iso_week_based_year
()
{
write_year
(
tm_iso_weak
().
year
);
}
out
=
detail
::
write
<
char_type
>
(
out
,
tm_iso_weak
().
year
);
}
void
on_iso_week_based_year_last2
()
{
void
on_iso_week_based_year_last2
()
{
write2
(
detail
::
to_unsigned
(
tm_split_year
(
tm_iso_weak
().
year
).
lower
));
write2
(
detail
::
to_unsigned
(
tm_split_year
(
tm_iso_weak
().
year
).
lower
));
}
}
...
...
test/chrono-test.cc
View file @
4707373d
...
@@ -60,6 +60,11 @@ TEST(chrono_test, format_tm) {
...
@@ -60,6 +60,11 @@ TEST(chrono_test, format_tm) {
EXPECT_EQ
(
fmt
::
format
(
"{:%F}"
,
tm
),
"2016-04-25"
);
EXPECT_EQ
(
fmt
::
format
(
"{:%F}"
,
tm
),
"2016-04-25"
);
EXPECT_EQ
(
fmt
::
format
(
"{:%T}"
,
tm
),
"11:22:33"
);
EXPECT_EQ
(
fmt
::
format
(
"{:%T}"
,
tm
),
"11:22:33"
);
// Short year
tm
.
tm_year
=
999
-
1900
;
EXPECT_EQ
(
fmt
::
format
(
"{:%Y}"
,
tm
),
"0999"
);
EXPECT_EQ
(
fmt
::
format
(
"{:%G}"
,
tm
),
"0998"
);
// for week on the year
// for week on the year
// https://www.cl.cam.ac.uk/~mgk25/iso-time.html
// https://www.cl.cam.ac.uk/~mgk25/iso-time.html
std
::
vector
<
std
::
string
>
str_tm_list
=
{
std
::
vector
<
std
::
string
>
str_tm_list
=
{
...
...
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