Sha256: 3707545ec6dd7300dc74c851b5dd77edc98df54d823b4b257f8203c244be9bb8

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

include Daru

describe Daru::DateTimeIndexHelper do


  describe '.infer_offset' do
    subject(:offset) { Daru::DateTimeIndexHelper.infer_offset(data) }

    context 'when the dataset does not have a regular offset' do
      let(:data) do
        [
          DateTime.new(2020, 1, 1, 00, 00, 00),
          DateTime.new(2020, 1, 1, 00, 01, 00),
          DateTime.new(2020, 1, 1, 00, 05, 00),
        ]
      end

      it 'returns nil' do
        expect(offset).to be_nil
      end
    end

    context 'when the dataset matches a defined offset' do
      let(:data) do
        [
          DateTime.new(2020, 1, 1, 00, 00, 00),
          DateTime.new(2020, 1, 1, 00, 01, 00),
          DateTime.new(2020, 1, 1, 00, 02, 00),
        ]
      end

      it 'returns the matched offset' do
        expect(offset).to be_an_instance_of(Daru::Offsets::Minute)
      end
    end

    context 'when the offset is a multiple of seconds' do
      let(:data) do
        [
          DateTime.new(2020, 1, 1, 00, 00, 00),
          DateTime.new(2020, 1, 1, 00, 00, 03),
          DateTime.new(2020, 1, 1, 00, 00, 06),
        ]
      end

      let(:expected_offset) { Daru::Offsets::Second.new(3) }

      it 'returns a Second offset' do
        expect(offset).to be_an_instance_of(Daru::Offsets::Second)
      end

      it 'has the correct multiplier' do
        expect(offset.freq_string).to eql(expected_offset.freq_string)
      end
    end

    context 'when the offset is less than a second' do
      let(:data) do
        [
          DateTime.new(2020, 1, 1, 00, 00, 00) + 0.00001,
          DateTime.new(2020, 1, 1, 00, 00, 00) + 0.00002,
          DateTime.new(2020, 1, 1, 00, 00, 00) + 0.00003,
        ]
      end

      it 'returns nil' do
        expect(offset).to be_nil
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daru-0.3 spec/date_time/date_time_index_helper_spec.rb