15#include <zypp-core/base/String.h>
16#include <zypp-core/base/Xml.h>
18#include <zypp-core/Date.h>
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";
48 std::string::size_type loc =
_mylocale.find_first_of(
".@" );
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 );
Store and operate on date (time_t).
ValueType _date
Calendar time.
std::string print(DateFormat dateFormat_r=DateFormat::calendar, TimeFormat timeFormat_r=TimeFormat::seconds, TimeZoneFormat timeZoneFormat_r=TimeZoneFormat::name, TimeBase base_r=TB_LOCALTIME) const
Default format is '2014-02-07 07:06:41 CET' The default is DateFormat::calendar, TimeFormat::seconds,...
static const ValueType year365
std::string printISO(DateFormat dateFormat_r=DateFormat::calendar, TimeFormat timeFormat_r=TimeFormat::seconds, TimeZoneFormat timeZoneFormat_r=TimeZoneFormat::name, TimeBase base_r=TB_LOCALTIME) const
Default ISO 8601 format is '2014-02-07T07:06:41+01'
static const ValueType hour
static const ValueType day
static const ValueType month31
base::EnumClass< ETimeFormatDef > TimeFormat
'enum class TimeFormat'
static const ValueType minute
base::EnumClass< EDateFormatDef > DateFormat
'enum class DateFormat'
base::EnumClass< ETimeZoneFormatDef > TimeZoneFormat
'enum class TimeZoneFormat'
static const ValueType month30
static const ValueType month
static const ValueType year366
std::string form(const std::string &format_r) const
Return string representation according to format as localtime.
static const ValueType month28
static const ValueType month29
static const ValueType second
static const ValueType year
Temorarily change a locale category value.
LocaleGuard(int category_r, const std::string &value_r="C")
Ctor saving the current locale category value.
~LocaleGuard()
Dtor asserts the saved locale category value is restored.
String related utilities and Regular expression matching.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
TInt strtonum(const C_Str &str)
Parsing numbers from string.
std::ostream & node(std::ostream &out_r, const std::string &name_r, Node::Attr attr_r)
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpAsXmlOn(std::ostream &str, const Repository &obj)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...