Created
March 25, 2019 20:08
-
-
Save Fedcomp/a40977fb1635e1f1b8bf9e1204775682 to your computer and use it in GitHub Desktop.
age difference
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
require 'pry-byebug' | |
require 'active_support/all' | |
dates = { | |
"a" => "10.01.2000", | |
"b" => "15.02.2000", | |
} | |
def seconds_to_units(seconds) | |
'%d days, %d hours, %d minutes, %d seconds' % | |
# the .reverse lets us put the larger units first for readability | |
[24,60,60].reverse.inject([seconds]) {|result, unitsize| | |
result[0,0] = result.shift.divmod(unitsize) | |
result | |
} | |
end | |
dates.to_a.combination(2).to_a.each do |(left_nick, left_date), (right_nick, right_date)| | |
left_date = Time.parse(left_date).to_i | |
right_date = Time.parse(right_date).to_i | |
difference = (left_date - right_date).abs | |
text_difference = seconds_to_units(difference) | |
puts "Разница между #{left_nick} и #{right_nick} составляет #{text_difference}" | |
end |
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
# frozen_string_literal: true | |
source "https://rubygems.org" | |
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } | |
# gem "rails" | |
gem 'rails', '~> 5.0' | |
gem 'pry-byebug' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment