Skip to content

Commit 2a47b4b

Browse files
committed
chrono: gps_clock,gps_time例示コード調整
1 parent ca64b9a commit 2a47b4b

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

reference/chrono/gps_clock.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int main()
7272

7373
### 出力例
7474
```
75-
2019-10-24 11:15:37 GPS
75+
2019-10-24 11:15:37.493236171
7676
```
7777

7878
## バージョン
@@ -81,7 +81,7 @@ int main()
8181

8282
### 処理系
8383
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
84-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
84+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.1 [mark verified]
8585
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
8686

8787

reference/chrono/gps_clock/from_utc.md

+10-11
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@ using namespace std::chrono_literals;
5050
5151
int main()
5252
{
53-
// ここでは日単位のシステム時間を、utc_clockを経由して、日単位のGPS時間に変換している。
54-
// 秒単位の時間を渡せば、秒単位のGPS時間が返る
55-
auto st = chrono::sys_days{2019y/10/24};
56-
auto ut = chrono::utc_clock::from_sys(st);
57-
auto tt = chrono::gps_clock::from_utc(ut); // 日単位のGPS時間が返る
53+
// ここでは日単位のシステム時間を、秒単位のUTC時間とGPS時間に変換している。
54+
auto st = chrono::sys_days{2019y/10/24}; // システム時間,日単位
55+
auto ut = chrono::utc_clock::from_sys(st); // UTC時間,秒単位
56+
auto tt = chrono::gps_clock::from_utc(ut); // GPS時間,秒単位
5857
59-
// うるう秒
58+
// UTC時間のうるう秒に関する情報
6059
chrono::leap_second_info info = chrono::get_leap_second_info(ut);
6160
6261
std::cout << st << std::endl;
63-
std::cout << ut << std::endl;
64-
std::cout << tt << std::endl;
62+
std::cout << ut << " UTC" << std::endl;
63+
std::cout << tt << " GPS" << std::endl;
6564
std::cout << info.elapsed.count() << std::endl;
6665
}
6766
```
@@ -76,9 +75,9 @@ int main()
7675

7776
### 出力
7877
```
79-
2019-10-24 00:00:00
78+
2019-10-24
8079
2019-10-24 00:00:00 UTC
81-
2019-10-24 00:00:27 GPS
80+
2019-10-24 00:00:18 GPS
8281
27
8382
```
8483

@@ -88,5 +87,5 @@ int main()
8887

8988
### 処理系
9089
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
91-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
90+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.1 [mark verified]
9291
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]

reference/chrono/gps_clock/now.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main()
3838

3939
### 出力例
4040
```
41-
2019-10-24 11:15:37 GPS
41+
2019-10-24 11:15:51.428340077
4242
```
4343

4444
## バージョン
@@ -47,5 +47,5 @@ int main()
4747

4848
### 処理系
4949
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
50-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
50+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.1 [mark verified]
5151
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]

reference/chrono/gps_clock/to_utc.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ int main()
5757
// うるう秒
5858
chrono::leap_second_info info = chrono::get_leap_second_info(ut);
5959
60-
std::cout << tt << std::endl;
61-
std::cout << ut << std::endl;
60+
std::cout << tt << " GPS" << std::endl;
61+
std::cout << ut << " UTC" << std::endl;
6262
std::cout << info.elapsed.count() << std::endl;
6363
}
6464
```
@@ -73,7 +73,7 @@ int main()
7373

7474
### 出力
7575
```
76-
2019-10-24 00:00:27 GPS
76+
2019-10-24 00:00:18 GPS
7777
2019-10-24 00:00:00 UTC
7878
27
7979
```
@@ -84,5 +84,5 @@ int main()
8484

8585
### 処理系
8686
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
87-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
87+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.1 [mark verified]
8888
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]

reference/chrono/gps_time.md

+23-19
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int main()
105105

106106
#### 出力例
107107
```
108-
2019-10-24 11:15:27 GPS
108+
2019-10-24 11:15:27
109109
```
110110

111111
### 入力の例
@@ -128,32 +128,35 @@ int main()
128128

129129
if (ss) {
130130
std::cout << tp << std::endl;
131-
}
132-
else {
131+
} else {
133132
std::cout << "解析失敗" << std::endl;
134133
}
135134
}
136135

137136
// タイムゾーンを含む入力
138137
{
139138
std::stringstream ss;
140-
ss << "2019-10-24 20:15:10 GPS";
139+
ss << "2019-10-24 20:15:27 GPS";
141140

142141
chrono::gps_seconds tp;
143142
std::string abbrev;
144-
chrono::from_stream(ss, "%Y-%m-%d %H:%M:%S %Z%z", tp, &abbrev);
143+
chrono::from_stream(ss, "%Y-%m-%d %H:%M:%S %Z", tp, &abbrev);
145144

146-
std::cout << tp << std::endl;
147-
std::cout << abbrev << std::endl;
145+
if (ss) {
146+
std::cout << tp << std::endl;
147+
std::cout << abbrev << std::endl;
148+
} else {
149+
std::cout << "解析失敗" << std::endl;
150+
}
148151
}
149152
}
150153
```
151154
* chrono::from_stream[color ff0000]
152155
153-
#### 出力例
156+
#### 出力
154157
```
155-
2019-10-24 11:15:27 GPS
156-
2019-10-24 11:15:27 GPS
158+
2019-10-24 20:15:45
159+
2019-10-24 20:15:45
157160
GPS
158161
```
159162
@@ -168,7 +171,7 @@ namespace chrono = std::chrono;
168171
int main()
169172
{
170173
chrono::gps_clock::time_point now = chrono::gps_clock::now();
171-
chrono::gps_seconds now_sec = chrono::floor<chrono::seconds>(tp);
174+
chrono::gps_seconds now_sec = chrono::floor<chrono::seconds>(now);
172175
173176
// デフォルトフォーマット
174177
std::cout << std::format("1 : {}", now_sec) << std::endl;
@@ -177,25 +180,25 @@ int main()
177180
std::cout << std::format("2 : {:%Y年%m月%d日 %H時%M分%S秒}", now_sec) << std::endl;
178181
179182
// 日付を / (スラッシュ) 区切り、時間を : (コロン) 区切り、タイムゾーンの略称付き
180-
std::cout << std::format("3 : {0:%Y/%m/%d %H:%M:%S %Z}", now_sec) << std::endl;
183+
std::cout << std::format("3 : {:%Y/%m/%d %H:%M:%S %Z}", now_sec) << std::endl;
181184
182185
// 日付だけ出力
183-
std::cout << std::format("4 : %Y年%m月%d日", now_sec) << std::endl;
184-
std::cout << std::format("5 : %F", now_sec) << std::endl;
186+
std::cout << std::format("4 : {:%Y年%m月%d日}", now_sec) << std::endl;
187+
std::cout << std::format("5 : {:%F}", now_sec) << std::endl;
185188
186189
// 時間だけ出力
187-
std::cout << std::format("6 : %H時%M分%S秒", now_sec) << std::endl;
188-
std::cout << std::format("7 : %T", now_sec) << std::endl;
190+
std::cout << std::format("6 : {:%H時%M分%S秒}", now_sec) << std::endl;
191+
std::cout << std::format("7 : {:%T}", now_sec) << std::endl;
189192
}
190193
```
191194
* chrono::gps_clock[link gps_clock.md]
192195
* now()[link gps_clock/now.md]
193196
* chrono::floor[link time_point/floor.md]
194197
* std::format[link format.md]
195198

196-
#### 出力例
199+
#### 出力
197200
```
198-
1 : 2019-12-20 10:05:05 GPS
201+
1 : 2019-12-20 10:05:05
199202
2 : 2019年12月20日 10時05分05秒
200203
3 : 2019/12/20 10:05:05 GPS
201204
4 : 2019年12月20日
@@ -204,13 +207,14 @@ int main()
204207
7 : 10:05:05
205208
```
206209

210+
207211
## バージョン
208212
### 言語
209213
- C++20
210214

211215
### 処理系
212216
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
213-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
217+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 14.1 [mark verified]
214218
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
215219

216220

0 commit comments

Comments
 (0)