Created
August 16, 2017 02:51
-
-
Save dagezi/ad8995624e1358508f34bc716aa7eada to your computer and use it in GitHub Desktop.
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
# Trivial example: 2017-01-01 is part of the last week of 2016 because ISO week starts with the Monday. | |
irb(main):004:0> fd2017 = Date.new(2017,1,1) | |
=> #<Date: 2017-01-01 ((2457755j,0s,0n),+0s,2299161j)> | |
irb(main):005:0> fd2017.cweek | |
=> 52 | |
irb(main):006:0> fd2017.cwday | |
=> 7 # Sunday | |
irb(main):007:0> fd2017.cwyear | |
=> 2016 | |
# What if the years with Tuesday? | |
irb(main):008:0> fd2019 = Date.new(2019,1,1) | |
=> #<Date: 2019-01-01 ((2458485j,0s,0n),+0s,2299161j)> | |
irb(main):009:0> fd2019.cwyear | |
=> 2019 # It's already in 2019!! | |
irb(main):010:0> fd2019.cwday | |
=> 2 # Tuesday | |
# Then how about the last day of 2018? | |
irb(main):011:0> ld2018 = Date.new(2018,12,31) | |
==> #<Date: 2018-12-31 ((2458484j,0s,0n),+0s,2299161j)> | |
irb(main):012:0> ld2018.cwday | |
=> 1 # Monday | |
irb(main):013:0> ld2018.cwyear | |
=> 2019 # Already in 2019!! | |
irb(main):014:0> ld2018.cweek | |
=> 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment