Skip to content

Commit 2e1d2fe

Browse files
committed
chrono: leap_second_info例示コード改定(GCC13.2)
1 parent 203d665 commit 2e1d2fe

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

reference/chrono/get_leap_second_info.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,45 +37,32 @@ using namespace std::chrono_literals;
3737
int main()
3838
{
3939
std::cout << std::boolalpha;
40-
{
41-
chrono::utc_time now = chrono::utc_clock::now();
42-
chrono::leap_second_info info = chrono::get_leap_second_info(now);
43-
44-
std::cout << info.is_leap_second << std::endl;
45-
std::cout << info.elapsed.count() << std::endl;
46-
}
47-
std::cout << std::endl;
48-
{
49-
// 2017年1月1日はうるう秒が挿入された日
50-
chrono::utc_time date = chrono::clock_cast<chrono::utc_clock>(chrono::sys_days{2017y/1/1});
51-
chrono::leap_second_info info = chrono::get_leap_second_info(date);
52-
53-
std::cout << info.is_leap_second << std::endl;
54-
std::cout << info.elapsed.count() << std::endl;
55-
}
40+
// 日本標準時(JST)2017年1月1日にうるう秒挿入が実施され
41+
// 2016-12-31 23:59:60 UTC
42+
// が存在する
43+
chrono::utc_time tp = chrono::clock_cast<chrono::utc_clock>(chrono::sys_days{2017y/1/1}) - 1s;
44+
chrono::leap_second_info info = chrono::get_leap_second_info(tp);
45+
std::cout << tp << std::endl;
46+
std::cout << info.is_leap_second << " " << info.elapsed.count() << std::endl;
5647
}
5748
```
5849
* chrono::leap_second_info[link leap_second_info.md]
5950
* chrono::utc_time[link utc_time.md]
6051
* chrono::utc_clock[link utc_clock.md]
61-
* now()[link utc_clock/now.md]
6252
* count()[link duration/count.md]
6353
* 2017y[link year/op_y.md]
6454
* chrono::sys_days[link sys_time.md]
6555
* chrono::clock_cast[link clock_cast.md]
6656

6757
### 出力例
6858
```
69-
false
70-
27
71-
72-
true
73-
27
59+
2016-12-31 23:59:60
60+
true 27
7461
```
7562

7663
### 処理系
7764
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
78-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
65+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.2 [mark impl]
7966
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
8067

8168

@@ -84,5 +71,6 @@ true
8471

8572

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

reference/chrono/leap_second_info.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,55 @@ using namespace std::chrono_literals;
3535
int main()
3636
{
3737
std::cout << std::boolalpha;
38-
{
39-
chrono::utc_time now = chrono::utc_clock::now();
40-
chrono::leap_second_info info = chrono::get_leap_second_info(now);
4138
42-
std::cout << info.is_leap_second << std::endl;
43-
std::cout << info.elapsed.count() << std::endl;
39+
// 2016-12-31 23:59:59 UTC
40+
chrono::utc_time tp = chrono::clock_cast<chrono::utc_clock>(chrono::sys_days{2017y/1/1});
41+
tp -= 2s;
42+
{
43+
chrono::leap_second_info info = chrono::get_leap_second_info(tp);
44+
std::cout << tp << std::endl;
45+
std::cout << info.is_leap_second << " " << info.elapsed.count() << std::endl;
4446
}
45-
std::cout << std::endl;
47+
48+
// 日本標準時(JST)2017年1月1日にうるう秒挿入が実施された
49+
// 2016-12-31 23:59:60 UTC
50+
tp += 1s;
4651
{
47-
// 2017年1月1日はうるう秒が挿入された日
48-
chrono::utc_time date = chrono::clock_cast<chrono::utc_clock>(chrono::sys_days{2017y/1/1});
49-
chrono::leap_second_info info = chrono::get_leap_second_info(date);
52+
chrono::leap_second_info info = chrono::get_leap_second_info(tp);
53+
std::cout << tp << std::endl;
54+
std::cout << info.is_leap_second << " " << info.elapsed.count() << std::endl;
55+
}
5056
51-
std::cout << info.is_leap_second << std::endl;
52-
std::cout << info.elapsed.count() << std::endl;
57+
// 2017-01-01 00:00:00 UTC
58+
tp += 1s;
59+
{
60+
chrono::leap_second_info info = chrono::get_leap_second_info(tp);
61+
std::cout << tp << std::endl;
62+
std::cout << info.is_leap_second << " " << info.elapsed.count() << std::endl;
5363
}
5464
}
5565
```
5666
* chrono::get_leap_second_info[link get_leap_second_info.md]
5767
* chrono::utc_time[link utc_time.md]
5868
* chrono::utc_clock[link utc_clock.md]
59-
* now()[link utc_clock/now.md]
6069
* count()[link duration/count.md]
6170
* 2017y[link year/op_y.md]
6271
* chrono::sys_days[link sys_time.md]
6372
* chrono::clock_cast[link clock_cast.md]
6473

65-
### 出力例
74+
### 出力
6675
```
67-
false
68-
27
69-
70-
true
71-
27
76+
2016-12-31 23:59:59
77+
false 26
78+
2016-12-31 23:59:60
79+
true 27
80+
2017-01-01 00:00:00
81+
false 27
7282
```
7383

7484
### 処理系
7585
- [Clang](/implementation.md#clang): 9.0 [mark noimpl]
76-
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl]
86+
- [GCC](/implementation.md#gcc): 9.2 [mark noimpl], 13.2 [mark impl]
7787
- [Visual C++](/implementation.md#visual_cpp): 2019 Update 3 [mark noimpl]
7888

7989

@@ -82,4 +92,5 @@ true
8292

8393

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

0 commit comments

Comments
 (0)