time_duration_humanizer 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/README.md +1 -1
- data/lib/time_duration_humanizer/version.rb +1 -1
- data/lib/time_duration_humanizer.rb +15 -7
- data/time_duration_humanizer.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9ea67a4041178b0a9d2e17f55f53b9ca04e8fa6
|
4
|
+
data.tar.gz: 5174c75e85618f1c997978db790f402efb0ce9df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65789569eeb769d3ffe6ee4a5155b338d083a5364d5535dba54eeaa5881b328157712feca25a9522d3b7adfdb230f4d053293d3c778fdd3c46569d129ef0f610
|
7
|
+
data.tar.gz: e29a7baa0d550aef8b3d2286396d5207c3d4aa140847ffee0643c5fcaa176ac334d4f72a9fd8782edfd4e4080427da1acb692ef760da83525ccdb5a8c8b930f8
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -45,7 +45,7 @@ irb(main):006:0> TimeDurationHumanizer.humanize(62208000, { days_in_year: 360 })
|
|
45
45
|
## Options (second parameter)
|
46
46
|
|
47
47
|
* and_at_end - default `true`
|
48
|
-
* days_in_year - default `
|
48
|
+
* days_in_year - default `365.25`
|
49
49
|
|
50
50
|
## Units (third parameter)
|
51
51
|
|
@@ -1,13 +1,21 @@
|
|
1
1
|
require "time_duration_humanizer/version"
|
2
2
|
|
3
3
|
module TimeDurationHumanizer
|
4
|
-
@@
|
4
|
+
@@units = {
|
5
|
+
years: 31557600,
|
6
|
+
months: 2592000,
|
7
|
+
weeks: 604800,
|
8
|
+
days: 86400,
|
9
|
+
hours: 3600,
|
10
|
+
minutes: 60,
|
11
|
+
seconds: 1
|
12
|
+
}
|
5
13
|
|
6
14
|
def self.humanize(seconds, options = {}, units = {})
|
7
15
|
options = {
|
8
16
|
and_at_end: true,
|
9
|
-
days_in_year:
|
10
|
-
}.merge!(options
|
17
|
+
days_in_year: 365.25
|
18
|
+
}.merge!(options)
|
11
19
|
|
12
20
|
units = {
|
13
21
|
years: true,
|
@@ -17,14 +25,14 @@ module TimeDurationHumanizer
|
|
17
25
|
hours: true,
|
18
26
|
minutes: true,
|
19
27
|
seconds: true
|
20
|
-
}.merge!(units
|
28
|
+
}.merge!(units)
|
21
29
|
|
22
30
|
values = []
|
23
31
|
duration = ''
|
24
32
|
|
25
33
|
units.each do |k, v|
|
26
|
-
if v == true && @@
|
27
|
-
u =
|
34
|
+
if v == true && @@units.keys.include?(k)
|
35
|
+
u = k == :years ? (options[:days_in_year] * @@units[:days]).to_i : @@units[k]
|
28
36
|
value = seconds >= u ? seconds / u : 0
|
29
37
|
if value > 0
|
30
38
|
values << { name: k.to_s, value: value }
|
@@ -36,7 +44,7 @@ module TimeDurationHumanizer
|
|
36
44
|
l = values.length
|
37
45
|
values.each_with_index do |v, i|
|
38
46
|
separator = i == l - 1 ? '' : (i == l - 2 && options[:and_at_end] == true ? " #{I18n.t('time_duration_humanizer.and')} " : ', ')
|
39
|
-
duration += "#{v[:value]} #{I18n.t("time_duration_humanizer.#{v[:value] == 1 ? v[:name].
|
47
|
+
duration += "#{v[:value]} #{I18n.t("time_duration_humanizer.#{v[:value] == 1 ? v[:name].chop : v[:name]}")}#{separator}"
|
40
48
|
end
|
41
49
|
|
42
50
|
duration
|
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Nikolay Digaev"]
|
10
10
|
spec.email = ["ffs.cmp@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{A Ruby gem for converting seconds into human-readable format.}
|
13
|
+
spec.description = %q{A Ruby gem for converting seconds into human-readable format (12345 => "3 hours, 25 minutes and 45 seconds").}
|
14
14
|
spec.homepage = "https://github.com/digaev/time_duration_humanier"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_duration_humanizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikolay Digaev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,8 +38,8 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description:
|
42
|
-
|
41
|
+
description: A Ruby gem for converting seconds into human-readable format (12345 =>
|
42
|
+
"3 hours, 25 minutes and 45 seconds").
|
43
43
|
email:
|
44
44
|
- ffs.cmp@gmail.com
|
45
45
|
executables: []
|
@@ -80,5 +80,5 @@ rubyforge_project:
|
|
80
80
|
rubygems_version: 2.4.5.1
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
|
-
summary:
|
83
|
+
summary: A Ruby gem for converting seconds into human-readable format.
|
84
84
|
test_files: []
|