a_moment_ago 1.1.4 → 1.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/time_ago.rb +81 -43
- metadata +40 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9a2dd4696d98518d61a94d6c8e72ef58b7c6edadb1fab6fefe0c525dc255c45
|
4
|
+
data.tar.gz: e25a517657093806dab6c83303309f4f5fabcf7b4dbc10619fd2225c582417d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18f95e28b2b6176d0aa6aa0059a1221d232664b41e48713d49588660b1e02c301c235fe75d4fe012e8bc85eff22bd0a4666ac061f4aa5890dd54e7d7d7dfb1f4
|
7
|
+
data.tar.gz: 5eb0be7451312bdcc292c4cc782542fc4c69a1f218cb0cf3496f520bbd887cdf809daeae6a94ca7037f3d28aa329fbd3a6681ac4c9f6168228c1049ee7aec4a0
|
data/lib/time_ago.rb
CHANGED
@@ -1,45 +1,83 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
1
|
+
# require "i18n"
|
2
|
+
|
3
|
+
# module TimeAgo
|
4
|
+
# DEFAULT_LOCALE = :en
|
5
|
+
|
6
|
+
# def self.format(time, locale: DEFAULT_LOCALE)
|
7
|
+
# I18n.load_path << Dir[File.expand_path("locales/*.yml", __dir__)]
|
8
|
+
# I18n.default_locale = DEFAULT_LOCALE
|
9
|
+
# I18n.locale = locale
|
10
|
+
|
11
|
+
# distance_in_seconds = (Time.current - time).to_i
|
12
|
+
|
13
|
+
# if distance_in_seconds < 5
|
14
|
+
# I18n.t("time_ago.just_now")
|
15
|
+
# elsif distance_in_seconds < 60
|
16
|
+
# I18n.t("time_ago.seconds_ago", count: distance_in_seconds)
|
17
|
+
# elsif distance_in_seconds < 3600
|
18
|
+
# minutes_ago = (distance_in_seconds / 60).to_i
|
19
|
+
# I18n.t("time_ago.minutes_ago", count: minutes_ago)
|
20
|
+
# elsif distance_in_seconds < 86400
|
21
|
+
# hours_ago = (distance_in_seconds / 3600).to_i
|
22
|
+
# I18n.t("time_ago.hours_ago", count: hours_ago)
|
23
|
+
# elsif distance_in_seconds < 172_800
|
24
|
+
# I18n.t("time_ago.yesterday_at", time: I18n.l(time, format: :time))
|
25
|
+
# else
|
26
|
+
# I18n.t("time_ago.other", time: I18n.l(time, format: :short))
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
|
31
|
+
# class Time
|
32
|
+
# def self.localized_format(time, locale: TimeAgo::DEFAULT_LOCALE)
|
33
|
+
# TimeAgo.format(time, locale: locale)
|
34
|
+
# end
|
35
|
+
|
36
|
+
# def ago(locale: TimeAgo::DEFAULT_LOCALE)
|
37
|
+
# TimeAgo.format(self, locale: locale)
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
require "i18n"
|
44
|
+
require "active_support/time"
|
45
|
+
|
46
|
+
module TimeAgo
|
47
|
+
DEFAULT_LOCALE = :en
|
48
|
+
|
49
|
+
def self.format(time, locale: DEFAULT_LOCALE)
|
50
|
+
I18n.load_path << Dir[File.expand_path("locales/*.yml", __dir__)]
|
51
|
+
I18n.default_locale = DEFAULT_LOCALE
|
52
|
+
I18n.locale = locale
|
53
|
+
|
54
|
+
distance_in_seconds = (Time.current - time).to_i
|
55
|
+
|
56
|
+
if distance_in_seconds < 5
|
57
|
+
I18n.t("time_ago.just_now")
|
58
|
+
elsif distance_in_seconds < 60
|
59
|
+
I18n.t("time_ago.seconds_ago", count: distance_in_seconds)
|
60
|
+
elsif distance_in_seconds < 3600
|
61
|
+
minutes_ago = (distance_in_seconds / 60).to_i
|
62
|
+
I18n.t("time_ago.minutes_ago", count: minutes_ago)
|
63
|
+
elsif distance_in_seconds < 86400
|
64
|
+
hours_ago = (distance_in_seconds / 3600).to_i
|
65
|
+
I18n.t("time_ago.hours_ago", count: hours_ago)
|
66
|
+
elsif distance_in_seconds < 172_800
|
67
|
+
I18n.t("time_ago.yesterday_at", time: I18n.l(time, format: :time))
|
68
|
+
else
|
69
|
+
I18n.t("time_ago.other", time: I18n.l(time, format: :short))
|
41
70
|
end
|
42
71
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
72
|
+
end
|
73
|
+
|
74
|
+
class Time
|
75
|
+
def self.localized_format(time, locale: TimeAgo::DEFAULT_LOCALE)
|
76
|
+
TimeAgo::format(time, locale: locale)
|
77
|
+
end
|
78
|
+
|
79
|
+
def ago(locale: TimeAgo::DEFAULT_LOCALE)
|
80
|
+
TimeAgo::format(self, locale: locale)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
metadata
CHANGED
@@ -1,28 +1,56 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a_moment_ago
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Webster Avosa
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
date: 2023-06-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A gem that formats time intervals as relative dates in Ruby/Rails
|
42
|
+
email:
|
43
|
+
- webster@webstercodes.com
|
16
44
|
executables: []
|
17
45
|
extensions: []
|
18
46
|
extra_rdoc_files: []
|
19
47
|
files:
|
20
48
|
- lib/time_ago.rb
|
21
|
-
homepage: https://rubygems.org/gems/
|
49
|
+
homepage: https://rubygems.org/gems/a_moment_ago
|
22
50
|
licenses:
|
23
51
|
- MIT
|
24
52
|
metadata: {}
|
25
|
-
post_install_message:
|
53
|
+
post_install_message:
|
26
54
|
rdoc_options: []
|
27
55
|
require_paths:
|
28
56
|
- lib
|
@@ -37,8 +65,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
65
|
- !ruby/object:Gem::Version
|
38
66
|
version: '0'
|
39
67
|
requirements: []
|
40
|
-
rubygems_version: 3.
|
41
|
-
signing_key:
|
68
|
+
rubygems_version: 3.4.13
|
69
|
+
signing_key:
|
42
70
|
specification_version: 4
|
43
|
-
summary:
|
71
|
+
summary: Localized relative date/time formatting gem
|
44
72
|
test_files: []
|