Skip to content

Commit d85cf7b

Browse files
authored
Update the time_point used in Format.PosixConversions (google#325)
Use a `time_point` in the Format.PosixConversions test cases that produces more distinct values for each of the conversion specifiers, which increases the confidence that we are assigning them correctly. Also correct a comment typo in `time_zone_format.cc:ToTM()` while we are here.
1 parent 6701485 commit d85cf7b

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/time_zone_format.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ std::tm ToTM(const time_zone::absolute_lookup& al) {
113113
tm.tm_mday = al.cs.day();
114114
tm.tm_mon = al.cs.month() - 1;
115115

116-
// Saturate tm.tm_year is cases of over/underflow.
116+
// Saturate tm.tm_year in cases of over/underflow.
117117
if (al.cs.year() < std::numeric_limits<int>::min() + 1900) {
118118
tm.tm_year = std::numeric_limits<int>::min();
119119
} else if (al.cs.year() - 1900 > std::numeric_limits<int>::max()) {

src/time_zone_format_test.cc

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -158,43 +158,44 @@ TEST(Format, Basics) {
158158

159159
TEST(Format, PosixConversions) {
160160
const time_zone tz = utc_time_zone();
161-
auto tp = chrono::system_clock::from_time_t(0);
161+
auto tp =
162+
chrono::system_clock::from_time_t(308189482); // 1979-10-08T00:11:22Z
162163

163-
TestFormatSpecifier(tp, tz, "%d", "01");
164-
TestFormatSpecifier(tp, tz, "%e", " 1"); // extension but internal support
164+
TestFormatSpecifier(tp, tz, "%d", "08");
165+
TestFormatSpecifier(tp, tz, "%e", " 8"); // extension but internal support
165166
TestFormatSpecifier(tp, tz, "%H", "00");
166167
TestFormatSpecifier(tp, tz, "%I", "12");
167-
TestFormatSpecifier(tp, tz, "%j", "001");
168-
TestFormatSpecifier(tp, tz, "%m", "01");
169-
TestFormatSpecifier(tp, tz, "%M", "00");
170-
TestFormatSpecifier(tp, tz, "%S", "00");
171-
TestFormatSpecifier(tp, tz, "%U", "00");
172-
TestFormatSpecifier(tp, tz, "%w", "4"); // 4=Thursday
173-
TestFormatSpecifier(tp, tz, "%W", "00");
174-
TestFormatSpecifier(tp, tz, "%y", "70");
175-
TestFormatSpecifier(tp, tz, "%Y", "1970");
168+
TestFormatSpecifier(tp, tz, "%j", "281");
169+
TestFormatSpecifier(tp, tz, "%m", "10");
170+
TestFormatSpecifier(tp, tz, "%M", "11");
171+
TestFormatSpecifier(tp, tz, "%S", "22");
172+
TestFormatSpecifier(tp, tz, "%U", "40");
173+
TestFormatSpecifier(tp, tz, "%w", "1"); // 1=Monday
174+
TestFormatSpecifier(tp, tz, "%W", "41");
175+
TestFormatSpecifier(tp, tz, "%y", "79");
176+
TestFormatSpecifier(tp, tz, "%Y", "1979");
176177
TestFormatSpecifier(tp, tz, "%z", "+0000");
177178
TestFormatSpecifier(tp, tz, "%Z", "UTC");
178179
TestFormatSpecifier(tp, tz, "%%", "%");
179180

180181
#if defined(__linux__)
181182
// SU/C99/TZ extensions
182183
TestFormatSpecifier(tp, tz, "%C", "19");
183-
TestFormatSpecifier(tp, tz, "%D", "01/01/70");
184-
TestFormatSpecifier(tp, tz, "%F", "1970-01-01");
185-
TestFormatSpecifier(tp, tz, "%g", "70");
186-
TestFormatSpecifier(tp, tz, "%G", "1970");
184+
TestFormatSpecifier(tp, tz, "%D", "10/08/79");
185+
TestFormatSpecifier(tp, tz, "%F", "1979-10-08");
186+
TestFormatSpecifier(tp, tz, "%g", "79");
187+
TestFormatSpecifier(tp, tz, "%G", "1979");
187188
#if defined(__GLIBC__)
188189
TestFormatSpecifier(tp, tz, "%k", " 0");
189190
TestFormatSpecifier(tp, tz, "%l", "12");
190191
#endif
191192
TestFormatSpecifier(tp, tz, "%n", "\n");
192-
TestFormatSpecifier(tp, tz, "%R", "00:00");
193+
TestFormatSpecifier(tp, tz, "%R", "00:11");
193194
TestFormatSpecifier(tp, tz, "%t", "\t");
194-
TestFormatSpecifier(tp, tz, "%T", "00:00:00");
195-
TestFormatSpecifier(tp, tz, "%u", "4"); // 4=Thursday
196-
TestFormatSpecifier(tp, tz, "%V", "01");
197-
TestFormatSpecifier(tp, tz, "%s", "0");
195+
TestFormatSpecifier(tp, tz, "%T", "00:11:22");
196+
TestFormatSpecifier(tp, tz, "%u", "1"); // 1=Monday
197+
TestFormatSpecifier(tp, tz, "%V", "41");
198+
TestFormatSpecifier(tp, tz, "%s", "308189482");
198199
#endif
199200
}
200201

0 commit comments

Comments
 (0)