Created
September 5, 2011 04:48
-
-
Save alanjcfs/1194114 to your computer and use it in GitHub Desktop.
Will return the day of the year in a sentence form
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
t = Time.now | |
dayth = t.yday | |
last_digit = dayth.to_s.slice(-1, 1).to_i | |
def ordinal(last_digit) | |
case last_digit | |
when 1 | |
"st" | |
when 2 | |
"nd" | |
when 3 | |
"rd" | |
else | |
"th" | |
end | |
end | |
puts "It is the #{dayth}#{ordinal(last_digit)} day of the year." |
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
t = Time.now | |
dayth = t.yday | |
last_digit = dayth.to_s.slice(-1, 1).to_i | |
def ordinal(last_digit) | |
case last_digit | |
when 1 | |
"st" | |
when 2 | |
"nd" | |
when 3 | |
"rd" | |
else | |
"th" | |
end | |
end | |
puts "It is the #{dayth}#{ordinal(last_digit)} day of the year." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment