Skip to content

Instantly share code, notes, and snippets.

@Fedcomp
Created March 25, 2019 20:08
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 Fedcomp/a40977fb1635e1f1b8bf9e1204775682 to your computer and use it in GitHub Desktop.
Save Fedcomp/a40977fb1635e1f1b8bf9e1204775682 to your computer and use it in GitHub Desktop.
age difference
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
# 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