Skip to content

Commit

Permalink
chrono: gps_clock,gps_time例示コード調整
Browse files Browse the repository at this point in the history
  • Loading branch information
yohhoy committed Nov 8, 2024
1 parent ca64b9a commit 2a47b4b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
4 changes: 2 additions & 2 deletions reference/chrono/gps_clock.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main()

### 出力例
```
2019-10-24 11:15:37 GPS
2019-10-24 11:15:37.493236171
```

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

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


Expand Down
21 changes: 10 additions & 11 deletions reference/chrono/gps_clock/from_utc.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ using namespace std::chrono_literals;
int main()
{
// ここでは日単位のシステム時間を、utc_clockを経由して、日単位のGPS時間に変換している。
// 秒単位の時間を渡せば、秒単位のGPS時間が返る
auto st = chrono::sys_days{2019y/10/24};
auto ut = chrono::utc_clock::from_sys(st);
auto tt = chrono::gps_clock::from_utc(ut); // 日単位のGPS時間が返る
// ここでは日単位のシステム時間を、秒単位のUTC時間とGPS時間に変換している。
auto st = chrono::sys_days{2019y/10/24}; // システム時間,日単位
auto ut = chrono::utc_clock::from_sys(st); // UTC時間,秒単位
auto tt = chrono::gps_clock::from_utc(ut); // GPS時間,秒単位
// うるう秒
// UTC時間のうるう秒に関する情報
chrono::leap_second_info info = chrono::get_leap_second_info(ut);
std::cout << st << std::endl;
std::cout << ut << std::endl;
std::cout << tt << std::endl;
std::cout << ut << " UTC" << std::endl;
std::cout << tt << " GPS" << std::endl;
std::cout << info.elapsed.count() << std::endl;
}
```
Expand All @@ -76,9 +75,9 @@ int main()

### 出力
```
2019-10-24 00:00:00
2019-10-24
2019-10-24 00:00:00 UTC
2019-10-24 00:00:27 GPS
2019-10-24 00:00:18 GPS
27
```

Expand All @@ -88,5 +87,5 @@ int main()

### 処理系
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.1 [mark verified]
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
4 changes: 2 additions & 2 deletions reference/chrono/gps_clock/now.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main()

### 出力例
```
2019-10-24 11:15:37 GPS
2019-10-24 11:15:51.428340077
```

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

### 処理系
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.1 [mark verified]
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
8 changes: 4 additions & 4 deletions reference/chrono/gps_clock/to_utc.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ int main()
// うるう秒
chrono::leap_second_info info = chrono::get_leap_second_info(ut);
std::cout << tt << std::endl;
std::cout << ut << std::endl;
std::cout << tt << " GPS" << std::endl;
std::cout << ut << " UTC" << std::endl;
std::cout << info.elapsed.count() << std::endl;
}
```
Expand All @@ -73,7 +73,7 @@ int main()

### 出力
```
2019-10-24 00:00:27 GPS
2019-10-24 00:00:18 GPS
2019-10-24 00:00:00 UTC
27
```
Expand All @@ -84,5 +84,5 @@ int main()

### 処理系
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.1 [mark verified]
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
42 changes: 23 additions & 19 deletions reference/chrono/gps_time.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int main()

#### 出力例
```
2019-10-24 11:15:27 GPS
2019-10-24 11:15:27
```

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

if (ss) {
std::cout << tp << std::endl;
}
else {
} else {
std::cout << "解析失敗" << std::endl;
}
}

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

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

std::cout << tp << std::endl;
std::cout << abbrev << std::endl;
if (ss) {
std::cout << tp << std::endl;
std::cout << abbrev << std::endl;
} else {
std::cout << "解析失敗" << std::endl;
}
}
}
```
* chrono::from_stream[color ff0000]
#### 出力例
#### 出力
```
2019-10-24 11:15:27 GPS
2019-10-24 11:15:27 GPS
2019-10-24 20:15:45
2019-10-24 20:15:45
GPS
```
Expand All @@ -168,7 +171,7 @@ namespace chrono = std::chrono;
int main()
{
chrono::gps_clock::time_point now = chrono::gps_clock::now();
chrono::gps_seconds now_sec = chrono::floor<chrono::seconds>(tp);
chrono::gps_seconds now_sec = chrono::floor<chrono::seconds>(now);
// デフォルトフォーマット
std::cout << std::format("1 : {}", now_sec) << std::endl;
Expand All @@ -177,25 +180,25 @@ int main()
std::cout << std::format("2 : {:%Y年%m月%d日 %H時%M分%S秒}", now_sec) << std::endl;
// 日付を / (スラッシュ) 区切り、時間を : (コロン) 区切り、タイムゾーンの略称付き
std::cout << std::format("3 : {0:%Y/%m/%d %H:%M:%S %Z}", now_sec) << std::endl;
std::cout << std::format("3 : {:%Y/%m/%d %H:%M:%S %Z}", now_sec) << std::endl;
// 日付だけ出力
std::cout << std::format("4 : %Y年%m月%d日", now_sec) << std::endl;
std::cout << std::format("5 : %F", now_sec) << std::endl;
std::cout << std::format("4 : {:%Y年%m月%d日}", now_sec) << std::endl;
std::cout << std::format("5 : {:%F}", now_sec) << std::endl;
// 時間だけ出力
std::cout << std::format("6 : %H時%M分%S秒", now_sec) << std::endl;
std::cout << std::format("7 : %T", now_sec) << std::endl;
std::cout << std::format("6 : {:%H時%M分%S秒}", now_sec) << std::endl;
std::cout << std::format("7 : {:%T}", now_sec) << std::endl;
}
```
* chrono::gps_clock[link gps_clock.md]
* now()[link gps_clock/now.md]
* chrono::floor[link time_point/floor.md]
* std::format[link format.md]

#### 出力例
#### 出力
```
1 : 2019-12-20 10:05:05 GPS
1 : 2019-12-20 10:05:05
2 : 2019年12月20日 10時05分05秒
3 : 2019/12/20 10:05:05 GPS
4 : 2019年12月20日
Expand All @@ -204,13 +207,14 @@ int main()
7 : 10:05:05
```


## バージョン
### 言語
- C++20

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


Expand Down

0 comments on commit 2a47b4b

Please sign in to comment.