A toolkit for working with phylogenetic data.
v0.24.0
date_time.cpp File Reference

Detailed Description

Implementation of date and time functions.

Definition in file date_time.cpp.

#include "genesis/utils/tools/date_time.hpp"
#include "genesis/utils/text/string.hpp"
#include "genesis/utils/core/options.hpp"
#include <array>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <locale>
#include <mutex>
#include <sstream>
#include <stdexcept>

Go to the source code of this file.

Namespaces

 genesis
 Container namespace for all symbols of genesis in order to keep them separate when used as a library.
 
 genesis::utils
 

Functions

std::tm convert_to_tm (std::string const &str, std::string const &format, std::string const &locale)
 Convert a std::string to a std::tm date/time object, if possible. Throw otherwise. More...
 
std::tm convert_to_tm (std::string const &str, std::string const &format)
 Convert a std::string to a std::tm date/time object, if possible. Throw otherwise. More...
 
std::tm convert_to_tm (std::string const &str)
 Convert a std::string to a std::tm date/time object, if possible. Throw otherwise. More...
 
bool convert_to_tm_ (std::string const &str, std::string const &format, std::string const &locale, std::tm &t)
 Local helper function that does the heavy load of time conversion. More...
 
std::string current_date ()
 Returns the current date as a string in the format "2014-12-31". More...
 
std::string current_time ()
 Returns the current time as a string in the format "13:37:42". More...
 
bool is_convertible_to_tm (std::string const &str, std::string const &format, std::string const &locale)
 Return whether a std::string is convertible to a std::tm date/time object, that is, whether it contains a date/time in a recognizable format. More...
 
bool is_convertible_to_tm (std::string const &str, std::string const &format)
 Return whether a std::string is convertible to a std::tm date/time object, that is, whether it contains a date/time in a recognizable format. More...
 
bool is_convertible_to_tm (std::string const &str)
 Return whether a std::string is convertible to a std::tm date/time object, that is, whether it contains a date/time in a recognizable format. More...
 
std::tm time_to_tm (std::time_t const &time, bool use_local_time=false)
 Convert std::time_t object to a std::tm object. More...
 
std::vector< std::tm > time_to_tm (std::vector< std::time_t > const &times, bool use_local_time=false)
 Convert a std::vector of std::time_t objects to a std::vector of std::tm objects. More...
 
std::string tm_date_to_string (std::tm const &time)
 Print the given std::tm object as a std::string containing only the date, using the ISO 8601 extended format. More...
 
std::string tm_time_to_string (std::tm const &time)
 Print the given std::tm object as a std::string containing only the time, using the ISO 8601 extended format. More...
 
std::string tm_to_string (std::tm const &time, std::string const &format, std::string const &locale)
 Print the given std::tm object as a std::string, using the format and locale. More...
 
std::string tm_to_string (std::tm const &time, std::string const &format)
 Print the given std::tm object as a std::string, using the format. More...
 
std::string tm_to_string (std::tm const &time)
 Print the given std::tm object as a std::string, using the ISO 8601 extended format. More...
 
std::time_t tm_to_time (std::tm time, bool use_local_time=false)
 Convert std::tm object to a std::time_t object. More...
 
std::vector< std::time_t > tm_to_time (std::vector< std::tm > const &times, bool use_local_time=false)
 Convert a std::vector of std::tm objects to a std::vector of std::time_t objects. More...
 

Variables

static const std::array< std::string, 9 > formats_
 
static const std::array< std::string, 3 > locales_ = {{ "C", "en_US.UTF-8", "" }}
 
static std::mutex tm_mutex_
 The std::localtime and std::gmtime functions are not thread safe, due to their shared internal state. Make sure that we can use them from multiple threads. More...