projects
/
platform
/
upstream
/
libzypp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a14d3cd
)
Adjust locale in Date(str, format) c-tor, like in Date::format().
author
Ján Kupec
<jkupec@suse.cz>
Thu, 22 Jan 2009 17:48:51 +0000
(18:48 +0100)
committer
Ján Kupec
<jkupec@suse.cz>
Thu, 22 Jan 2009 17:48:51 +0000
(18:48 +0100)
zypp/Date.cc
patch
|
blob
|
history
diff --git
a/zypp/Date.cc
b/zypp/Date.cc
index
483bafd
..
367ce34
100644
(file)
--- a/
zypp/Date.cc
+++ b/
zypp/Date.cc
@@
-22,6
+22,9
@@
using std::endl;
namespace zypp
{ /////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
+ static std::string adjustLocale();
+ static void restoreLocale(const std::string & locale);
+
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : Date::Date
///////////////////////////////////////////////////////////////////
//
// METHOD NAME : Date::Date
@@
-33,9
+36,15
@@
namespace zypp
Date::Date( const std::string & date_str, const std::string & format )
{
struct tm tm;
Date::Date( const std::string & date_str, const std::string & format )
{
struct tm tm;
- if ( ::strptime( date_str.c_str(), format.c_str(), &tm ) != NULL )
+ std::string thisLocale = adjustLocale();
+
+ char * res = ::strptime( date_str.c_str(), format.c_str(), &tm );
+ if ( res != NULL )
_date = ::timelocal( &tm );
_date = ::timelocal( &tm );
- else
+
+ restoreLocale(thisLocale);
+
+ if (res == NULL)
throw DateFormatException(
str::form( "Invalid date format: '%s'", date_str.c_str() ) );
}
throw DateFormatException(
str::form( "Invalid date format: '%s'", date_str.c_str() ) );
}
@@
-48,7
+57,18
@@
namespace zypp
std::string Date::form( const std::string & format_r ) const
{
static char buf[1024];
std::string Date::form( const std::string & format_r ) const
{
static char buf[1024];
+ std::string thisLocale = adjustLocale();
+ if ( ! strftime( buf, 1024, format_r.c_str(), localtime( &_date ) ) )
+ *buf = '\0';
+
+ restoreLocale(thisLocale);
+
+ return buf;
+ }
+
+ static std::string adjustLocale()
+ {
const char * tmp = ::setlocale( LC_TIME, NULL );
std::string thisLocale( tmp ? tmp : "" );
const char * tmp = ::setlocale( LC_TIME, NULL );
std::string thisLocale( tmp ? tmp : "" );
@@
-86,15
+106,15
@@
namespace zypp
thisLocale.clear();
}
thisLocale.clear();
}
- if ( ! strftime( buf, 1024, format_r.c_str(), localtime( &_date ) ) )
- *buf = '\0';
+ return thisLocale;
+ }
- if ( ! thisLocale.empty() )
+ static void restoreLocale(const std::string & locale)
+ {
+ if ( ! locale.empty() )
{
{
- ::setlocale( LC_TIME,
thisL
ocale.c_str() );
+ ::setlocale( LC_TIME,
l
ocale.c_str() );
}
}
-
- return buf;
}
/////////////////////////////////////////////////////////////////
}
/////////////////////////////////////////////////////////////////