How can i print morning if the Time.new is morning and afternoon if its afternoon
00:00 - 12:00
12:00 - 00:00
Another possibility if you will be doing this test a lot (not that I am advocating monkey patching at the drop of a hat):
class Time
def morning?
hour < 12
end
def afternoon?
hour >= 12
end
end
puts Time.now.morning? ? 'morning' : 'afternoon'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With