Sha256: 94f7cf7115befd7cc17398b6f2b6a362e9fe4c90a82f699d692d13ca356aa4fb

Contents?: true

Size: 1.74 KB

Versions: 124

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

RSpec.describe :distance_of_time_in_words do

  INTERVALS = [:years, :months, :weeks, :days, :hours, :minutes, :seconds]
  SECONDS_IN_INTERVAL = INTERVALS.zip(
    [365 * 24 * 60 * 60,
     30 * 24 * 60 * 60,
     7 * 24 * 60 * 60,
     24 * 60 * 60,
     60 * 60,
     60,
     1]).to_h
  link :distance_of_time_in_words, from: :ree_datetime

  let(:err_result) {distance_of_time_in_words(Time.new(2040, 1, 1,2, 15),
                               Time.new(2012, 1, 1, 2, 30))}
  it {
    from_time = Time.now
    expect{ err_result }.to raise_error(ArgumentError)

    expect(distance_of_time_in_words(from_time, from_time + 50 * SECONDS_IN_INTERVAL[:minutes])).to eq('about 1 hour')
    expect(distance_of_time_in_words(from_time, from_time + 15)).to eq('less than a minute')
    expect(distance_of_time_in_words(from_time, from_time + 15, include_seconds: true)).to eq('less than 20 seconds')
    expect(distance_of_time_in_words(from_time, from_time + 60 * SECONDS_IN_INTERVAL[:hours])).to eq('3 days')
    expect(distance_of_time_in_words(from_time, from_time + 45, include_seconds: true)).to eq('less than a minute')
    expect(distance_of_time_in_words(from_time, from_time + 76)).to eq('1 minute')
    expect(distance_of_time_in_words(from_time, from_time + 1 * SECONDS_IN_INTERVAL[:years] + 3 * SECONDS_IN_INTERVAL[:days])).to eq('about 1 year')
    expect(distance_of_time_in_words(from_time, from_time + 3 * SECONDS_IN_INTERVAL[:years] + 6 * SECONDS_IN_INTERVAL[:months])).to eq('over 3 years')
    expect(distance_of_time_in_words(from_time, from_time + 4 * SECONDS_IN_INTERVAL[:years] + 3 * SECONDS_IN_INTERVAL[:days])).to eq('about 4 years')
    expect(distance_of_time_in_words(Time.now, Time.now)).to eq('less than a minute')
  }
end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_datetime/spec/ree_datetime/functions/distance_of_time_in_words_spec.rb