a_moment_ago 1.1.4 → 1.1.5
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 +4 -4
- data/lib/locales/en.yml +14 -0
- data/lib/time_ago.rb +37 -43
- metadata +27 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a792ffaa8445ffe070a75deed346de34e1da6089a6bcb2a310ee8ea6d65f11c
|
4
|
+
data.tar.gz: 74834ab399dfdf547836b660ada9d144b8c5490939b0dcdeaa411128ea4da88e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe0dabfd50e598d14a81911e17688cb236d1cd278db4a8b10a66bafa67c29924baf4ee6409f6db4c0e66c40beac21cd057efecddc801f08b6f6a0aaa9bff5fa0
|
7
|
+
data.tar.gz: 8ef97d1ab9cfcc54ce672e307629f8cefbe1500caa04079bf42032b99fee07687a0293aefd285b60ae696c75bf68ba60477ec3e6df64e3ccc8c7ffa47103ac1d
|
data/lib/locales/en.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
en:
|
2
|
+
time_ago:
|
3
|
+
just_now: "just now"
|
4
|
+
seconds_ago:
|
5
|
+
one: "1 second ago"
|
6
|
+
other: "%{count} seconds ago"
|
7
|
+
minutes_ago:
|
8
|
+
one: "1 minute ago"
|
9
|
+
other: "%{count} minutes ago"
|
10
|
+
hours_ago:
|
11
|
+
one: "1 hour ago"
|
12
|
+
other: "%{count} hours ago"
|
13
|
+
yesterday_at: "Yesterday at %{time}"
|
14
|
+
other: "%{time}"
|
data/lib/time_ago.rb
CHANGED
@@ -1,45 +1,39 @@
|
|
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
|
-
time = "Wednesday at " + @now.hour.to_s + ":" + @now.min.to_s
|
28
|
-
elsif @now.day === 4
|
29
|
-
time = "Thursday at " + @now.hour.to_s + ":" + @now.min.to_s
|
30
|
-
elsif @now.day === 5
|
31
|
-
time = "Friday at " + @now.hour.to_s + ":" + @now.min.to_s
|
32
|
-
elsif @now.day === 6
|
33
|
-
time = "Saturday at " + @now.hour.to_s + ":" + @now.min.to_s
|
34
|
-
elsif @now.day === 7
|
35
|
-
time = "Sunday at " + @now.hour.to_s + ":" + @now.min.to_s
|
36
|
-
else
|
37
|
-
time = "on " + @now.strftime("%A") + " at " + @now.hour.to_s + ":" + @now.min.to_s
|
38
|
-
end
|
39
|
-
|
40
|
-
puts "#{time}"
|
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))
|
41
27
|
end
|
42
28
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
metadata
CHANGED
@@ -1,28 +1,43 @@
|
|
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.5
|
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
|
+
description: A gem that formats time intervals as relative dates in Ruby/Rails
|
28
|
+
email:
|
29
|
+
- webster@webstercodes.com
|
16
30
|
executables: []
|
17
31
|
extensions: []
|
18
32
|
extra_rdoc_files: []
|
19
33
|
files:
|
34
|
+
- lib/locales/en.yml
|
20
35
|
- lib/time_ago.rb
|
21
|
-
homepage: https://rubygems.org/gems/
|
36
|
+
homepage: https://rubygems.org/gems/a_moment_ago
|
22
37
|
licenses:
|
23
38
|
- MIT
|
24
39
|
metadata: {}
|
25
|
-
post_install_message:
|
40
|
+
post_install_message:
|
26
41
|
rdoc_options: []
|
27
42
|
require_paths:
|
28
43
|
- lib
|
@@ -37,8 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
52
|
- !ruby/object:Gem::Version
|
38
53
|
version: '0'
|
39
54
|
requirements: []
|
40
|
-
rubygems_version: 3.
|
41
|
-
signing_key:
|
55
|
+
rubygems_version: 3.4.13
|
56
|
+
signing_key:
|
42
57
|
specification_version: 4
|
43
|
-
summary:
|
58
|
+
summary: Localized relative date/time formatting gem
|
44
59
|
test_files: []
|