Created
February 29, 2024 04:36
-
-
Save tigris/29b9ca64c63a7a73ae0f8526fc698bf4 to your computer and use it in GitHub Desktop.
Ruby DateTime#next_year on leap days
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
#!/usr/bin/env ruby | |
require 'date' | |
now = DateTime.now | |
yesterday = now - 1 | |
puts "Now: #{now}" | |
puts "Yesterday: #{yesterday}" | |
puts "======" | |
one_year_from_now = now.next_year | |
one_year_from_yesterday = yesterday.next_year | |
puts "Now + 1.year: #{one_year_from_now}" | |
puts "Yesterday + 1.year: #{one_year_from_yesterday}" | |
puts "======" | |
puts "Equal? #{one_year_from_now == one_year_from_yesterday}" |
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
Now: 2024-02-29T15:34:50+11:00 | |
Yesterday: 2024-02-28T15:34:50+11:00 | |
====== | |
Now + 1.year: 2025-02-28T15:34:50+11:00 | |
Yesterday + 1.year: 2025-02-28T15:34:50+11:00 | |
====== | |
Equal? true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment