Created
August 27, 2012 03:13
-
-
Save oogali/3485239 to your computer and use it in GitHub Desktop.
crude date range in english
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'time' | |
def get_date_range(start_date, end_date) | |
start_ts = Time.parse start_date | |
end_ts = Time.parse end_date | |
if (start_ts > end_ts) | |
ts = start_ts | |
start_ts = end_ts | |
end_ts = ts | |
end | |
if start_ts.year != end_ts.year | |
return start_ts.strftime('%B %e, %Y') + ' to ' + end_ts.strftime('%B %e, %Y') | |
end | |
str = start_ts.strftime('%B ') | |
if start_ts.month == end_ts.month | |
str += start_ts.day.to_s + '-' + end_ts.day.to_s + ', ' + end_ts.year.to_s | |
else | |
str += start_ts.day.to_s + ' to ' + end_ts.strftime('%B %e, %Y') | |
end | |
str | |
end | |
start_date = '2012-07-01' | |
end_date = '2011-06-10' | |
puts get_date_range start_date, end_date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment