MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / lastDateTime

Method lastDateTime

src/utilities/sql/SqlFile_Impl.cpp:2933–2981  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2931 }
2932
2933 openstudio::DateTime SqlFile_Impl::lastDateTime(bool includeHourAndMinute, int envPeriodIndex) {
2934 // default until added to eplusout.sql from energy plus
2935 boost::optional<unsigned> year;
2936 unsigned month = 1;
2937 unsigned day = 1;
2938 unsigned hour = 1;
2939 unsigned minute = 0;
2940
2941 if (m_db) {
2942 std::stringstream s;
2943 s << "SELECT ";
2944 if (hasYear()) {
2945 s << "Year, ";
2946 }
2947 s << "Month, Day, Hour, Minute from Time where Month is not NULL and Day is not null and EnvironmentPeriodIndex = " << envPeriodIndex
2948 << " order by TimeIndex DESC LIMIT 1";
2949
2950 sqlite3_stmt* sqlStmtPtr;
2951 int code = sqlite3_prepare_v2(m_db, s.str().c_str(), -1, &sqlStmtPtr, nullptr);
2952
2953 code = sqlite3_step(sqlStmtPtr);
2954 if (code == SQLITE_ROW) {
2955 int b = 0;
2956 if (hasYear()) {
2957 year = sqlite3_column_int(sqlStmtPtr, b++);
2958 }
2959 month = sqlite3_column_int(sqlStmtPtr, b++);
2960 day = sqlite3_column_int(sqlStmtPtr, b++);
2961 if (includeHourAndMinute) {
2962 hour = sqlite3_column_int(sqlStmtPtr, b++);
2963 minute = sqlite3_column_int(sqlStmtPtr, b++);
2964 } else {
2965 hour = 24;
2966 minute = 0;
2967 }
2968 }
2969 sqlite3_finalize(sqlStmtPtr);
2970 }
2971
2972 // Note JM 2019-03-14: Starting with E+ v8.9.0, we actually have Year in the SQL file
2973 // So if we can, we use the actual year, otherwise we initialze with defaults
2974 // and let the Date Ctor figure out the assumed year
2975 openstudio::Date date = year ? Date(monthOfYear(month), day, *year) : Date(monthOfYear(month), day);
2976
2977 // DLM: get standard time zone?
2978 openstudio::Time time(0, hour, minute, 0);
2979
2980 return openstudio::DateTime(date, time);
2981 }
2982
2983 openstudio::OptionalTimeSeries SqlFile_Impl::timeSeries(const DataDictionaryItem& dataDictionary) {
2984 openstudio::OptionalTimeSeries ts;

Callers 1

timeSeriesMethod · 0.95

Calls 4

monthOfYearFunction · 0.85
DateTimeClass · 0.70
DateClass · 0.50
strMethod · 0.45

Tested by

no test coverage detected