Skip to content

Commit cf2bba9

Browse files
committed
PR comments
1 parent a51a4cb commit cf2bba9

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

AVSCommon/Utils/src/TimeUtils.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
// PORTIONS LICENSED UNDER
16+
// WHEN NOT ON LINUX, PORTIONS LICENSED UNDER
1717
/**
1818
* Copyright 2011-2015 Quickstep Technologies LLC.
1919
* Copyright 2015 Pivotal Software, Inc.
@@ -37,11 +37,18 @@
3737
#include <mutex>
3838
#include <random>
3939
#include <sstream>
40+
#include <time.h>
4041

4142
#include "AVSCommon/Utils/Timing/TimeUtils.h"
4243
#include "AVSCommon/Utils/Logger/Logger.h"
4344
#include "AVSCommon/Utils/String/StringUtils.h"
4445

46+
#ifndef __linux__
47+
#define USE_CUSTOM_TIMEGM 1
48+
#else
49+
#define USE_CUSTOM_TIMEGM 0
50+
#endif
51+
4552
namespace alexaClientSDK {
4653
namespace avsCommon {
4754
namespace utils {
@@ -121,19 +128,21 @@ static const unsigned long ENCODED_TIME_STRING_EXPECTED_LENGTH =
121128
* @param[out] ret Required pointer to object where the result will be saved.
122129
* @return Whether the conversion was successful.
123130
*/
124-
static bool convertToLocalTimeT(const std::tm* timeStruct, std::time_t* ret) {
125-
if (timeStruct == nullptr) {
126-
return false;
127-
}
131+
// UNUSED FOR NOW. SEE COMMENT IN convertToUtcTimeT
132+
// static bool convertToLocalTimeT(const std::tm* timeStruct, std::time_t* ret) {
133+
// if (timeStruct == nullptr) {
134+
// return false;
135+
// }
128136

129-
std::tm tmCopy = *timeStruct;
130-
*ret = std::mktime(&tmCopy);
131-
return *ret >= 0;
132-
}
137+
// std::tm tmCopy = *timeStruct;
138+
// *ret = std::mktime(&tmCopy);
139+
// return *ret >= 0;
140+
// }
133141

134142
TimeUtils::TimeUtils() : m_safeCTimeAccess{SafeCTimeAccess::instance()} {
135143
}
136144

145+
#if USE_CUSTOM_TIMEGM
137146
// BEGIN LICENSED UNDER APACHE FROM PIVOTAL SOFTWARE
138147
namespace {
139148
constexpr std::time_t kSecondsInMinute = 60;
@@ -224,6 +233,7 @@ std::time_t timegmCustom(const struct std::tm *tm) {
224233
return time;
225234
}
226235
// END LICENSED UNDER APACHE FROM PIVOTAL SOFTWARE
236+
#endif
227237

228238
bool TimeUtils::convertToUtcTimeT(const std::tm* utcTm, std::time_t* ret) {
229239
if (ret == nullptr) {
@@ -242,7 +252,12 @@ bool TimeUtils::convertToUtcTimeT(const std::tm* utcTm, std::time_t* ret) {
242252
// adjust converted time
243253
// *ret = converted - offset;
244254

245-
*ret = timegmCustom(utcTm);
255+
#if USE_CUSTOM_TIMEGM
256+
*ret = timegmCustom(utcTm);
257+
#else
258+
std::tm cpy = *utcTm;
259+
*ret = timegm(&cpy);
260+
#endif
246261

247262
return true;
248263
}

0 commit comments

Comments
 (0)