Last active
November 21, 2020 00:16
-
-
Save bburdiliak/42498f290e8ee812ededbd92659355bd to your computer and use it in GitHub Desktop.
Date range formatter without duplicity
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
# Takes in: 29/09/20 - 29/09/20 | |
# Outputs: 2020-09-28 18:00:00..2020-09-29 17:59:59.999999 | |
def add_time_to_date(date) | |
date_from, date_to = date.split(' - ').map { |d| Time.parse(convert_date_format(d)) } | |
date_from.beginning_of_day.to_datetime..date_to.end_of_day.to_datetime | |
end | |
def convert_date_format(value) | |
return DateTime.strptime(value, '%d/%m/%y').strftime("%Y-%m-%d") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice one.