WSL/SLF GitLab Repository

Commit 55fbf756 authored by Mathias Bavay's avatar Mathias Bavay
Browse files

This is the fix for issue 140. When setting a Date with setDate(y,m,d,H,M, TZ)...

This is the fix for issue 140. When setting a Date with setDate(y,m,d,H,M, TZ) if TZ==0 no recalculation of the date elements (year, month, etc) would be performed, thus keeping a potential 24 for hours. If calling afterward getDate(gmt), it would return these internal values without any further calculation, thus returning hour=24.
parent ed696434
......@@ -165,28 +165,22 @@ void Date::setTimeZone(const double& in_timezone, const bool& in_dst) {
*/
void Date::setDate(const int& i_year, const int& i_month, const int& i_day, const int& i_hour, const int& i_minute, const double& i_timezone, const bool& i_dst)
{
plausibilityCheck(i_year, i_month, i_day, i_hour, i_minute);
plausibilityCheck(i_year, i_month, i_day, i_hour, i_minute); //also checks leap years
undef = false;
setTimeZone(i_timezone, i_dst);
if(timezone==0 && dst==false) {
//data is GMT and no DST
//setting values and computing GMT julian date
gmt_year = i_year;
gmt_month = i_month;
gmt_day = i_day;
gmt_hour = i_hour;
gmt_minute = i_minute;
gmt_julian = calculateJulianDate(gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
gmt_julian = calculateJulianDate(i_year, i_month, i_day, i_hour, i_minute);
} else {
//computing local julian date
const double local_julian = calculateJulianDate(i_year, i_month, i_day, i_hour, i_minute);
//converting local julian date to GMT julian date
gmt_julian = localToGMT(local_julian);
//updating values to GMT
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
}
//updating values to GMT, fixing potential 24:00 hour (ie: replaced by next day, 00:00)
calculateValues(gmt_julian, gmt_year, gmt_month, gmt_day, gmt_hour, gmt_minute);
}
void Date::setDate(const int& year, const unsigned int& month, const unsigned int& day, const unsigned int& hour, const unsigned int& minute, const double& in_timezone, const bool& in_dst)
......@@ -576,22 +570,9 @@ void Date::rnd(const double& precision, const RND& type) {
}
const Date Date::rnd(const Date& indate, const double& precision, const RND& type) {
if( !indate.isUndef() ) {
const double rnd_factor = (3600*24)/precision;
double gmt_julian;
if(type==UP)
gmt_julian = ceil(gmt_julian*rnd_factor) / rnd_factor;
if(type==DOWN)
gmt_julian = floor(gmt_julian*rnd_factor) / rnd_factor;
if(type==CLOSEST)
gmt_julian = round(gmt_julian*rnd_factor) / rnd_factor;
Date tmp(gmt_julian, indate.getTimeZone());
return tmp;
} else {
Date tmp(indate);
return tmp;
}
Date tmp(indate);
tmp.rnd(precision, type);
return tmp;
}
// OPERATORS //HACK this will have to handle Durations
......@@ -897,9 +878,9 @@ long Date::getJulianDayNumber(const int& _year, const int& _month, const int& _d
}
const long jdn = lday - 32075L +
1461L * ( lyear + 4800L + ( lmonth - 14L ) / 12L ) / 4L +
367L * ( lmonth - 2L - ( lmonth - 14L ) / 12L * 12L ) / 12L -
3L * ( ( lyear + 4900L + ( lmonth - 14L ) / 12L ) / 100L ) / 4L;
1461L * ( lyear + 4800L + ( lmonth - 14L ) / 12L ) / 4L +
367L * ( lmonth - 2L - ( lmonth - 14L ) / 12L * 12L ) / 12L -
3L * ( ( lyear + 4900L + ( lmonth - 14L ) / 12L ) / 100L ) / 4L;
return jdn;
}
......
......@@ -566,7 +566,7 @@ void ImisIO::calculatePsum(const Date& dateStart, const Date& dateEnd,
const std::vector< std::vector<MeteoData> >& vecMeteoAnetz,
std::vector< std::vector<double> >& vec_of_psums)
{
unsigned int nr_of_slices = (unsigned int)((dateEnd.getJulianDate(true) - dateStart.getJulianDate(true) + 0.00001) * 4.0) + 1;
const unsigned int nr_of_slices = (unsigned int)((dateEnd.getJulianDate(true) - dateStart.getJulianDate(true) + 0.00001) * 4.0) + 1;
for (unsigned int ii=0; ii<vecMeteoAnetz.size(); ii++){
double tmp_psum = 0.0;
......@@ -671,16 +671,6 @@ void ImisIO::readData(const Date& dateStart, const Date& dateEnd, std::vector< s
dateS.getDate(datestart[0], datestart[1], datestart[2], datestart[3], datestart[4]);
dateE.getDate(dateend[0], dateend[1], dateend[2], dateend[3], dateend[4]);
//Oracle can't deal with an integer for the hour of 24, hence the following workaround
if (datestart[3] == 24){
Date tmpDate = dateS + 3.0/(24.*3600.); //add three seconds to omit 24 for 00
tmpDate.getDate(datestart[0], datestart[1], datestart[2], datestart[3], datestart[4]);
}
if (dateend[3] == 24){
Date tmpDate = dateE + 3.0/(24.*3600.); //add three seconds to omit 24 for 00
tmpDate.getDate(dateend[0], dateend[1], dateend[2], dateend[3], dateend[4]);
}
//get data for one specific station
std::vector<std::string> vecHts1;
parseStationID(vecStationIDs.at(stationindex).getStationID(), stat_abk, stao_nr);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment