Skip to content

Instantly share code, notes, and snippets.

@bburdiliak
Last active November 21, 2020 00:16
Show Gist options
  • Save bburdiliak/42498f290e8ee812ededbd92659355bd to your computer and use it in GitHub Desktop.
Save bburdiliak/42498f290e8ee812ededbd92659355bd to your computer and use it in GitHub Desktop.
Date range formatter without duplicity
# 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
@chibuezeayogu
Copy link

Nice one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment