Skip to content

Instantly share code, notes, and snippets.

@piharpi
Created March 11, 2019 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piharpi/a5cee9e522966f7e501f34dacf6b9a7a to your computer and use it in GitHub Desktop.
Save piharpi/a5cee9e522966f7e501f34dacf6b9a7a to your computer and use it in GitHub Desktop.
This find day of year by number
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