Skip to content

Commit bd0f906

Browse files
committed
Fixed some compilation issues on windwos
1 parent 2e86a77 commit bd0f906

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

examples/classic.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ int main() {
2626
const std::time_t now = std::time(nullptr);
2727

2828
std::tm tm_utc;
29+
#if defined(_WIN32) || defined(_WIN64)
30+
gmtime_s(&tm_utc, &now);
31+
#else
2932
gmtime_r(&now, &tm_utc);
33+
#endif
3034
std::cout << format("UTC: %Y-%m-%d %H:%M:%S\n", tm_utc);
3135

3236
std::tm tm_local;
37+
#if defined(_WIN32) || defined(_WIN64)
38+
localtime_s(&tm_local, &now);
39+
#else
3340
localtime_r(&now, &tm_local);
41+
#endif
3442
std::cout << format("Local: %Y-%m-%d %H:%M:%S\n", tm_local);
3543
}

examples/epoch_shift.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ int main() {
3434
int off = GetOffset(now, "America/New_York");
3535
const std::time_t now_nyc = now + off;
3636
std::tm tm_nyc;
37+
#if defined(_WIN32) || defined(_WIN64)
38+
gmtime_s(&tm_nyc, &now_nyc);
39+
#else
3740
gmtime_r(&now_nyc, &tm_nyc);
41+
#endif
3842
std::cout << format("NYC: %Y-%m-%d %H:%M:%S\n", tm_nyc);
3943

4044
// Shift back: "local time_t" to UTC

src/benchmarks.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,11 @@ void BM_Time_ToDateTime_Libc(benchmark::State& state) {
794794
while (state.KeepRunning()) {
795795
std::swap(t, t2);
796796
t += 1;
797+
#if defined(_WIN32) || defined(_WIN64)
798+
benchmark::DoNotOptimize(localtime_s(&tm, &t));
799+
#else
797800
benchmark::DoNotOptimize(localtime_r(&t, &tm));
801+
#endif
798802
}
799803
}
800804
BENCHMARK(BM_Time_ToDateTime_Libc);
@@ -815,7 +819,11 @@ void BM_Time_ToDateTimeUTC_Libc(benchmark::State& state) {
815819
struct tm tm;
816820
while (state.KeepRunning()) {
817821
t += 1;
822+
#if defined(_WIN32) || defined(_WIN64)
823+
benchmark::DoNotOptimize(gmtime_s(&tm, &t));
824+
#else
818825
benchmark::DoNotOptimize(gmtime_r(&t, &tm));
826+
#endif
819827
}
820828
}
821829
BENCHMARK(BM_Time_ToDateTimeUTC_Libc);
@@ -934,7 +942,7 @@ void BM_Format_FormatTime(benchmark::State& state) {
934942
const cctz::time_zone tz = TestTimeZone();
935943
const std::chrono::system_clock::time_point tp =
936944
cctz::convert(cctz::civil_second(1977, 6, 28, 9, 8, 7), tz) +
937-
std::chrono::nanoseconds(1);
945+
std::chrono::microseconds(1);
938946
while (state.KeepRunning()) {
939947
benchmark::DoNotOptimize(cctz::format(fmt, tp, tz));
940948
}
@@ -947,7 +955,7 @@ void BM_Format_ParseTime(benchmark::State& state) {
947955
const cctz::time_zone tz = TestTimeZone();
948956
std::chrono::system_clock::time_point tp =
949957
cctz::convert(cctz::civil_second(1977, 6, 28, 9, 8, 7), tz) +
950-
std::chrono::nanoseconds(1);
958+
std::chrono::microseconds(1);
951959
const std::string when = cctz::format(fmt, tp, tz);
952960
while (state.KeepRunning()) {
953961
benchmark::DoNotOptimize(cctz::parse(fmt, when, tz, &tp));

0 commit comments

Comments
 (0)