Created
June 29, 2018 15:40
-
-
Save npezza93/9a1b1839e4f09ae7a802659b6baf751d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
months = [1,2,3,4,5,6,7,9,10,11,12].to_a.map { |month| Date.new(2018, month) } | |
months = months.map { |month| month..month.end_of_month } | |
months.inject([]) do |array, month| | |
if array.present? && array.last.last + 1.day == month.first | |
array.push(array.pop.first..month.last) | |
else | |
array.push(month) | |
end | |
end.map do |range| | |
[range.first.strftime("%b '%y"), range.last.beginning_of_month.strftime("%b '%y")].join(" - ") | |
end.join(" and ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment