time_calculator 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/time_calculator.rb +30 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 235440ea54cc22ccacbb794623279d28f06772471c96340c463fc2b8a8cb8921
|
4
|
+
data.tar.gz: 174d3d9e41f1c4371da28723bc2fdbffc0fbfad94380e08c0ce4ecadecacec4f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aca1b0add4211b69c77f0b032f2fce833ead3a53f4754b68e13d5b43c82379e4a1c05a4ff3fc7a67732072b17ca31cf8bf300abd7e699f0ce84aa29c71f200b7
|
7
|
+
data.tar.gz: c74402a7ea20a5368bf1382fd83ee5099496a2a4eb898482bcd93382b34c4c837ad32214ced7fc9edd36c77a364f2111e586cce19971429c2e5cc9241afd80b1
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class TimeCalculator
|
2
|
+
def self.calculate(started_at)
|
3
|
+
time_diff = (Time.now - started_at)
|
4
|
+
minute_diff = (time_diff / 1.minute)
|
5
|
+
hour_diff = (time_diff / 1.hour)
|
6
|
+
day_diff = (time_diff / 1.day)
|
7
|
+
month_diff = (time_diff / 1.month)
|
8
|
+
year_diff = (time_diff / 1.year)
|
9
|
+
|
10
|
+
minute = minute_diff.round
|
11
|
+
hour = hour_diff.round
|
12
|
+
day = day_diff.round
|
13
|
+
month = month_diff.round
|
14
|
+
year = year_diff.round
|
15
|
+
if year_diff >= 1
|
16
|
+
time = "#{year} years ago."
|
17
|
+
elsif month_diff >= 1
|
18
|
+
time = "#{month} months ago."
|
19
|
+
elsif day_diff >= 1
|
20
|
+
time = "#{day} days ago."
|
21
|
+
elsif hour_diff >= 1
|
22
|
+
time = "#{hour} hours ago."
|
23
|
+
elsif minute_diff >= 1
|
24
|
+
time = "#{minute} minutes ago."
|
25
|
+
else
|
26
|
+
time = "#{t 'just_now'}"
|
27
|
+
end
|
28
|
+
return time
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: time_calculator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Prashant Vishwakarma
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem that calculates your time in terms of like '1 day ago' and '3 months
|
14
|
+
ago'
|
15
|
+
email: prashant.vishwakarma@clecotech.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/time_calculator.rb
|
21
|
+
homepage: https://rubygems.org/gems/time_calculator
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Calculate your time difference!
|
44
|
+
test_files: []
|