AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Member Functions | List of all members
alexaClientSDK::avsCommon::utils::timing::TimeUtils Class Reference

#include <TimeUtils.h>

Public Member Functions

 TimeUtils ()
bool convertToUtcTimeT (const std::tm *utcTm, std::time_t *ret)
bool convert8601TimeStringToUnix (const std::string &timeString, int64_t *unixTime)
bool convert8601TimeStringToUtcTimePoint (const std::string &iso8601TimeString, std::chrono::system_clock::time_point *tp)
bool getCurrentUnixTime (int64_t *currentTime)
bool convertTimeToUtcIso8601Rfc3339 (const std::chrono::system_clock::time_point &tp, std::string *iso8601TimeString)

Detailed Description

Class used to safely access the time utilities.

Constructor & Destructor Documentation

◆ TimeUtils()

alexaClientSDK::avsCommon::utils::timing::TimeUtils::TimeUtils ( )


Member Function Documentation

◆ convert8601TimeStringToUnix()

bool alexaClientSDK::avsCommon::utils::timing::TimeUtils::convert8601TimeStringToUnix ( const std::string &  timeString,
int64_t *  unixTime 

This function converts a string representing time, encoded in the ISO-8601 format, to what is commonly known as Unix time (epoch).

For completeness, the expected format of the input string is as follows:


Where (in order of listing) : Y means year M means month D means day H means hour M means minute S means second

So, for example:


means the year 1986, August 8th, 9:30pm.

timeStringThe time string, formatted as described above.
[out]unixTimeThe converted time into Unix epoch time.
Whether the conversion was successful.

◆ convert8601TimeStringToUtcTimePoint()

bool alexaClientSDK::avsCommon::utils::timing::TimeUtils::convert8601TimeStringToUtcTimePoint ( const std::string &  iso8601TimeString,
std::chrono::system_clock::time_point *  tp 

Converts a ISO 8601 date-time string to a timepoint. Referring to function convert8601TimeStringToUnix for details of the string representation in ISO 8601 format.

iso8601TimeStringThe time string in a ISO 8601 format.
[out]tpThe converted time into UTC time point format.
Whether the conversion was successful.

◆ convertTimeToUtcIso8601Rfc3339()

bool alexaClientSDK::avsCommon::utils::timing::TimeUtils::convertTimeToUtcIso8601Rfc3339 ( const std::chrono::system_clock::time_point &  tp,
std::string *  iso8601TimeString 

Convert timepoint to a ISO 8601 RFC 3339 date-time string. This follows these specifications:

The end result will look like "1970-01-01T00:00:00.000Z"

tpThe timepoint from which to convert.
[out]iso8601TimeStringThe resulting time string.
True, if successful, false otherwise.

◆ convertToUtcTimeT()

bool alexaClientSDK::avsCommon::utils::timing::TimeUtils::convertToUtcTimeT ( const std::tm *  utcTm,
std::time_t *  ret 

Convert tm struct to time_t in UTC time

This function is needed because mktime uses the current timezone. Hence, we calculate the current timezone difference, and adjust the converted time.

utcTmtime to be converted. This should be in UTC time
[out]retThe converted UTC time to time_t
Whether the conversion was successful.

◆ getCurrentUnixTime()

bool alexaClientSDK::avsCommon::utils::timing::TimeUtils::getCurrentUnixTime ( int64_t *  currentTime)

Gets the current time in Unix epoch time, as a 64 bit integer.

[out]currentTimeThe current time in Unix epoch time, as a 64 bit integer.
Whether the get time was successful.

The documentation for this class was generated from the following file:

AlexaClientSDK 3.0.0 - Copyright 2016-2022, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0