Created
June 18, 2011 14:16
-
-
Save CobyR/1033128 to your computer and use it in GitHub Desktop.
file to populate day thoughts under month thought in PersonalBrain
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
require 'date' | |
class Time | |
# Returns a new Time, +years+ later than this time. Feb 29 of a | |
# leap year will be rounded up to Mar 1 if the target date is not a leap | |
# year. | |
def plus_year(years) | |
Time.local(year + years, month, day, hour, min, sec, usec) | |
end | |
# Returns a new Time, +months+ later than this time. The day will be | |
# rounded down if it is not valid for that month. | |
# 31 plus 1 month will be on Feb 28! | |
def plus_month(months) | |
d = Date.new(year, month, day) | |
d >>= months | |
Time.local(d.year, d.month, d.day, hour, min, sec, usec) | |
end | |
# Returns a new Time, +days+ later than this time. | |
# Does this do as I expect over DST? What if the hour doesn't exist | |
# in the next day, due to DST changes? | |
def plus_day(days) | |
d = Date.new(year, month, day) | |
d += days | |
Time.local(d.year, d.month, d.day, hour, min, sec, usec) | |
end | |
end | |
puts 'Enter the Month you want the date string for:' | |
month = gets | |
puts 'Enter the Year you want the date string for:' | |
year = gets | |
temp_date = Date.parse(year.chomp + "-" + month.chomp + "-1") | |
start_date =Time.local(temp_date.year, temp_date.month, temp_date.day) | |
puts start_date.strftime('%Y, (%m) %B, %d, %A') | |
end_date = start_date.plus_month(1).plus_day(-1) | |
puts end_date.strftime('%Y, (%m) %B, %d, %A') | |
puts "Press Enter to begin" | |
a = gets | |
start_loop = Date.parse(start_date.year.to_s + "-" + start_date.month.to_s + "-" + start_date.day.to_s) | |
end_loop = Date.parse(end_date.year.to_s + "-" + end_date.month.to_s + "-" + end_date.day.to_s) | |
output = "" | |
x=0 | |
(start_loop..end_loop).each do | current | | |
x+=1 | |
output += current.strftime('%Y, (%m) %B, %d, %A') + ";" | |
puts x | |
end | |
puts output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment