mastodon-cpp  0.101.1
Public Member Functions | Public Attributes | Friends | List of all members
Mastodon::Easy::time Struct Reference

Type for time. Converts to time_point and string. More...

#include <types_easy.hpp>

Public Member Functions

 operator const system_clock::time_point () const
 
 operator const string () const
 Returns local time as string in ISO 8601 format (FTTz). More...
 
const string strtime (const string &format, const bool &local=true) const
 Converts time to a string. More...
 

Public Attributes

system_clock::time_point timepoint = system_clock::time_point()
 

Friends

std::ostream & operator<< (std::ostream &out, const Easy::time &t)
 Returns local time as string in ISO 8601 format (FTTz). More...
 

Detailed Description

Type for time. Converts to time_point and string.

Since
0.100.0

Member Function Documentation

◆ operator const string()

Easy::time::operator const string ( ) const

Returns local time as string in ISO 8601 format (FTTz).

Since
0.100.0
27 {
28  return strtime("%FT%T%z", true);
29 }
const string strtime(const string &format, const bool &local=true) const
Converts time to a string.
Definition: types_easy.cpp:31

◆ strtime()

const string Easy::time::strtime ( const string &  format,
const bool &  local = true 
) const

Converts time to a string.

The return value can not exceed 1023 chars.

Parameters
formatThe format of the string, same as with strftime.
localUse local time (default) or UTC.

Example:

Mastodon::Easy::time timepoint = status.created_at();
std::cout << timepoint.strtime("%F, %T UTC", false) << '\n';
Returns
The time as string.
Since
0.100.0
Examples:
example02_stream.cpp.
32 {
33  constexpr std::uint16_t bufsize = 1024;
34  std::time_t time = system_clock::to_time_t(timepoint);
35  std::tm *timeinfo;
36  if (local)
37  {
38  timeinfo = std::localtime(&time);
39  }
40  else
41  {
42  timeinfo = std::gmtime(&time);
43  }
44 
45  char buffer[bufsize];
46  std::strftime(buffer, bufsize, format.c_str(), timeinfo);
47 
48  return static_cast<const string>(buffer);
49 }

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const Easy::time t 
)
friend

Returns local time as string in ISO 8601 format (FTTz).

Since
0.100.0

The documentation for this struct was generated from the following files: