-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
hh_mm_ss
formatting for values >= 1 day (#3727)
Co-authored-by: Stephan T. Lavavej <[email protected]>
- Loading branch information
1 parent
47679bb
commit 99d36f5
Showing
6 changed files
with
78 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/std/tests/GH_003676_format_large_hh_mm_ss_values/env.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\concepts_20_matrix.lst |
50 changes: 50 additions & 0 deletions
50
tests/std/tests/GH_003676_format_large_hh_mm_ss_values/test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <cassert> | ||
#include <chrono> | ||
#include <format> | ||
#include <iostream> | ||
#include <sstream> | ||
#include <string> | ||
|
||
using namespace std; | ||
using namespace chrono; | ||
|
||
void assert_equal(const auto& expected, const auto& value) { | ||
if (expected == value) { | ||
return; | ||
} | ||
|
||
cout << "Expected: " << expected << endl; | ||
cout << "Got: " << value << endl; | ||
assert(false); | ||
} | ||
|
||
template <typename R, typename P> | ||
void assert_duration_format_equal(const duration<R, P>& dur, const string& str) { | ||
ostringstream oss; | ||
oss << hh_mm_ss{dur}; | ||
assert_equal(str, oss.str()); | ||
assert_equal(str, format("{:%T}", dur)); | ||
} | ||
|
||
template <typename R, typename P> | ||
void assert_duration_format_equal_positive(const duration<R, P>& dur, const string& str) { | ||
assert_duration_format_equal(dur, str); | ||
assert_duration_format_equal(-dur, '-' + str); | ||
} | ||
|
||
int main() { | ||
assert_duration_format_equal(0ns, "00:00:00.000000000"); | ||
assert_duration_format_equal(-0h, "00:00:00"); | ||
assert_duration_format_equal(years{0}, "00:00:00"); | ||
|
||
assert_duration_format_equal_positive(3h, "03:00:00"); | ||
assert_duration_format_equal_positive(10h + 20min + 30s, "10:20:30"); | ||
assert_duration_format_equal_positive(days{3}, "72:00:00"); | ||
assert_duration_format_equal_positive(years{1}, "8765:49:12"); | ||
assert_duration_format_equal_positive(duration<float, days::period>{1.55f}, "37:11:59"); | ||
assert_duration_format_equal_positive(2ms, "00:00:00.002"); | ||
assert_duration_format_equal_positive(60min, "01:00:00"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters