Skip to content

Commit a7f9e6c

Browse files
committed
chrono::parse, (sys | tai | utc | file)_time : コード例と出力の修正、動作確認
parse や from_stream の %Z には「+」や数字も含められるので、「JST+0900」のような文字列が %Z にヒットします。 %Z と %z で分けて解析したい場合は空白を挟む必要があります。 上記を考慮しコード例を修正し、動作確認を行いました。 動作確認の際に発見したコードや出力の誤りも修正しています。
1 parent 5ab35d5 commit a7f9e6c

File tree

5 files changed

+27
-26
lines changed

5 files changed

+27
-26
lines changed

reference/chrono/file_time.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ namespace std {
7474
```cpp example
7575
#include <iostream>
7676
#include <fstream>
77+
#include <chrono>
7778
#include <filesystem>
7879
#include <fstream>
7980
@@ -85,7 +86,7 @@ int main()
8586
std::ofstream{"regular.txt"};
8687
8788
// ファイルの最終更新日時を取得して出力
88-
fs::file_time_type tp = fs::last_write_time("regulat.txt");
89+
fs::file_time_type tp = fs::last_write_time("regular.txt");
8990
std::cout << tp << std::endl;
9091
}
9192
```
@@ -94,7 +95,7 @@ int main()
9495

9596
#### 出力例
9697
```
97-
2019-10-24 11:15:10 UTC
98+
2019-10-24 11:15:10
9899
```
99100

100101
### 入力の例
@@ -128,12 +129,12 @@ int main()
128129
// タイムゾーンとオフセットを含む入力
129130
{
130131
std::stringstream ss;
131-
ss << "2019-10-24 20:15:10 UTC+0900";
132+
ss << "2019-10-24 20:15:10 UTC +0900";
132133

133134
fs::file_time_type tp;
134135
std::string abbrev;
135136
chrono::minutes offset{0};
136-
chrono::from_stream(ss, "%Y-%m-%d %H:%M:%S %Z%z", tp, &abbrev, &offset);
137+
chrono::from_stream(ss, "%Y-%m-%d %H:%M:%S %Z %z", tp, &abbrev, &offset);
137138

138139
std::cout << tp << std::endl;
139140
std::cout << abbrev << std::endl;
@@ -146,8 +147,8 @@ int main()
146147
147148
#### 出力例
148149
```
149-
2019-10-24 11:15:10 UTC
150-
2019-10-24 11:15:10 UTC
150+
2019-10-24 11:15:10
151+
2019-10-24 11:15:10
151152
UTC
152153
540
153154
```
@@ -168,7 +169,7 @@ int main()
168169
std::ofstream{"regular.txt"};
169170
170171
// ファイルの最終更新日時を取得して出力
171-
fs::file_time_type tp = fs::last_write_time("regulat.txt");
172+
fs::file_time_type tp = fs::last_write_time("regular.txt");
172173
173174
// デフォルトフォーマット
174175
std::cout << std::format("1 : {}", tp) << std::endl;
@@ -194,7 +195,7 @@ int main()
194195

195196
#### 出力例
196197
```
197-
1 : 2019-12-20 10:05:00 UTC
198+
1 : 2019-12-20 10:05:00
198199
2 : 2019年12月20日 10時05分05秒
199200
3 : 2019/12/20 10:05:05
200201
4 : 2019年12月20日
@@ -210,7 +211,7 @@ int main()
210211

211212
### 処理系
212213
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
213-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
214+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 15.1 [mark verified]
214215
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
215216

216217

reference/chrono/parse.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace std::chrono {
8080
| `%y` | 10進数での年のうしろ2桁。世紀が (`%C`などで) 指定されない場合、範囲`[69, 99]`は1969年から1999年を参照し、範囲`[00, 68]`は2000年から2068年を参照する。改良コマンド`%Ny` (Nは10進整数) によって読み込む最大の文字数を指定できる。Nを指定しない場合、デフォルトは2。先頭の0は許可されるが要求はされない。改良コマンド`%Ey`または`%Oy`はロケール依存の異なる表現になる。 | `"20"`<br/> `%Ey`では (元号ベースの下2桁年) `"02"` |
8181
| `%Y` | 10進数での年。改良コマンド`%NY` (Nは10進整数) によって読み込む最大の文字数を指定できる。Nを指定しない場合、デフォルトは4。先頭の0は許可されるが要求はされない。改良コマンド`%EY`はロケール依存の異なる表現になる | `"2020"`<br/> `%EY`では`"令和02年"` |
8282
| `%z` | `[+|-]hh[mm]`フォーマットでのUTCタイムゾーンからのオフセット時間 (`[ ]`カッコ内は省略可能)。例として`-0430`はUTCから4時間30分遅れていることを表す。 改良コマンド`%Ez`と`%Oz`は、時と分の間にコロン (`:`) が要求され、時の先頭のゼロは省略できる`[+|-]h[h][:mm]`フォーマットとなる。 | `"+0900"`<br/>`%Ez`では`"9"` |
83-
| `%Z` | タイムゾーンの略称。単一の単語を解析する。この単語に含めることができるのは、基本文字集合の英数字または`'_'`, `'/'`, `'-'`, `'+'`の文字のみ。 | `"JST"` |
83+
| `%Z` | タイムゾーンの略称。単一の単語を解析する。この単語に含めることができるのは、基本文字集合の英数字または`'_'`, `'/'`, `'-'`, `'+'`の文字のみ。 | `"JST"`<br/> `"JST+0900"` |
8484
| `%%` | 文字`%`を抽出する | `"%"` |
8585
8686
@@ -138,12 +138,12 @@ int main()
138138
// タイムゾーン情報を含む日時の解析
139139
{
140140
std::stringstream ss;
141-
ss << "2019-10-24 20:15:10 JST+0900";
141+
ss << "2019-10-24 20:15:10 JST +0900";
142142
143143
chrono::sys_seconds tp;
144144
std::string abbrev;
145145
chrono::minutes offset;
146-
ss >> chrono::parse("%Y-%m-%d %H:%M:%S %Z%z", tp, abbrev, offset);
146+
ss >> chrono::parse("%Y-%m-%d %H:%M:%S %Z %z", tp, abbrev, offset);
147147
148148
if (ss) {
149149
std::cout << tp << std::endl;
@@ -174,7 +174,7 @@ JST
174174

175175
### 処理系
176176
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
177-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
177+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 15.1 [mark verified]
178178
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
179179

180180

reference/chrono/sys_time.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ int main()
182182
// タイムゾーンとオフセットを含む入力
183183
{
184184
std::stringstream ss;
185-
ss << "2019-10-24 20:15:10 JST+0900";
185+
ss << "2019-10-24 20:15:10 JST +0900";
186186

187187
chrono::sys_seconds tp;
188188
std::string abbrev;
189189
chrono::minutes offset{0};
190-
chrono::from_stream(ss, "%Y-%m-%d %H:%M:%S %Z%z", tp, &abbrev, &offset);
190+
chrono::from_stream(ss, "%Y-%m-%d %H:%M:%S %Z %z", tp, &abbrev, &offset);
191191

192192
std::cout << tp << std::endl;
193193
std::cout << abbrev << std::endl;
@@ -244,7 +244,7 @@ int main()
244244

245245
#### 出力例
246246
```
247-
1 : 2019-12-20 10:05:05 UTC
247+
1 : 2019-12-20 10:05:05
248248
2 : 2019年12月20日 10時05分05秒
249249
3 : 2019/12/20 10:05:05 UTC
250250
4 : 2019年12月20日
@@ -259,7 +259,7 @@ int main()
259259

260260
### 処理系
261261
- [Clang](/implementation.md#clang): 8.0 (入出力ストリームなし) [mark verified]
262-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
262+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 15.1 [mark verified]
263263
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
264264

265265

reference/chrono/tai_time.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int main()
104104

105105
#### 出力例
106106
```
107-
2019-10-24 11:15:37 TAI
107+
2019-10-24 11:15:37
108108
```
109109

110110
### 入力の例
@@ -140,7 +140,7 @@ int main()
140140

141141
chrono::tai_seconds tp;
142142
std::string abbrev;
143-
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);
144144

145145
std::cout << tp << std::endl;
146146
std::cout << abbrev << std::endl;
@@ -194,7 +194,7 @@ int main()
194194

195195
#### 出力例
196196
```
197-
1 : 2019-12-20 10:05:05 TAI
197+
1 : 2019-12-20 10:05:05
198198
2 : 2019年12月20日 10時05分05秒
199199
3 : 2019/12/20 10:05:05 TAI
200200
4 : 2019年12月20日
@@ -209,7 +209,7 @@ int main()
209209

210210
### 処理系
211211
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
212-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
212+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 15.1 [mark verified]
213213
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
214214

215215

reference/chrono/utc_time.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int main()
9595

9696
#### 出力例
9797
```
98-
2019-10-24 11:15:10 UTC
98+
2019-10-24 11:15:10
9999
```
100100

101101
### 入力の例
@@ -127,12 +127,12 @@ int main()
127127
// タイムゾーンとオフセットを含む入力
128128
{
129129
std::stringstream ss;
130-
ss << "2019-10-24 20:15:10 UTC+0900";
130+
ss << "2019-10-24 20:15:10 UTC +0900";
131131

132132
chrono::utc_seconds tp;
133133
std::string abbrev;
134134
chrono::minutes offset{0};
135-
chrono::from_stream(ss, "%Y-%m-%d %H:%M:%S %Z%z", tp, &abbrev, &offset);
135+
chrono::from_stream(ss, "%Y-%m-%d %H:%M:%S %Z %z", tp, &abbrev, &offset);
136136

137137
std::cout << tp << std::endl;
138138
std::cout << abbrev << std::endl;
@@ -189,7 +189,7 @@ int main()
189189

190190
#### 出力例
191191
```
192-
1 : 2019-12-20 10:05:05 UTC
192+
1 : 2019-12-20 10:05:05
193193
2 : 2019年12月20日 10時05分05秒
194194
3 : 2019/12/20 10:05:05 UTC
195195
4 : 2019年12月20日
@@ -204,7 +204,7 @@ int main()
204204

205205
### 処理系
206206
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
207-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
207+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 15.1 [mark verified]
208208
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
209209

210210

0 commit comments

Comments
 (0)