Use timegm/_mkgmtime instead of mktime

mktime return localized timezone result.
Certification uses UTC time zone,
so call timegm/_mkgmtime to match with certification.

Change-Id: I338ca14bb75e75d45c1de1ab976a61ec2e51eeca
Reviewed-on: https://chromium-review.googlesource.com/c/openscreen/+/2658656
Reviewed-by: Brandon Tolsch <btolsch@chromium.org>
Commit-Queue: Brandon Tolsch <btolsch@chromium.org>
diff --git a/cast/common/certificate/cast_cert_validator_unittest.cc b/cast/common/certificate/cast_cert_validator_unittest.cc
index 53b6f05..819ef49 100644
--- a/cast/common/certificate/cast_cert_validator_unittest.cc
+++ b/cast/common/certificate/cast_cert_validator_unittest.cc
@@ -610,6 +610,21 @@
           TRUST_STORE_FROM_TEST_FILE, "");
 }
 
+// Tests reversibility between DateTimeToSeconds and DateTimeFromSeconds
+TEST(VerifyCastDeviceCertTest, TimeDateConversionValidate) {
+  DateTime org_date = AprilFirst2020();
+  DateTime converted_date = {};
+  std::chrono::seconds seconds = DateTimeToSeconds(org_date);
+  DateTimeFromSeconds(seconds.count(), &converted_date);
+
+  EXPECT_EQ(org_date.second, converted_date.second);
+  EXPECT_EQ(org_date.minute, converted_date.minute);
+  EXPECT_EQ(org_date.hour, converted_date.hour);
+  EXPECT_EQ(org_date.day, converted_date.day);
+  EXPECT_EQ(org_date.month, converted_date.month);
+  EXPECT_EQ(org_date.year, converted_date.year);
+}
+
 }  // namespace
 }  // namespace cast
 }  // namespace openscreen
diff --git a/cast/common/certificate/types.cc b/cast/common/certificate/types.cc
index 937e190..d891c0a 100644
--- a/cast/common/certificate/types.cc
+++ b/cast/common/certificate/types.cc
@@ -88,7 +88,13 @@
   tm.tm_mday = time.day;
   tm.tm_mon = time.month - 1;
   tm.tm_year = time.year - 1900;
-  return std::chrono::seconds(mktime(&tm));
+  time_t sec;
+#if defined(_WIN32)
+  sec = _mkgmtime(&tm);
+#else
+  sec = timegm(&tm);
+#endif
+  return std::chrono::seconds(sec);
 }
 
 }  // namespace cast