Am 10.08.2013 00:39, schrieb Olaf Radicke:
> it's a bit hard to convert cxxtools::DateTime to RFC 822 (rss feed) date
> format:
>
> <# target date format (RFC 822): Mon, 06 Sep 2009 16:20:00 +0000 #>
> % cxxtools::DateTime lastupdate = feedManager.getLastUpdate();
> % time_t rawtime;
> % struct tm * timeinfo;
> % const char * weekday[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
> % const char * monthname[] = {"NON",
> % "Jan","Feb","Mar",
> % "Apr","May","Jun",
> % "Jul","Aug","Sep",
> % "Oct","Nov","Dec"};
> % std::string strhour;
> % std::string strminute;
> % std::string strsecond;
> % time ( &rawtime );
> % timeinfo = localtime ( &rawtime );
> % timeinfo->tm_year = lastupdate.year();
> % timeinfo->tm_mon = lastupdate.month();
> % timeinfo->tm_mday = lastupdate.day();
> % mktime ( timeinfo );
> % if ( lastupdate.hour() < 10 ) {
> % strhour = "0" + cxxtools::convert<std::string>( lastupdate.hour() );
> % } else {
> % strhour = cxxtools::convert<std::string>( lastupdate.hour() );
> % };
> % if ( lastupdate.minute() < 10 ) {
> % strminute =
> % "0" + cxxtools::convert<std::string>( lastupdate.minute() );
> % } else {
> % strminute =
> % cxxtools::convert<std::string>( lastupdate.minute() );
> % };
> % if ( lastupdate.second() < 10 ) {
> % strsecond =
> % "0" + cxxtools::convert<std::string>( lastupdate.second() );
> % } else {
> % strsecond =
> % cxxtools::convert<std::string>( lastupdate.second() );
> % };
>
> <pubDate><$ weekday[timeinfo->tm_wday] $> , <$ lastupdate.day() $> <$
> monthname[lastupdate.month()] $> <$ lastupdate.year() $> <$ strhour $>:<$
> strminute $>:<$ strsecond $> +0000 </pubDate>
>
>
> Olaf
>
Do not use localtime in tntnet applications. It is not thread safe.
localtime_r is the thread safe variant.
And for formatting there is strftime:
cxxtools::DateTime dt(2013, 5, 15, 0, 0, 0);
struct tm timeinfo;
timeinfo.tm_year = dt.year();
timeinfo.tm_mon = dt.month() - 1;
timeinfo.tm_mday = dt.day();
timeinfo.tm_wday = 0;
timeinfo.tm_hour = dt.hour();
timeinfo.tm_min = dt.minute();
timeinfo.tm_sec = dt.second();
timeinfo.tm_isdst = 0;
time_t t = mktime(&timeinfo); // somewhat strange to use mktime to
convert tm to time_t and localtime_r back to tm but we need the day of week
localtime_r(&t, &timeinfo);
char buffer[80];
strftime(buffer, sizeof(buffer), "%a, %d %b %y %T %z", &timeinfo);
std::cout << buffer << std::endl;
Tommi
------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general