36 const char * tmp = ::setlocale( LC_TIME, NULL );
39 if (
_mylocale.find(
"UTF-8" ) == std::string::npos
40 &&
_mylocale.find(
"utf-8" ) == std::string::npos
47 std::string needLocale =
".UTF-8";
49 if ( loc != std::string::npos )
52 needLocale =
_mylocale.substr( 0, loc ) + needLocale;
54 if ( loc != std::string::npos )
65 ::setlocale( LC_TIME, needLocale.c_str() );
77 ::setlocale( LC_TIME,
_mylocale.c_str() );
84 inline bool isDST(
struct tm & tm )
86 time_t t = ::mktime( &tm );
87 struct tm *tm2 = ::localtime( &t );
88 return ( tm2 && tm2->tm_isdst > 0 );
93 static const char * fmt[] = {
102 return fmt[dateFormat_r.asIntegral()];
107 static const char * fmt[] = {
113 return fmt[timeFormat_r.asIntegral()];
118 static const char * fmt[] = {
123 return fmt[timeZoneFormat_r.asIntegral()];
132 static char buf[512];
133 if ( ! strftime( buf, 512, format_r.c_str(), (base_r ==
Date::TB_UTC ? gmtime : localtime)( &date_r ) ) )
138 unsigned l = ::strlen( buf );
140 && ( buf[l-1] ==
'0' )
141 && ( buf[l-2] ==
'0' )
142 && ( buf[l-5] ==
'+' || buf[l-5] ==
'-') )
166 Date::Date(
const std::string & date_str,
const std::string & format )
167 : _date(
Date( date_str, format, TB_LOCALTIME ) )
175 struct tm tm = {0,0,0,0,0,0,0,0,0,0,0};
176 char * res = ::strptime( date_str.c_str(), format.c_str(), &tm );
182 _date = (base_r ==
TB_UTC ? ::timegm : ::timelocal)( &tm );
186 {
return doForm( format_r, base_r,
_date ); }
191 if ( dateFormat_r != DateFormat::none )
192 str << _dateFormat( dateFormat_r );
193 if ( timeFormat_r != TimeFormat::none )
195 if ( dateFormat_r != DateFormat::none )
197 str << _timeFormat( timeFormat_r );
198 if ( timeZoneFormat_r != TimeZoneFormat::none )
199 str << _timeZoneFormat( timeZoneFormat_r );
201 return doForm(
str, base_r,
_date );
207 if ( dateFormat_r != DateFormat::none )
208 str << _dateFormat( dateFormat_r );
209 if ( timeFormat_r != TimeFormat::none )
211 if ( dateFormat_r != DateFormat::none )
213 str << _timeFormat( timeFormat_r );
214 switch ( timeZoneFormat_r.asEnum() )
216 case TimeZoneFormat::none:
218 case TimeZoneFormat::name:
225 case TimeZoneFormat::offset:
226 str << _timeZoneFormat( TimeZoneFormat::offset );
230 return doForm(
str, base_r,
_date );