13
13
* permissions and limitations under the License.
14
14
*/
15
15
16
- // PORTIONS LICENSED UNDER
16
+ // WHEN NOT ON LINUX, PORTIONS LICENSED UNDER
17
17
/* *
18
18
* Copyright 2011-2015 Quickstep Technologies LLC.
19
19
* Copyright 2015 Pivotal Software, Inc.
37
37
#include < mutex>
38
38
#include < random>
39
39
#include < sstream>
40
+ #include < time.h>
40
41
41
42
#include " AVSCommon/Utils/Timing/TimeUtils.h"
42
43
#include " AVSCommon/Utils/Logger/Logger.h"
43
44
#include " AVSCommon/Utils/String/StringUtils.h"
44
45
46
+ #ifndef __linux__
47
+ #define USE_CUSTOM_TIMEGM 1
48
+ #else
49
+ #define USE_CUSTOM_TIMEGM 0
50
+ #endif
51
+
45
52
namespace alexaClientSDK {
46
53
namespace avsCommon {
47
54
namespace utils {
@@ -121,19 +128,21 @@ static const unsigned long ENCODED_TIME_STRING_EXPECTED_LENGTH =
121
128
* @param[out] ret Required pointer to object where the result will be saved.
122
129
* @return Whether the conversion was successful.
123
130
*/
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
+ // }
128
136
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
+ // }
133
141
134
142
TimeUtils::TimeUtils () : m_safeCTimeAccess{SafeCTimeAccess::instance ()} {
135
143
}
136
144
145
+ #if USE_CUSTOM_TIMEGM
137
146
// BEGIN LICENSED UNDER APACHE FROM PIVOTAL SOFTWARE
138
147
namespace {
139
148
constexpr std::time_t kSecondsInMinute = 60 ;
@@ -224,6 +233,7 @@ std::time_t timegmCustom(const struct std::tm *tm) {
224
233
return time;
225
234
}
226
235
// END LICENSED UNDER APACHE FROM PIVOTAL SOFTWARE
236
+ #endif
227
237
228
238
bool TimeUtils::convertToUtcTimeT (const std::tm* utcTm, std::time_t * ret) {
229
239
if (ret == nullptr ) {
@@ -242,7 +252,12 @@ bool TimeUtils::convertToUtcTimeT(const std::tm* utcTm, std::time_t* ret) {
242
252
// adjust converted time
243
253
// *ret = converted - offset;
244
254
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
246
261
247
262
return true ;
248
263
}
0 commit comments