Sha256: 5ca340a831ef0a10bd10c270d1b16deac83ae2a7411661a161684941d9d54713

Contents?: true

Size: 1.39 KB

Versions: 39

Compression:

Stored size: 1.39 KB

Contents

module Chronic
  class RepeaterSeasonName < RepeaterSeason #:nodoc:
    SEASON_SECONDS = 7_862_400 # 91 * 24 * 60 * 60
    DAY_SECONDS = 86_400 # (24 * 60 * 60)

    def next(pointer)
      direction = pointer == :future ? 1 : -1
      find_next_season_span(direction, @type)
    end

    def this(pointer = :future)
      direction = pointer == :future ? 1 : -1

      today = Chronic.construct(@now.year, @now.month, @now.day)
      goal_ssn_start = today + direction * num_seconds_til_start(@type, direction)
      goal_ssn_end = today + direction * num_seconds_til_end(@type, direction)
      curr_ssn = find_current_season(MiniDate.from_time(@now))
      case pointer
      when :past
        this_ssn_start = goal_ssn_start
        this_ssn_end = (curr_ssn == @type) ? today : goal_ssn_end
      when :future
        this_ssn_start = (curr_ssn == @type) ? today + RepeaterDay::DAY_SECONDS : goal_ssn_start
        this_ssn_end = goal_ssn_end
      when :none
        this_ssn_start = goal_ssn_start
        this_ssn_end = goal_ssn_end
      end

      construct_season(this_ssn_start, this_ssn_end)
    end

    def offset(span, amount, pointer)
      Span.new(offset_by(span.begin, amount, pointer), offset_by(span.end, amount, pointer))
    end

    def offset_by(time, amount, pointer)
      direction = pointer == :future ? 1 : -1
      time + amount * direction * RepeaterYear::YEAR_SECONDS
    end

  end
end

Version data entries

39 entries across 39 versions & 7 rubygems

Version Path
gitlab-chronic-0.10.6 lib/chronic/repeaters/repeater_season_name.rb
gitlab-chronic-0.10.5 lib/chronic/repeaters/repeater_season_name.rb
gitlab-chronic-0.10.4 lib/chronic/repeaters/repeater_season_name.rb
gitlab-chronic-0.10.3 lib/chronic/repeaters/repeater_season_name.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/chronic-0.10.2/lib/chronic/repeaters/repeater_season_name.rb
chronic-mmlac-0.6.4.2 lib/chronic/repeaters/repeater_season_name.rb
chronic-mmlac-0.10.2.1 lib/chronic/repeaters/repeater_season_name.rb
chronic-0.10.2 lib/chronic/repeaters/repeater_season_name.rb
chronic-0.10.1 lib/chronic/repeaters/repeater_season_name.rb
chronic-0.10.0 lib/chronic/repeaters/repeater_season_name.rb
chronic-0.9.1 lib/chronic/repeaters/repeater_season_name.rb
chronic-0.9.0 lib/chronic/repeaters/repeater_season_name.rb
Hokkaido-0.1.5 chronic/lib/chronic/repeaters/repeater_season_name.rb
Hokkaido-0.1.4 chronic/lib/chronic/repeaters/repeater_season_name.rb
Hokkaido-0.1.3 chronic/lib/chronic/repeaters/repeater_season_name.rb
Hokkaido-0.1.2 chronic/lib/chronic/repeaters/repeater_season_name.rb
Hokkaido-0.1.1 chronic/lib/chronic/repeaters/repeater_season_name.rb
Hokkaido-0.1.0 chronic/lib/chronic/repeaters/repeater_season_name.rb
Hokkaido-0.0.9 chronic/lib/chronic/repeaters/repeater_season_name.rb
Hokkaido-0.0.6 chronic/lib/chronic/repeaters/repeater_season_name.rb