/** * TimeUtil.cc * * Created on: 29 oct. 2012 * Author: AKKA IS */ #include "TimeUtil.hh" #include #include #include #include "DD_time.hh" namespace AMDA { TimeUtil::TimeUtil() { } TimeUtil::~TimeUtil() { } int TimeUtil::monthday[][12] = { {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335} }; void TimeUtil::formatTimeInIso(const double time, std::ostream& pOs, t_DDTimeKind timeKind) { dd_tmstr_t tm; int visocos; tm.times = time; SetIntNew(&tm, timeKind); if (((tm.year & 3) == 0)&&(((tm.year % 100) != 0)||((tm.year % 400)==0))) visocos = 1; else visocos = 0; int month = 0; while((month < 12) && (tm.day >= monthday[visocos][month])) month++; int day = tm.day +1 - monthday[visocos][month-1]; pOs << std::setfill('0') << tm.year << "-" << std::setw(2) << std::right << month << "-" << std::setw(2) << std::right << day << "T" << std::setw(2) << std::right << tm.hour << ":" << std::setw(2) << std::right << tm.min << ":" << std::setw(2) <= monthday[visocos][month])) month++; int day = tm.day +1 - monthday[visocos][month-1]; pOs << std::setfill('0') << tm.year << "-" << std::setw(2) << std::right << month << "-" << std::setw(2) << std::right << day << "T" << std::setw(2) << std::right << tm.hour << ":" << std::setw(2) << std::right << tm.min << ":" << std::setw(2) <= monthday[visocos][month])) month++; int day = tm.day +1 - monthday[visocos][month-1]; pOs << std::setfill('0') << tm.year << "-" << std::setw(2) << std::right << month << "-" << std::setw(2) << std::right << day << "T" << std::setw(2) << std::right << tm.hour << ":" << std::setw(2) << std::right << tm.min << ":" << std::setw(2) <> tabTime[0]; //year; ss.width(1); ss >> c; //- ss.width(2); ss >> tabTime[1]; //month ss.width(1); ss >> c; //- ss.width(2); ss >> tabTime[2]; //day; ss.width(1); ss >> c; //T ss.width(2); ss >> tabTime[3]; //hour; ss.width(1); ss >> c; //: ss.width(2); ss >> tabTime[4]; //min; ss.width(1); ss >> c; //: ss.width(2); ss >> tabTime[5]; //sec; if (ss.eof()) tabTime[6] = 0; else { ss.width(1); ss >> c; //. ss.width(3); ss >> tabTime[6]; //ms; } UT = UT2double(tabTime); return UT->times; } std::string TimeUtil::formatTimeInIso(const double time, t_DDTimeKind timeKind) { std::stringstream ss; formatTimeInIso(time, ss, timeKind); return ss.str(); } std::string TimeUtil::DD2ISO_Time(std::string time, t_DDTimeKind timeKind) { return TimeUtil::formatTimeInIso(DD_Time2Double(const_cast(time.c_str())), timeKind); } void TimeUtil::double2DD_Time(const double time, std::ostream& pOs, t_DDTimeKind timeKind, const int offsetDay) { dd_tmstr_t UT; UT.times = time; SetIntNew(&UT, timeKind); // //sprintf(UTstring,"%04d%03d%02d%02d%02d%03d",(UT.year),(UT.day),(UT.hour), (UT.min), (UT.sec),(UT.msec)); UT.day+= offsetDay; pOs << std::setfill('0') <= monthday[visocos][month])) month++; int day = tm.day +1 - monthday[visocos][month-1]; pOs << std::setfill('0') << tm.year << " " << std::setw(2) << std::right << month << " " << std::setw(2) << std::right << day << " " << std::setw(2) << std::right << tm.hour << " " << std::setw(2) << std::right << tm.min << " " << std::setw(2) <