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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/time_ago.rb +81 -43
  3. metadata +40 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 344f1a3b780de59d28c4104a8c0074ee10058de453b4b1e3bf12ab529dfe7f95
4
- data.tar.gz: 3c90ac591b0d2bd2eadd41f24bbce7a039bb71c0fefb09ff615d96b0946763cc
3
+ metadata.gz: b9a2dd4696d98518d61a94d6c8e72ef58b7c6edadb1fab6fefe0c525dc255c45
4
+ data.tar.gz: e25a517657093806dab6c83303309f4f5fabcf7b4dbc10619fd2225c582417d7
5
5
  SHA512:
6
- metadata.gz: dc011d5771a93426bbc37093f17b1d4a545f3ca38e96b32239e4b1e258617db272a750da7d3c564ba9edc255e4d8d59c34adb5d70a25e3384c3b3dc6b2ceb169
7
- data.tar.gz: 0bb5caf2f2121c4b9a85b3405c9c71970f96c04ae157f4d9b22ed5b246bb090ce29c05f29f08d3ec2fa3e0c507b3d33529274dfeccba39a63d4d0419b0ed7480
6
+ metadata.gz: 18f95e28b2b6176d0aa6aa0059a1221d232664b41e48713d49588660b1e02c301c235fe75d4fe012e8bc85eff22bd0a4666ac061f4aa5890dd54e7d7d7dfb1f4
7
+ data.tar.gz: 5eb0be7451312bdcc292c4cc782542fc4c69a1f218cb0cf3496f520bbd887cdf809daeae6a94ca7037f3d28aa329fbd3a6681ac4c9f6168228c1049ee7aec4a0
data/lib/time_ago.rb CHANGED
@@ -1,45 +1,83 @@
1
- class TimeAgo
2
- def initialize
3
- @now = Time.now
4
- end
5
-
6
- def time_ago
7
- time = ""
8
- if @now.sec === 0
9
- time = "just now"
10
- elsif @now.sec < 60
11
- time = @now.sec.to_s + " s ago"
12
- elsif @now.min === 0
13
- time = @now.hour.to_s + " h ago"
14
- elsif @now.min < 60
15
- time = @now.min.to_s + " m ago"
16
- elsif @now.hour === 0
17
- time = "today at " + @now.hour.to_s + ":" + @now.min.to_s
18
- elsif @now.hour < 24
19
- time = @now.hour.to_s + " hrs ago"
20
- elsif @now.day === 0
21
- time = "yesterday at " + @now.hour.to_s + ":" + @now.min.to_s
22
- elsif @now.day === 1
23
- time = "Monday at " + @now.hour.to_s + ":" + @now.min.to_s
24
- elsif @now.day === 2
25
- time = "Tuesday at " + @now.hour.to_s + ":" + @now.min.to_s
26
- elsif @now.day === 3
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))
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
- # created = TimeAgo.new
45
- # created.time_ago
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
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: 2022-04-11 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Rendering time in words, e.g. 'just now', '1 minute ago', '2 hours ago',
14
- etc.
15
- email: webster@simplyvirtual.io
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/hola
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.2.3
41
- signing_key:
68
+ rubygems_version: 3.4.13
69
+ signing_key:
42
70
  specification_version: 4
43
- summary: Rendering time in words
71
+ summary: Localized relative date/time formatting gem
44
72
  test_files: []