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
68214bd9
Commit
68214bd9
authored
Nov 30, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More time formatting
parent
bcf3fcd6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
11 deletions
+27
-11
include/fmt/time.h
include/fmt/time.h
+19
-10
test/time-test.cc
test/time-test.cc
+8
-1
No files found.
include/fmt/time.h
View file @
68214bd9
...
...
@@ -159,6 +159,17 @@ struct chrono_formatter {
out
=
format_decimal
<
char_type
>
(
out
,
n
,
num_digits
);
}
void
format_localized
(
const
tm
&
time
,
char
format
)
{
auto
locale
=
context
.
locale
().
template
get
<
std
::
locale
>();
auto
&
facet
=
std
::
use_facet
<
std
::
time_put
<
char_type
>>
(
locale
);
std
::
basic_ostringstream
<
char_type
>
os
;
os
.
imbue
(
locale
);
const
char
format_str
[]
=
{
'%'
,
'O'
,
format
};
facet
.
put
(
os
,
os
,
' '
,
&
time
,
format_str
,
format_str
+
sizeof
(
format_str
));
auto
str
=
os
.
str
();
std
::
copy
(
str
.
begin
(),
str
.
end
(),
out
);
}
void
on_text
(
const
char_type
*
begin
,
const
char_type
*
end
)
{
std
::
copy
(
begin
,
end
,
out
);
}
...
...
@@ -174,21 +185,19 @@ struct chrono_formatter {
auto
hour
=
(
s
.
count
()
/
3600
)
%
24
;
if
(
ns
==
numeric_system
::
standard
)
return
write
(
hour
,
2
);
auto
locale
=
context
.
locale
().
template
get
<
std
::
locale
>();
auto
&
facet
=
std
::
use_facet
<
std
::
time_put
<
char_type
>>
(
locale
);
std
::
basic_ostringstream
<
char_type
>
os
;
os
.
imbue
(
locale
);
auto
time
=
tm
();
time
.
tm_hour
=
hour
;
const
char
format
[]
=
{
'%'
,
'O'
,
'H'
};
facet
.
put
(
os
,
os
,
' '
,
&
time
,
format
,
format
+
sizeof
(
format
));
auto
str
=
os
.
str
();
std
::
copy
(
str
.
begin
(),
str
.
end
(),
out
);
format_localized
(
time
,
'H'
);
}
void
on_12_hour
(
numeric_system
)
{
void
on_12_hour
(
numeric_system
ns
)
{
auto
hour
=
(
s
.
count
()
/
3600
)
%
12
;
write
(
hour
>
0
?
hour
:
12
,
2
);
hour
=
hour
>
0
?
hour
:
12
;
if
(
ns
==
numeric_system
::
standard
)
return
write
(
hour
,
2
);
auto
time
=
tm
();
time
.
tm_hour
=
hour
;
format_localized
(
time
,
'I'
);
}
void
on_minute
(
numeric_system
)
{
...
...
test/time-test.cc
View file @
68214bd9
...
...
@@ -95,10 +95,17 @@ TEST(TimeTest, ChronoLocale) {
return
;
}
std
::
ostringstream
os
;
auto
str
=
[
&
]
{
auto
s
=
os
.
str
();
os
.
str
(
""
);
return
s
;
};
os
.
imbue
(
loc
);
auto
time
=
std
::
tm
();
time
.
tm_hour
=
14
;
os
<<
std
::
put_time
(
&
time
,
"%OH"
);
EXPECT_EQ
(
os
.
str
(),
fmt
::
format
(
loc
,
"{:%OH}"
,
std
::
chrono
::
hours
(
14
)));
EXPECT_EQ
(
str
(),
fmt
::
format
(
loc
,
"{:%OH}"
,
std
::
chrono
::
hours
(
14
)));
os
<<
std
::
put_time
(
&
time
,
"%OI"
);
EXPECT_EQ
(
str
(),
fmt
::
format
(
loc
,
"{:%OI}"
,
std
::
chrono
::
hours
(
14
)));
}
#endif
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