Skip to content

Commit

Permalink
chrono: leap_second_info例示コード改定(GCC13.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
yohhoy committed Oct 17, 2024
1 parent 203d665 commit 2e1d2fe
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 42 deletions.
34 changes: 11 additions & 23 deletions reference/chrono/get_leap_second_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,32 @@ using namespace std::chrono_literals;
int main()
{
std::cout << std::boolalpha;
{
chrono::utc_time now = chrono::utc_clock::now();
chrono::leap_second_info info = chrono::get_leap_second_info(now);
std::cout << info.is_leap_second << std::endl;
std::cout << info.elapsed.count() << std::endl;
}
std::cout << std::endl;
{
// 2017年1月1日はうるう秒が挿入された日
chrono::utc_time date = chrono::clock_cast<chrono::utc_clock>(chrono::sys_days{2017y/1/1});
chrono::leap_second_info info = chrono::get_leap_second_info(date);
std::cout << info.is_leap_second << std::endl;
std::cout << info.elapsed.count() << std::endl;
}
// 日本標準時(JST)2017年1月1日にうるう秒挿入が実施され
// 2016-12-31 23:59:60 UTC
// が存在する
chrono::utc_time tp = chrono::clock_cast<chrono::utc_clock>(chrono::sys_days{2017y/1/1}) - 1s;
chrono::leap_second_info info = chrono::get_leap_second_info(tp);
std::cout << tp << std::endl;
std::cout << info.is_leap_second << " " << info.elapsed.count() << std::endl;
}
```
* chrono::leap_second_info[link leap_second_info.md]
* chrono::utc_time[link utc_time.md]
* chrono::utc_clock[link utc_clock.md]
* now()[link utc_clock/now.md]
* count()[link duration/count.md]
* 2017y[link year/op_y.md]
* chrono::sys_days[link sys_time.md]
* chrono::clock_cast[link clock_cast.md]

### 出力例
```
false
27
true
27
2016-12-31 23:59:60
true 27
```

### 処理系
- [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.2 [mark impl]
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]


Expand All @@ -84,5 +71,6 @@ true


## 参照
- [日本標準時プロジェクト Information of Leap second](https://jjy.nict.go.jp/QandA/data/leapsec.html)
- [P1466R3 Miscellaneous minor fixes for chrono](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1466r3.html)
- [LWG Issue 3359. `<chrono>` leap second support should allow for negative leap seconds](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2117r0.html#3359)
49 changes: 30 additions & 19 deletions reference/chrono/leap_second_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,45 +35,55 @@ using namespace std::chrono_literals;
int main()
{
std::cout << std::boolalpha;
{
chrono::utc_time now = chrono::utc_clock::now();
chrono::leap_second_info info = chrono::get_leap_second_info(now);
std::cout << info.is_leap_second << std::endl;
std::cout << info.elapsed.count() << std::endl;
// 2016-12-31 23:59:59 UTC
chrono::utc_time tp = chrono::clock_cast<chrono::utc_clock>(chrono::sys_days{2017y/1/1});
tp -= 2s;
{
chrono::leap_second_info info = chrono::get_leap_second_info(tp);
std::cout << tp << std::endl;
std::cout << info.is_leap_second << " " << info.elapsed.count() << std::endl;
}
std::cout << std::endl;
// 日本標準時(JST)2017年1月1日にうるう秒挿入が実施された
// 2016-12-31 23:59:60 UTC
tp += 1s;
{
// 2017年1月1日はうるう秒が挿入された日
chrono::utc_time date = chrono::clock_cast<chrono::utc_clock>(chrono::sys_days{2017y/1/1});
chrono::leap_second_info info = chrono::get_leap_second_info(date);
chrono::leap_second_info info = chrono::get_leap_second_info(tp);
std::cout << tp << std::endl;
std::cout << info.is_leap_second << " " << info.elapsed.count() << std::endl;
}
std::cout << info.is_leap_second << std::endl;
std::cout << info.elapsed.count() << std::endl;
// 2017-01-01 00:00:00 UTC
tp += 1s;
{
chrono::leap_second_info info = chrono::get_leap_second_info(tp);
std::cout << tp << std::endl;
std::cout << info.is_leap_second << " " << info.elapsed.count() << std::endl;
}
}
```
* chrono::get_leap_second_info[link get_leap_second_info.md]
* chrono::utc_time[link utc_time.md]
* chrono::utc_clock[link utc_clock.md]
* now()[link utc_clock/now.md]
* count()[link duration/count.md]
* 2017y[link year/op_y.md]
* chrono::sys_days[link sys_time.md]
* chrono::clock_cast[link clock_cast.md]

### 出力例
### 出力
```
false
27
true
27
2016-12-31 23:59:59
false 26
2016-12-31 23:59:60
true 27
2017-01-01 00:00:00
false 27
```

### 処理系
- [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.2 [mark impl]
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]


Expand All @@ -82,4 +92,5 @@ true


## 参照
- [日本標準時プロジェクト Information of Leap second](https://jjy.nict.go.jp/QandA/data/leapsec.html)
- [P1466R3 Miscellaneous minor fixes for chrono](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1466r3.html)

0 comments on commit 2e1d2fe

Please sign in to comment.