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

Method firstDateTime

src/utilities/sql/SqlFile_Impl.cpp:2883–2931  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2881 }
2882
2883 openstudio::DateTime SqlFile_Impl::firstDateTime(bool includeHourAndMinute, int envPeriodIndex) {
2884 // default until added to eplusout.sql from energy plus
2885 boost::optional<unsigned> year;
2886 unsigned month = 1;
2887 unsigned day = 1;
2888 unsigned hour = 1;
2889 unsigned minute = 0;
2890
2891 if (m_db) {
2892 std::stringstream s;
2893 s << "SELECT ";
2894 if (hasYear()) {
2895 s << "Year, ";
2896 }
2897 s << "Month, Day, Hour, Minute from Time where Month is not NULL and Day is not null and EnvironmentPeriodIndex = " << envPeriodIndex
2898 << " LIMIT 1";
2899
2900 sqlite3_stmt* sqlStmtPtr;
2901 int code = sqlite3_prepare_v2(m_db, s.str().c_str(), -1, &sqlStmtPtr, nullptr);
2902
2903 code = sqlite3_step(sqlStmtPtr);
2904 if (code == SQLITE_ROW) {
2905 int b = 0;
2906 if (hasYear()) {
2907 year = sqlite3_column_int(sqlStmtPtr, b++);
2908 }
2909 month = sqlite3_column_int(sqlStmtPtr, b++);
2910 day = sqlite3_column_int(sqlStmtPtr, b++);
2911 if (includeHourAndMinute) {
2912 hour = sqlite3_column_int(sqlStmtPtr, b++);
2913 minute = sqlite3_column_int(sqlStmtPtr, b++);
2914 } else {
2915 hour = 1;
2916 minute = 0;
2917 }
2918 }
2919 sqlite3_finalize(sqlStmtPtr);
2920 }
2921
2922 // Note JM 2019-03-14: Starting with E+ v8.9.0, we actually have Year in the SQL file
2923 // So if we can, we use the actual year, otherwise we initialze with defaults
2924 // and let the Date Ctor figure out the assumed year
2925 openstudio::Date date = year ? Date(monthOfYear(month), day, *year) : Date(monthOfYear(month), day);
2926
2927 // DLM: get standard time zone?
2928 openstudio::Time time(0, hour, minute, 0);
2929
2930 return openstudio::DateTime(date, time);
2931 }
2932
2933 openstudio::DateTime SqlFile_Impl::lastDateTime(bool includeHourAndMinute, int envPeriodIndex) {
2934 // default until added to eplusout.sql from energy plus

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