[libc++][TZDB] Fixes mapping of nonexisting time. (#127330) · llvm/llvm-project@e7e2c16 (original) (raw)

`@@ -88,7 +88,7 @@ static void test_nonexistent() {

`

88

88

`// Pick an historic date where it's well known what the time zone rules were.

`

89

89

`// This makes it unlikely updates to the database change these rules.

`

90

90

` std::chrono::local_timestd::chrono::seconds time{

`

91

``

`-

(std::chrono::sys_days{std::chrono::March / 30 / 1986} + 2h + 30min).time_since_epoch()};

`

``

91

`+

(std::chrono::sys_days{std::chrono::March / 30 / 1986} + 2h).time_since_epoch()};

`

92

92

``

93

93

` std::chrono::sys_seconds expected{time.time_since_epoch() - 1h};

`

94

94

``

`@@ -100,6 +100,13 @@ static void test_nonexistent() {

`

100

100

`assert(tz->to_sys(time + 0us, std::chrono::choose::latest) == expected);

`

101

101

`assert(tz->to_sys(time + 0ms, std::chrono::choose::earliest) == expected);

`

102

102

`assert(tz->to_sys(time + 0s, std::chrono::choose::latest) == expected);

`

``

103

+

``

104

`+

// The entire nonexisting hour should map to the same time.

`

``

105

`+

// For nonexistant the value of std::chrono::choose has no effect.

`

``

106

`+

assert(tz->to_sys(time + 1s, std::chrono::choose::earliest) == expected);

`

``

107

`+

assert(tz->to_sys(time + 1min, std::chrono::choose::latest) == expected);

`

``

108

`+

assert(tz->to_sys(time + 30min, std::chrono::choose::earliest) == expected);

`

``

109

`+

assert(tz->to_sys(time + 59min + 59s, std::chrono::choose::latest) == expected);

`

103

110

`}

`

104

111

``

105

112

`// Tests ambiguous conversions.

`

`@@ -120,7 +127,7 @@ static void test_ambiguous() {

`

120

127

`// Pick an historic date where it's well known what the time zone rules were.

`

121

128

`// This makes it unlikely updates to the database change these rules.

`

122

129

` std::chrono::local_timestd::chrono::seconds time{

`

123

``

`-

(std::chrono::sys_days{std::chrono::September / 28 / 1986} + 2h + 30min).time_since_epoch()};

`

``

130

`+

(std::chrono::sys_days{std::chrono::September / 28 / 1986} + 2h).time_since_epoch()};

`

124

131

``

125

132

` std::chrono::sys_seconds earlier{time.time_since_epoch() - 2h};

`

126

133

` std::chrono::sys_seconds later{time.time_since_epoch() - 1h};

`

`@@ -133,6 +140,12 @@ static void test_ambiguous() {

`

133

140

`assert(tz->to_sys(time + 0us, std::chrono::choose::latest) == later);

`

134

141

`assert(tz->to_sys(time + 0ms, std::chrono::choose::earliest) == earlier);

`

135

142

`assert(tz->to_sys(time + 0s, std::chrono::choose::latest) == later);

`

``

143

+

``

144

`+

// Test times in the ambigious hour

`

``

145

`+

assert(tz->to_sys(time + 1s, std::chrono::choose::earliest) == earlier + 1s);

`

``

146

`+

assert(tz->to_sys(time + 1min, std::chrono::choose::latest) == later + 1min);

`

``

147

`+

assert(tz->to_sys(time + 30min, std::chrono::choose::earliest) == earlier + 30min);

`

``

148

`+

assert(tz->to_sys(time + 59min + 59s, std::chrono::choose::latest) == later + 59min + 59s);

`

136

149

`}

`

137

150

``

138

151

`// This test does the basic validations of this function. The library function

`