Back to Documentations

Signature Description Parameters
template<typename ... Ts>
DataFrame
get_data_between_times(DateTime::HourType start_hr, // 24 hour notation
                       DateTime::HourType end_hr,   // 24 hour notation
                       DateTime::MinuteType start_mn = 0,
                       DateTime::MinuteType end_mn = 0,
                       DateTime::SecondType start_sc = 0,
                       DateTime::SecondType end_sc = 0,
                       DateTime::MillisecondType start_msc = 0,
                       DateTime::MillisecondType end_msc = 0,
                       inclusiveness incld = inclusiveness::neither) const;
This selects the rows using the index column that happen between the specified start and end time. It returns another DataFrame with selected data indexed by DateTime. Self is unchanged.

NOTE: The index column type must be DateTime or it won't compile
Ts: List all the types of all data columns. A type should be specified in the list only once.
start_hour: Specified start hour
start_minute: Specified start minute
start_second: Specified start second
start_msec: Specified start milli-second
end_hour: Specified end hour
end_minute: Specified end minute
end_second: Specified end second
end_msec: Specified end milli-second
incld: How to include/exclude start and end times
template<typename ... Ts>
PtrView
get_view_between_times(DateTime::HourType start_hr, // 24 hour notation
                       DateTime::HourType end_hr,   // 24 hour notation
                       DateTime::MinuteType start_mn = 0,
                       DateTime::MinuteType end_mn = 0,
                       DateTime::SecondType start_sc = 0,
                       DateTime::SecondType end_sc = 0,
                       DateTime::MillisecondType start_msc = 0,
                       DateTime::MillisecondType end_msc = 0,
                       inclusiveness incld = inclusiveness::neither);
It behaves like get_data_between_times(), but it returns a View. A view is a DataFrame that is a reference to the original DataFrame. So if you modify anything in the view the original DataFrame will also be modified.

NOTE: There are certain operations that you cannot do with a view. For example, you cannot add/delete columns, etc.
Ts: List all the types of all data columns. A type should be specified in the list only once.
start_hour: Specified start hour
start_minute: Specified start minute
start_second: Specified start second
start_msec: Specified start milli-second
end_hour: Specified end hour
end_minute: Specified end minute
end_second: Specified end second
end_msec: Specified end milli-second
incld: How to include/exclude start and end times
template<typename ... Ts>
ConstPtrView
get_view_between_times(DateTime::HourType start_hr, // 24 hour notation
                       DateTime::HourType end_hr,   // 24 hour notation
                       DateTime::MinuteType start_mn = 0,
                       DateTime::MinuteType end_mn = 0,
                       DateTime::SecondType start_sc = 0,
                       DateTime::SecondType end_sc = 0,
                       DateTime::MillisecondType start_msc = 0,
                       DateTime::MillisecondType end_msc = 0,
                       inclusiveness incld = inclusiveness::neither) const;
Same as above view, but it returns a const view. You can not change data in const views. But if the data is changed in the original DataFrame or through another view, it is reflected in the const view. Ts: List all the types of all data columns. A type should be specified in the list only once.
start_hour: Specified start hour
start_minute: Specified start minute
start_second: Specified start second
start_msec: Specified start milli-second
end_hour: Specified end hour
end_minute: Specified end minute
end_second: Specified end second
end_msec: Specified end milli-second
incld: How to include/exclude start and end times
static void test_get_data_between_times()  {

    std::cout << "\nTesting get_data_between_times( ) ..." << std::endl;

    DTDataFrame df;

    try  {
        df.read("DT_Intraday.csv", io_format::csv2);
    }
    catch (const DataFrameError &ex)  {
        std::cout << ex.what() << std::endl;
        ::exit(-1);
    }

    {
        // Between 11am and 11:30am
        //
        const auto  result = df.get_view_between_times<double, long>(11, 11, 0, 30);

        assert(result.get_index().size() == 207);
        assert(result.get_index()[0].date() == 19861116);
        assert(result.get_index()[10].date() == 19861125);
        assert(result.get_index()[100].date() == 19870303);
        assert(result.get_index()[206].date() == 19870623);
        assert(result.get_column<double>("dbl value").size() == 207);
        assert(result.get_column<double>("dbl value")[0] == 21.0);
        assert(result.get_column<double>("dbl value")[10] == 225.5);
        assert(result.get_column<double>("dbl value")[100] == 2438.0);
        assert(result.get_column<double>("dbl value")[206] == 4984.5);
        assert(result.get_column<long>("lng value").size() == 207);
        assert(result.get_column<long>("lng value")[0] == 420);
        assert(result.get_column<long>("lng value")[10] == 4510);
        assert(result.get_column<long>("lng value")[100] == 48760);
        assert(result.get_column<long>("lng value")[206] == 99690);
    }

    {
        const auto  result = df.get_view_between_times<double, long>(11, 11, 0, 30, 0, 0, 0, 0, inclusiveness::both);

        assert(result.get_index().size() == 226);
        assert(result.get_index()[0].date() == 19861116);
        assert(result.get_index()[10].date() == 19861125);
        assert(result.get_index()[100].date() == 19870224);
        assert(result.get_index()[225].date() == 19870623);
        assert(result.get_column<double>("dbl value").size() == 226);
        assert(result.get_column<double>("dbl value")[0] == 21.0);
        assert(result.get_column<double>("dbl value")[10] == 225.0);
        assert(result.get_column<double>("dbl value")[100] == 2283.5);
        assert(result.get_column<double>("dbl value")[225] == 4984.5);
        assert(result.get_column<long>("lng value").size() == 226);
        assert(result.get_column<long>("lng value")[0] == 420);
        assert(result.get_column<long>("lng value")[10] == 4500);
        assert(result.get_column<long>("lng value")[100] == 45670);
        assert(result.get_column<long>("lng value")[225] == 99690);
    }

    {
        const auto  result = df.get_data_between_times<double, long>(11, 11, 0, 30, 0, 0, 0, 0, inclusiveness::end);

        assert(result.get_index().size() == 218);
        assert(result.get_index()[0].date() == 19861116);
        assert(result.get_index()[10].date() == 19861125);
        assert(result.get_index()[100].date() == 19870226);
        assert(result.get_index()[217].date() == 19870623);
        assert(result.get_column<double>("dbl value").size() == 218);
        assert(result.get_column<double>("dbl value")[0] == 21.0);
        assert(result.get_column<double>("dbl value")[10] == 225.5);
        assert(result.get_column<double>("dbl value")[100] == 2331.0);
        assert(result.get_column<double>("dbl value")[217] == 4984.5);
        assert(result.get_column<long>("lng value").size() == 218);
        assert(result.get_column<long>("lng value")[0] == 420);
        assert(result.get_column<long>("lng value")[10] == 4510);
        assert(result.get_column<long>("lng value")[100] == 46620);
        assert(result.get_column<long>("lng value")[217] == 99690);
    }
}

C++ DataFrame