30 inline bool isDST(
struct tm & tm )
32 time_t t = ::mktime( &tm );
33 struct tm *tm2 = ::localtime( &t );
34 return ( tm2 && tm2->tm_isdst > 0 );
59 Date::Date(
const std::string & date_str,
const std::string & format )
60 : _date(
Date( date_str, format, TB_LOCALTIME ) )
66 struct tm tm = {0,0,0,0,0,0,0,0,0,0,0};
69 char * res = ::strptime( date_str.c_str(), format.c_str(), &tm );
73 _date = (base_r ==
TB_UTC ? ::timegm : ::timelocal)( &tm );
79 str::form(
"Invalid date format: '%s'", date_str.c_str() ) );
90 static char buf[1024];
93 if ( ! strftime( buf, 1024, format_r.c_str(), (base_r ==
TB_UTC ? gmtime : localtime)( &
_date ) ) )
103 const char * tmp = ::setlocale( LC_TIME, NULL );
104 std::string thisLocale( tmp ? tmp :
"" );
106 if ( thisLocale.find(
"UTF-8" ) == std::string::npos
107 && thisLocale.find(
"utf-8" ) == std::string::npos
108 && thisLocale !=
"POSIX"
110 && thisLocale !=
"" )
114 std::string needLocale =
".UTF-8";
116 if ( loc != std::string::npos )
119 needLocale = thisLocale.substr( 0, loc ) + needLocale;
120 loc = thisLocale.find_last_of(
"@" );
121 if ( loc != std::string::npos )
124 needLocale += thisLocale.substr( loc );
130 needLocale = thisLocale + needLocale;
132 ::setlocale( LC_TIME, needLocale.c_str() );
145 if ( ! locale.empty() )
146 ::setlocale( LC_TIME, locale.c_str() );
static const ValueType day
static const ValueType minute
static const ValueType month31
static void restoreLocale(const std::string &locale)
static const ValueType month30
static const ValueType month
static const ValueType month29
ValueType _date
Calendar time.
Store and operate on date (time_t).
static const ValueType year365
static const ValueType month28
static const ValueType year
_It strtonum(const C_Str &str)
Parsing numbers from string.
std::string form(const char *format,...)
Printf style construction of std::string.
static const ValueType hour
std::string form(const std::string &format_r) const
Return string representation according to format as localtime.
static const ValueType year366
static std::string adjustLocale()
static const ValueType second