00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013
00014
00015 #include "zypp/base/String.h"
00016
00017 #include "zypp/Date.h"
00018
00019 using std::endl;
00020
00022 namespace zypp
00023 {
00024
00026
00027
00028
00029
00030 Date::Date( const std::string & seconds_r )
00031 { str::strtonum( seconds_r, _date ); }
00032
00034
00035
00036
00037
00038 std::string Date::form( const std::string & format_r ) const
00039 {
00040 static char buf[1024];
00041
00042 const char * tmp = ::setlocale( LC_TIME, NULL );
00043 std::string thisLocale( tmp ? tmp : "" );
00044
00045 if ( thisLocale.find( "UTF-8" ) == std::string::npos
00046 && thisLocale.find( "utf-8" ) == std::string::npos
00047 && thisLocale != "POSIX"
00048 && thisLocale != "C"
00049 && thisLocale != "" )
00050 {
00051
00052
00053 std::string needLocale = ".UTF-8";
00054 std::string::size_type loc = thisLocale.find_first_of( ".@" );
00055 if ( loc != std::string::npos )
00056 {
00057
00058 needLocale = thisLocale.substr( 0, loc ) + needLocale;
00059 loc = thisLocale.find_last_of( "@" );
00060 if ( loc != std::string::npos )
00061 {
00062
00063 needLocale += thisLocale.substr( loc );
00064 }
00065 }
00066 else
00067 {
00068
00069 needLocale = thisLocale + needLocale;
00070 }
00071 ::setlocale( LC_TIME, needLocale.c_str() );
00072 }
00073 else
00074 {
00075
00076 thisLocale.clear();
00077 }
00078
00079 if ( ! strftime( buf, 1024, format_r.c_str(), localtime( &_date ) ) )
00080 *buf = '\0';
00081
00082 if ( ! thisLocale.empty() )
00083 {
00084 ::setlocale( LC_TIME, thisLocale.c_str() );
00085 }
00086
00087 return buf;
00088 }
00089
00091 }