Created
March 11, 2019 06:47
-
-
Save piharpi/a5cee9e522966f7e501f34dacf6b9a7a to your computer and use it in GitHub Desktop.
This find day of year by number
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
start_of_year = Time.new(2016, 1, 1) | |
# p start_of_year | |
# p start_of_year - 180 # second | |
# p start_of_year - (60 * 60 * 24) | |
def find_day_of_year_by_number(number) | |
current_date = Time.new(2016, 1, 1) | |
one_day = 60 * 60 * 24 | |
until current_date.yday == number | |
current_date += one_day | |
end | |
current_date | |
end | |
p find_day_of_year_by_number(150) | |
p find_day_of_year_by_number(1) | |
p find_day_of_year_by_number(150) | |
p find_day_of_year_by_number(150) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment