Sha256: 9be3ffefae729cdc188bc1fec83e852e5c25deda9e56844f5dd30391246b8e22

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

describe Time do

  describe 'weekend' do

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

  describe 'fortnight' do

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

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

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

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

  describe 'calendar_month' do

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

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

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

Version data entries

2 entries across 2 versions & 1 rubygems

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