Kodi Development 22.0
for Binary and Script based Add-Ons
 
Loading...
Searching...
No Matches
Time value processing

Detailed Description

String time formats
This is used to process the respective time formats in text fields.

Function Documentation

◆ TimeStringToSeconds()

static long TimeStringToSeconds ( const std::string & timeString)
inlinestatic

Converts a time string to the respective integer value.

Parameters
[in]timeStringString with time.
Following types are possible:
  • "MM min" (integer number with "min" on end)
  • "HH:MM:SS"
Returns
Time in seconds

Example:

#include <kodi/tools/StringUtils.h>
EXPECT_EQ(77455, kodi::tools::StringUtils::TimeStringToSeconds("21:30:55"));
EXPECT_EQ(154*60, kodi::tools::StringUtils::TimeStringToSeconds(" 154 min"));
EXPECT_EQ(2*3600+4*60+3, kodi::tools::StringUtils::TimeStringToSeconds("2:04:03"));
EXPECT_EQ(2*3600+4*60+3, kodi::tools::StringUtils::TimeStringToSeconds(" 2:4:3"));
EXPECT_EQ(2*3600+4*60+3, kodi::tools::StringUtils::TimeStringToSeconds(" \t\t 02:04:03 \n "));
EXPECT_EQ(1*3600+5*60+2, kodi::tools::StringUtils::TimeStringToSeconds("01:05:02:04:03 \n "));
static long TimeStringToSeconds(const std::string &timeString)
Converts a time string to the respective integer value.
Definition StringUtils.h:2895

◆ SecondsToTimeString()

static std::string SecondsToTimeString ( long seconds,
TIME_FORMAT format = TIME_FORMAT_GUESS )
inlinestatic

Convert a time in seconds to a string based on the given time format.

Parameters
[in]secondstime in seconds
[in]format[opt] The format we want the time in
Returns
The formatted time
See also
TIME_FORMAT

Example:

#include <kodi/tools/StringUtils.h>
std::string ref, var;
ref = "21:30:55";
EXPECT_STREQ(ref.c_str(), var.c_str());
static std::string SecondsToTimeString(long seconds, TIME_FORMAT format=TIME_FORMAT_GUESS)
Convert a time in seconds to a string based on the given time format.
Definition StringUtils.h:2941

◆ DateStringToYYYYMMDD()

static int DateStringToYYYYMMDD ( const std::string & dateString)
inlinestatic

Converts a string in the format YYYYMMDD to the corresponding integer value.

Parameters
[in]dateStringThe date in the associated format, possible values are:
  • DD (for days only)
  • MM-DD (for days with month)
  • YYYY-MM-DD (for years, then month and last days)
Returns
Corresponding integer, e.g. "2020-12-24" return as integer value 20201224

Example:

#include <kodi/tools/StringUtils.h>
int ref, var;
ref = 20120706;
EXPECT_EQ(ref, var);
static int DateStringToYYYYMMDD(const std::string &dateString)
Converts a string in the format YYYYMMDD to the corresponding integer value.
Definition StringUtils.h:3007