+ inline bool isDST( struct tm & tm )
+ {
+ time_t t = ::mktime( &tm );
+ struct tm *tm2 = ::localtime( &t );
+ return ( tm2 && tm2->tm_isdst > 0 );
+ }
+
+ inline const char * _dateFormat( Date::DateFormat dateFormat_r )
+ {
+ static const char * fmt[] = {
+ "", ///< ""
+ "%Y-%m-%d", ///< 2014-02-07
+ "%Y-%m", ///< 2014-02
+ "%Y", ///< 2014
+ "%G-W%V", ///< 2014-W06
+ "%G-W%V-%u", ///< 2014-W06-5 (1 is Monday)
+ "%Y-%j", ///< 2014-038
+ };
+ return fmt[dateFormat_r.asIntegral()];
+ }
+
+ inline const char * _timeFormat( Date::TimeFormat timeFormat_r )
+ {
+ static const char * fmt[] = {
+ "", ///< ""
+ "%H:%M:%S", ///< 07:06:41
+ "%H:%M", ///< 07:06
+ "%H", ///< 07
+ };
+ return fmt[timeFormat_r.asIntegral()];
+ }
+
+ inline const char * _timeZoneFormat( Date::TimeZoneFormat timeZoneFormat_r )
+ {
+ static const char * fmt[] = {
+ "", ///< ""
+ " %Z", ///< UTC, CET, ...
+ "%z", ///< +0000
+ };
+ return fmt[timeZoneFormat_r.asIntegral()];
+ }
+
+ inline std::string doForm( const std::string & format_r, Date::TimeBase base_r, const Date::ValueType & date_r )
+ {
+ if ( ! date_r )
+ return "0";
+
+ LocaleGuard guard;
+ static char buf[512];
+ if ( ! strftime( buf, 512, format_r.c_str(), (base_r == Date::TB_UTC ? gmtime : localtime)( &date_r ) ) )
+ *buf = '\0';
+ else
+ {
+ // strip a trailing '00' in a timeZoneFormat
+ unsigned l = ::strlen( buf );
+ if ( l >= 5
+ && ( buf[l-1] == '0' )
+ && ( buf[l-2] == '0' )
+ && ( buf[l-5] == '+' || buf[l-5] == '-') )
+ buf[l-2] = '\0';
+ }
+ return buf;
+ }
+ } // namespace
+ ///////////////////////////////////////////////////////////////////