Changeset 751 for trunk/lib


Ignore:
Timestamp:
Jan 14, 2009, 1:36:20 PM (15 years ago)
Author:
Peter Johansson
Message:

closes #308

Location:
trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Date.cc

    r693 r751  
    44  Copyright (C) 2007 Peter Johansson
    55  Copyright (C) 2008 Jari Häkkinen
     6  Copyright (C) 2009 Peter Johansson
    67
    78  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2425
    2526#include <algorithm>
     27#include <cassert>
     28#include <ctime>
    2629#include <sstream>
    2730#include <string>
     
    2932namespace theplu {
    3033namespace svndigest {
    31 
    32   static const char* wdays_[7] = {
    33     "Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
    34     "Saturday"
    35   };
    36 
    37    
    38   static const char* month_[12] = {
    39     "January", "February", "March", "April", "May", "June", "July", "August",
    40     "September", "October", "November", "December"
    41   };
    42 
    4334
    4435  Date::Date(void)
     
    152143    std::stringstream ss;
    153144    struct tm* timeinfo = std::gmtime(&time_);
    154     for (std::string::iterator i=format.begin(); i!=format.end(); ++i) {
    155       if (*i == '%' && ++i !=format.end()) {
    156         if (*i == 'a')
    157           ss << std::string(wdays_[timeinfo->tm_wday]).substr(0,3);
    158         else if (*i == 'A')
    159           ss << wdays_[timeinfo->tm_wday];
    160         else if (*i == 'b')
    161           ss << std::string(month_[timeinfo->tm_mon]).substr(0,3);
    162         else if (*i == 'B')
    163           ss << month_[timeinfo->tm_mon];
    164         else if (*i == 'd')
    165           ss << timeinfo->tm_mday;
    166         else if (*i == 'e') {
    167           if (timeinfo->tm_mday<10)
    168             ss << "0";
    169           ss << timeinfo->tm_mday;
    170         }
    171         else if (*i == 'H') {
    172           if (timeinfo->tm_hour<10)
    173             ss << "0";
    174           ss << timeinfo->tm_hour;
    175         }
    176         else if (*i == 'I') {
    177           int tmp = (timeinfo->tm_hour + 11) % 12 + 1;
    178           if (tmp<10)
    179             ss << "0";
    180           ss << tmp;
    181         }
    182         else if (*i == 'j')
    183           ss << timeinfo->tm_yday+1;
    184         else if (*i == 'm') {
    185           if (timeinfo->tm_mon<9)
    186             ss << "0";
    187           ss << timeinfo->tm_mon+1;
    188         }
    189         else if (*i == 'M') {
    190           if (timeinfo->tm_min<10)
    191             ss << "0";
    192           ss << timeinfo->tm_min;
    193         }
    194         else if (*i == 'P')
    195           if (timeinfo->tm_hour<12)
    196             ss << "AM";
    197           else
    198             ss << "PM";
    199         else if (*i == 'S') {
    200           if (timeinfo->tm_sec<10)
    201             ss << "0";
    202           ss << timeinfo->tm_sec;
    203         }
    204         else if (*i == 'w')
    205           if (timeinfo->tm_wday==0)
    206             ss << "7";
    207           else
    208             ss << timeinfo->tm_wday;
    209         else if (*i == 'y') {
    210           int y(timeinfo->tm_year % 100);
    211           if (y<10)
    212             ss << "0";
    213           ss << y;
    214         }
    215         else if (*i == 'Y')
    216           ss << timeinfo->tm_year+1900;
    217         else if (*i == 'Z')
    218           ss << timeinfo->tm_zone;
    219         else {
    220           ss << '%';
    221           --i;
    222         }
    223       }
    224       else
    225         ss << *i;
    226     }
    227 
    228     return ss.str();
     145    char buffer[80];
     146    size_t res = std::strftime(buffer, 80, format.c_str(), timeinfo);
     147    assert(res>0);
     148    return buffer;
    229149  }
    230150
  • trunk/lib/Node.cc

    r727 r751  
    44  Copyright (C) 2005, 2006, 2007 Jari Häkkinen, Peter Johansson
    55  Copyright (C) 2008 Jari Häkkinen
     6  Copyright (C) 2009 Peter Johansson
    67
    78  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    2425
    2526#include "Date.h"
     27#include "HtmlStream.h"
    2628#include "html_utility.h"
    2729#include "SVNlog.h"
     
    229231                                  const SVNlog& log) const
    230232  {
     233    HtmlStream hs(os);
    231234    os << "<h3>Author Summary</h3>";
    232235    os << "<table class=\"listings\">\n";
     
    252255
    253256    // print authors
    254     const std::string timefmt("%e/%m/%y %H:%M:%S");
     257    const std::string timefmt("%Y-%m-%d  %H:%M");
    255258    for (std::set<std::string>::const_iterator i=stats.authors().begin();
    256259         i!=stats.authors().end(); ++i){
     
    269272        const Commitment& lc(log.latest_commit(*i));
    270273        os << "</td>" << "<td>" << trac_revision(lc.revision())
    271            << "</td>" << "<td>" << Date(lc.date())(timefmt);
     274           << "</td>" << "<td>";
     275        hs << Date(lc.date())(timefmt);
    272276      }
    273277      else {
     
    297301    const Commitment& lc(log.latest_commit());
    298302    os << "<td>" << trac_revision(lc.revision()) << "</td>\n";
    299     os << "<td>" << Date(lc.date())(timefmt)<< "</td>\n";
     303    os << "<td>";
     304    hs << Date(lc.date())(timefmt);
     305    os << "</td>\n";
    300306    os << "</tr>\n";
    301307    os << "</tbody>\n";
  • trunk/lib/first_page.cc

    r693 r751  
    44  Copyright (C) 2006 Peter Johansson
    55  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
     6  Copyright (C) 2009 Peter Johansson
    67
    78  This file is part of svndigest, http://dev.thep.lu.se/svndigest
     
    8586    Date begin(log.commits()[0].date());
    8687    Date end(log.commits().back().date());
    87     std::string timefmt("%a, %e %b %Y  %H:%M:%S");
     88    std::string timefmt("%a %b %e %H:%M:%S %Y");
    8889
    8990    os << "<div class=\"main\">"
     
    118119                     const Stats& stats)
    119120  {
     121    HtmlStream hs(os);
    120122    os << "<div class=\"main\">"
    121123       << "<table class=\"main\"><thead><tr><th colspan=\"2\">"
     
    130132       <<"</tr>";
    131133
    132     std::string timefmt("%Y %b %d %H:%M:%S");
     134    std::string timefmt("%Y-%m-%d  %H:%M");
    133135    using namespace std;
    134136    for (vector<Commitment>::const_iterator i=lc.begin(); i!=lc.end(); ++i) {
     
    145147         << "%)</td><td>" << stats.comments(i->author()) << " ("
    146148         << 100*stats.comments(i->author())/(stats.comments()?stats.comments():1)
    147          << "%)</td><td>" << Date(i->date())(timefmt) << "</td>" <<"</tr>";
     149         << "%)</td><td>";
     150      hs << Date(i->date())(timefmt);
     151      os << "</td>" <<"</tr>";
    148152    }
    149153    os << "<tr><td>Total</td>";
     
    168172       << "<td>Removed</td><td>Message</td></tr>\n";
    169173    HtmlStream hs(os);
    170     std::string timefmt("%Y %b %d %H:%M:%S");
     174    std::string timefmt("%Y-%m-%d  %H:%M");
    171175    const size_t maxlength = 80;
    172176    const Configuration& conf = Configuration::instance();
     
    179183         << "</td>";
    180184      Date date(i->date());
    181       os << "<td>" << date(timefmt) << "</td>";
     185      os << "<td>";
     186      hs << date(timefmt);
     187      os << "</td>";
    182188      os << "<td>";
    183189      os << trac_revision(i->revision());
  • trunk/lib/html_utility.cc

    r750 r751  
    6464  {
    6565    Date date;
    66     os << "<p class=\"footer\">\nGenerated on "
    67        << date("%a %b %d %H:%M:%S %Y") << " (UTC) by "
    68        << anchor("http://dev.thep.lu.se/svndigest/",
     66    HtmlStream hs(os);
     67    os << "<p class=\"footer\">\nGenerated on ";
     68    hs << date("%a %b %e %H:%M:%S %Y") << " (UTC) by ";
     69    os << anchor("http://dev.thep.lu.se/svndigest/",
    6970                 PACKAGE_STRING, 0, "");
    7071    if (DEV_BUILD)
Note: See TracChangeset for help on using the changeset viewer.