Changeset 1431 for trunk/lib/Date.cc


Ignore:
Timestamp:
Dec 17, 2011, 3:11:18 AM (9 years ago)
Author:
Peter Johansson
Message:

prefer yat's convert function and avoid tmp variables

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Date.cc

    r978 r1431  
    2222
    2323#include "Date.h"
     24
     25#include "yat/utility.h"
    2426
    2527#include <algorithm>
     
    9092      ss << " and ";
    9193    }
    92    
     94
    9395
    9496    unsigned int day = (t1-t0)/24/60/60;
     
    108110    time_t timezone_correction = timeinfo->tm_gmtoff;
    109111
    110     unsigned int year, month, day, hour, minute, second;
    111112    std::string tmp;
    112113    std::getline(sstream,tmp,'-');
    113     year=atoi(tmp.c_str());
    114     timeinfo->tm_year = year - 1900;
     114    using yat::utility::convert;
     115    timeinfo->tm_year = convert<unsigned int>(tmp) - 1900;
    115116
    116117    std::getline(sstream,tmp,'-');
    117     month=atoi(tmp.c_str());
    118     timeinfo->tm_mon = month - 1;
     118    timeinfo->tm_mon = convert<unsigned int>(tmp) - 1;
    119119
    120120    std::getline(sstream,tmp,'T');
    121     day=atoi(tmp.c_str());
    122     timeinfo->tm_mday = day;
     121    timeinfo->tm_mday = convert<unsigned int>(tmp);
    123122
    124123    std::getline(sstream,tmp,':');
    125     hour=atoi(tmp.c_str());
    126     timeinfo->tm_hour = hour;
     124    timeinfo->tm_hour = convert<unsigned int>(tmp);
    127125
    128126    std::getline(sstream,tmp,':');
    129     minute=atoi(tmp.c_str());
    130     timeinfo->tm_min = minute;
     127    timeinfo->tm_min = convert<unsigned int>(tmp);
    131128
    132129    std::getline(sstream,tmp,'.');
    133     second=atoi(tmp.c_str());
    134     timeinfo->tm_sec = second;
     130    timeinfo->tm_sec = convert<unsigned int>(tmp);
    135131
    136132    time_ = mktime(timeinfo);
     
    143139    std::stringstream ss;
    144140    struct tm* timeinfo = std::gmtime(&time_);
    145     char buffer[80]; 
     141    char buffer[80];
    146142    size_t res = std::strftime(buffer, 80, format.c_str(), timeinfo);
    147143    if (!res) {
     
    152148
    153149
    154   const Date& Date::operator=(const Date& rhs) 
     150  const Date& Date::operator=(const Date& rhs)
    155151  {
    156152    time_ = rhs.time_;
Note: See TracChangeset for help on using the changeset viewer.