Sha256: a875141500869168ff0e35c02a58ac71887362469014c2fad7085ffb0e086f09

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

describe Time do

  describe 'weekend' do

    (0..6).each do |n|
      context "Monday plus #{n} days" do
        subject { Time.parse('2014-01-06') + n.days }
        its(:beginning_of_weekend){ should eq Time.parse('2014-01-10 15:00') }
        its(:end_of_weekend){ should eq Time.parse('2014-01-13 02:00').end_of_hour }
      end
    end
  end

  describe 'fortnight' do

    context 'first day of year' do
      subject { Time.parse '2014-01-01' }
      its(:beginning_of_fortnight){ should eq Time.parse('2014-01-01') }
      its(:end_of_fortnight){ should eq Time.parse('2014-01-14').end_of_day }
    end

    context 'second fortnight of year' do
      subject { Time.parse '2014-01-16' }
      its(:beginning_of_fortnight){ should eq Time.parse('2014-01-15') }
      its(:end_of_fortnight){ should eq Time.parse('2014-01-28').end_of_day }
    end

    context 'middle of year' do
      subject { Time.parse '2014-06-13' }
      its(:beginning_of_fortnight){ should eq Time.parse('2014-06-04') }
      its(:end_of_fortnight){ should eq Time.parse('2014-06-17').end_of_day }
    end

    context 'last day of year' do
      subject { Time.parse '2014-12-31' }
      its(:beginning_of_fortnight){ should eq Time.parse('2014-12-31') }
      its(:end_of_fortnight){ should eq Time.parse('2015-01-13').end_of_day }
    end
  end

  describe 'calendar_month' do

    subject { Time.parse '2014-01-01' }

    context 'week begins Monday' do
      its(:beginning_of_calendar_month){ should eq Time.parse('2013-12-30') }
      its(:end_of_calendar_month){ should eq Time.parse('2014-02-02').end_of_day }
    end

    context 'week begins Sunday' do
      it { subject.beginning_of_calendar_month(:sunday).should eq Time.parse('2013-12-29') }
      it { subject.end_of_calendar_month(:sunday).should eq Time.parse('2014-02-01').end_of_day }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
by_star-2.2.0.rc1 spec/unit/kernel_time_spec.rb