Skip to content

Instantly share code, notes, and snippets.

@alterisian
Created June 5, 2011 18:32
Show Gist options
  • Select an option

  • Save alterisian/1009253 to your computer and use it in GitHub Desktop.

Select an option

Save alterisian/1009253 to your computer and use it in GitHub Desktop.

Revisions

  1. Ian M revised this gist Jun 6, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion weekends.rb
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # ruby script/runner lib\weekends.rb

    # Returns parameter from_date if it is a Friday.
    def next_friday(from_date)
    def next_friday( from_date )
    while from_date.cwday!=5
    from_date = from_date + 1.day
    end
  2. Ian M revised this gist Jun 6, 2011. 1 changed file with 28 additions and 27 deletions.
    55 changes: 28 additions & 27 deletions weekends.rb
    Original file line number Diff line number Diff line change
    @@ -1,34 +1,35 @@
    #Author: Ian Moss aka oceanician : http://twitter.com/oceanician
    #First Published: https://gist.github.com/1009253
    #I'm running as part of a rails project with:
    # ruby script/runner lib\weekends.rb

    def next_friday(d)
    while d.cwday!=5
    d = d+1.day
    end
    d
    end
    # Returns parameter from_date if it is a Friday.
    def next_friday(from_date)
    while from_date.cwday!=5
    from_date = from_date + 1.day
    end
    from_date
    end

    def weekends_til( end_date )
    weekends = []
    def weekends_til( end_date )
    weekends = []
    friday_count = next_friday( Date.today )
    while( friday_count <= end_date )
    weekends << friday_count
    friday_count = friday_count + 7.days
    end

    friday_count = next_friday( Date.today )

    while ( friday_count <= end_date )
    weekends << friday_count
    friday_count = friday_count + 7.days
    end

    weekends
    end
    weekends
    end

    #calculate all the weekends from now, until the middle of September.
    #I'm running as part of a rails project with:
    # ruby script/runner lib\weekends.rb
    #future = Date.today + 5.months + 3.weeks
    #calculate all the weekends from now, until the middle of September.
    #I'm running as part of a rails project with:
    # ruby script/runner lib\weekends.rb
    #future = Date.today + 5.months + 3.weeks

    future = Date.civil(y=2011, m=9, d=21)
    weekends=weekends_til(future)
    puts "Make the most of the next #{weekends.size} weekends until, "+future.to_s(:long)
    weekends.each{|w| puts "From: Fri "+w.to_s+" to Sun " +(w+3.days).to_s}
    # Notionally decided 21st September is the end of Summer!
    future = Date.civil(y=2011, m=9, d=21)
    weekends=weekends_til(future)

    puts "Make the most of the next #{weekends.size} weekends until, "+future.to_s(:long)
    weekends.each{|w| puts "From: Fri "+w.to_s+" to Sun " +(w+3.days).to_s}
  3. Ian M revised this gist Jun 5, 2011. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions weekends.rb
    Original file line number Diff line number Diff line change
    @@ -8,16 +8,14 @@ def next_friday(d)
    d
    end

    def weekends_til(d)
    def weekends_til( end_date )
    weekends = []

    next_friday = next_friday( Date.today )
    friday_count = next_friday( Date.today )

    n = next_friday

    while ( n <= d )
    weekends << n
    n=n+7.days
    while ( friday_count <= end_date )
    weekends << friday_count
    friday_count = friday_count + 7.days
    end

    weekends
  4. Ian M revised this gist Jun 5, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions weekends.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #Author: Ian Moss aka oceanician : http://twitter.com/oceanician
    #First Published: https://gist.github.com/1009253

    def next_friday(d)
    while d.cwday!=5
  5. Ian M created this gist Jun 5, 2011.
    34 changes: 34 additions & 0 deletions weekends.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@

    def next_friday(d)
    while d.cwday!=5
    d = d+1.day
    end
    d
    end

    def weekends_til(d)
    weekends = []

    next_friday = next_friday( Date.today )

    n = next_friday

    while ( n <= d )
    weekends << n
    n=n+7.days
    end

    weekends
    end

    #calculate all the weekends from now, until the middle of September.
    #I'm running as part of a rails project with:
    # ruby script/runner lib\weekends.rb
    #future = Date.today + 5.months + 3.weeks

    future = Date.civil(y=2011, m=9, d=21)
    weekends=weekends_til(future)
    puts "Make the most of the next #{weekends.size} weekends until, "+future.to_s(:long)
    weekends.each{|w| puts "From: Fri "+w.to_s+" to Sun " +(w+3.days).to_s}