friendly_timestamp 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02edf86556a4bcb7776f8f0ecbd25a30cc6014f7
4
- data.tar.gz: c929fa8146cd75e18d50ab41fb4f1fefa80547bd
3
+ metadata.gz: cdcb9d0b247d5361e3eee9ba82f7ff206d910ff8
4
+ data.tar.gz: 95e3126958c0378bb7a4a28be6bfe5efee9cd811
5
5
  SHA512:
6
- metadata.gz: d83ed94c44eb65baea9c5fab40336d1930cdba995b880201cb48408c002276bae1f596f80bdf599352134aeb08515a52e2a78634bbe45248c76a86497f7a681e
7
- data.tar.gz: 436fbde96d214c89510f0649cee279b39a5893b53c173c61172eea1aec66606bdc9719dffd21001992e5799ff3cf94254c40b5900864fb160c4a71f6baa34ac9
6
+ metadata.gz: 6c200cb7ae34132a92e5e4de766adc3718476e40b951f449d6a9fab80524291018cafe12d1ab10aba582fdabd70a868bdd91f44e7041c87c782ed748f3121c51
7
+ data.tar.gz: 6d207d58865339e1156c2fe235f7bdc892371c6deaadd4393814615f02d2895a4fd757439f816692326a78efdad448d997f54f57c0bd97cccfa7256e61113dc0
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,74 +1,74 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at kuroun.seung@rackspace.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kuroun.seung@rackspace.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in friendly_timestamp.gemspec
4
- gem 'activesupport'
5
- gem 'rspec-rails', '3.5.2'
6
- gem 'rubocop'
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in friendly_timestamp.gemspec
4
+ gem 'activesupport'
5
+ gem 'rspec-rails', '3.5.2'
6
+ gem 'rubocop'
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016 Kuroun
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kuroun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -1,33 +1,33 @@
1
- var get_cookie, set_cookie;
2
-
3
- $(document).ready(function() {
4
- var d, n;
5
- d = new Date;
6
- n = d.getTimezoneOffset();
7
- return set_cookie('fts_offset', n, 30);
8
- });
9
-
10
- set_cookie = function(cname, cvalue, exdays) {
11
- var d;
12
- d = new Date;
13
- d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
14
- return document.cookie = cname + '=' + cvalue + ';expires=' + d.toUTCString() + ';path=/';
15
- };
16
-
17
- get_cookie = function(cname) {
18
- var c, ca, i, name;
19
- name = cname + '=';
20
- ca = document.cookie.split(';');
21
- i = 0;
22
- while (i < ca.length) {
23
- c = ca[i];
24
- while (c.charAt(0) === ' ') {
25
- c = c.substring(1);
26
- }
27
- if (c.indexOf(name) === 0) {
28
- return c.substring(name.length, c.length);
29
- }
30
- i++;
31
- }
32
- return '';
33
- };
1
+ var get_cookie, set_cookie;
2
+
3
+ $(document).ready(function() {
4
+ var d, n;
5
+ d = new Date;
6
+ n = d.getTimezoneOffset();
7
+ return set_cookie('fts_offset', n, 30);
8
+ });
9
+
10
+ set_cookie = function(cname, cvalue, exdays) {
11
+ var d;
12
+ d = new Date;
13
+ d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000);
14
+ return document.cookie = cname + '=' + cvalue + ';expires=' + d.toUTCString() + ';path=/';
15
+ };
16
+
17
+ get_cookie = function(cname) {
18
+ var c, ca, i, name;
19
+ name = cname + '=';
20
+ ca = document.cookie.split(';');
21
+ i = 0;
22
+ while (i < ca.length) {
23
+ c = ca[i];
24
+ while (c.charAt(0) === ' ') {
25
+ c = c.substring(1);
26
+ }
27
+ if (c.indexOf(name) === 0) {
28
+ return c.substring(name.length, c.length);
29
+ }
30
+ i++;
31
+ }
32
+ return '';
33
+ };
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "friendly_timestamp"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "friendly_timestamp"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,84 @@
1
+ module CoreExtensions
2
+ module Time
3
+ module FriendlyTimestamp
4
+ ONE_MINUTE = 60
5
+ ONE_HOUR = ONE_MINUTE * 60
6
+ ONE_DAY = ONE_HOUR * 24
7
+ ONE_WEEK = ONE_DAY * 7
8
+ ONE_MONTH = ONE_DAY * 30
9
+ ONE_YEAR = ONE_DAY * 365
10
+
11
+ def friendly_format
12
+ # convert time to local time
13
+ # using minute format if less hour
14
+ # using hour format if less than a day
15
+ # using full format otherwise (Thurs, Nov 12th 2016)
16
+ case (self.class.now - self).to_i.abs
17
+ when 0...ONE_MINUTE
18
+ 'a moment ago'
19
+ when ONE_MINUTE...ONE_HOUR
20
+ minute_format
21
+ when ONE_HOUR...ONE_DAY
22
+ hour_format
23
+ when ONE_DAY...ONE_WEEK
24
+ day_format
25
+ when ONE_WEEK...ONE_MONTH
26
+ week_format
27
+ when ONE_MONTH...ONE_YEAR
28
+ month_format
29
+ when ONE_YEAR...ONE_YEAR * 5
30
+ year_format
31
+ else
32
+ full_format
33
+ end
34
+ end
35
+
36
+ def minute_format
37
+ in_minutes = diff_utc / ONE_MINUTE
38
+ "#{word_form(in_minutes, 'minute')} ago"
39
+ end
40
+
41
+ def hour_format
42
+ in_hours = diff_utc / ONE_HOUR
43
+ "#{word_form(in_hours, 'hour')} ago"
44
+ end
45
+
46
+ def day_format
47
+ in_days = diff_utc / ONE_DAY
48
+ "#{word_form(in_days, 'day')} ago"
49
+ end
50
+
51
+ def week_format
52
+ in_weeks = diff_utc / ONE_WEEK
53
+ "#{word_form(in_weeks, 'week')} ago"
54
+ end
55
+
56
+ def month_format
57
+ in_months = diff_utc / ONE_MONTH
58
+ "#{word_form(in_months, 'month')} ago"
59
+ end
60
+
61
+ def year_format
62
+ in_years = diff_utc / ONE_YEAR
63
+ "#{word_form(in_years, 'year')} ago"
64
+ end
65
+
66
+ def full_format(mn_offset = 0)
67
+ # multiplle -1 here because js represent time difference varies from how rails represents
68
+ # get offset in hour
69
+ hour_offset = (-1 * mn_offset.to_f / 60)
70
+ fts_local_time = in_time_zone(hour_offset)
71
+ fts_local_time.strftime("%a, %b #{fts_local_time.day.ordinalize} %Y at %H:%M %Z")
72
+ end
73
+
74
+ def word_form(num, word)
75
+ word = num.round > 1 ? word.pluralize : word.singularize
76
+ num > num.round ? "more than #{num.round} #{word}" : "less than #{num.round} #{word}"
77
+ end
78
+
79
+ def diff_utc
80
+ (self.class.now - self).to_f.abs
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,86 +1,6 @@
1
- require 'friendly_timestamp/engine'
2
- require 'friendly_timestamp/version'
3
- require 'active_support/all'
4
-
5
- ONE_MINUTE = 60
6
- ONE_HOUR = ONE_MINUTE * 60
7
- ONE_DAY = ONE_HOUR * 24
8
- ONE_WEEK = ONE_DAY * 7
9
- ONE_MONTH = ONE_DAY * 30
10
- ONE_YEAR = ONE_DAY * 365
11
-
12
- class Time
13
- def friendly_format
14
- # convert time to local time
15
- # using minute format if less hour
16
- # using hour format if less than a day
17
- # using full format otherwise (Thurs, Nov 12th 2016)
18
- case (Time.now - self).to_i.abs
19
- when 0...ONE_MINUTE
20
- 'a moment ago'
21
- when ONE_MINUTE...ONE_HOUR
22
- minute_format
23
- when ONE_HOUR...ONE_DAY
24
- hour_format
25
- when ONE_DAY...ONE_WEEK
26
- day_format
27
- when ONE_WEEK...ONE_MONTH
28
- week_format
29
- when ONE_MONTH...ONE_YEAR
30
- month_format
31
- when ONE_YEAR...ONE_YEAR * 5
32
- year_format
33
- else
34
- full_format
35
- end
36
- end
37
-
38
- def minute_format
39
- in_minutes = diff_utc / ONE_MINUTE
40
- "#{word_form(in_minutes, 'minute')} ago"
41
- end
42
-
43
- def hour_format
44
- in_hours = diff_utc / ONE_HOUR
45
- "#{word_form(in_hours, 'hour')} ago"
46
- end
47
-
48
- def day_format
49
- in_days = diff_utc / ONE_DAY
50
- "#{word_form(in_days, 'day')} ago"
51
- end
52
-
53
- def week_format
54
- in_weeks = diff_utc / ONE_WEEK
55
- "#{word_form(in_weeks, 'week')} ago"
56
- end
57
-
58
- def month_format
59
- in_months = diff_utc / ONE_MONTH
60
- "#{word_form(in_months, 'month')} ago"
61
- end
62
-
63
- def year_format
64
- in_years = diff_utc / ONE_YEAR
65
- "#{word_form(in_years, 'year')} ago"
66
- end
67
-
68
- def full_format(mn_offset = 0)
69
- # multiplle -1 here because js represent time difference varies from how rails represents
70
- # get offset in hour
71
- hour_offset = (-1 * mn_offset.to_f / 60)
72
- fts_local_time = in_time_zone hour_offset
73
- fts_local_time.strftime("%a, %b #{fts_local_time.day.ordinalize} %Y at %H:%M %Z")
74
- end
75
-
76
- private
77
-
78
- def word_form(num, word)
79
- word = num.round > 1 ? word.pluralize : word.singularize
80
- num > num.round ? "more than #{num.round} #{word}" : "less than #{num.round} #{word}"
81
- end
82
-
83
- def diff_utc
84
- (Time.now - self).to_f.abs
85
- end
86
- end
1
+ require 'friendly_timestamp/engine'
2
+ require 'friendly_timestamp/version'
3
+ require 'core_extensions/time/friendly_timestamp'
4
+ require 'active_support/all'
5
+
6
+ Time.include CoreExtensions::Time::FriendlyTimestamp
@@ -1,5 +1,5 @@
1
- require 'rails/engine'
2
-
3
- module FriendlyTimestamp
4
- class Engine < Rails::Engine; end
5
- end
1
+ require 'rails/engine'
2
+
3
+ module FriendlyTimestamp
4
+ class Engine < Rails::Engine; end
5
+ end
@@ -1,3 +1,3 @@
1
- module FriendlyTimestamp
2
- VERSION = :'1.0.2'
3
- end
1
+ module FriendlyTimestamp
2
+ VERSION = :'1.0.3'
3
+ end
@@ -1,86 +1,86 @@
1
- require 'spec_helper'
2
-
3
- describe Time do
4
- it 'has a version number' do
5
- expect(FriendlyTimestamp::VERSION).not_to be nil
6
- end
7
-
8
- describe 'word_form' do
9
- # make sure that return more than or less than phrase
10
- # make sure that number is no decimal form
11
- # make sure that it returns appropriate singular and plural form of word
12
- word = 'minute'
13
- context 'when number after decimal point is equal or more than 5' do
14
- num = 1.5
15
- it 'is supposed to be rounded up' do
16
- expect(Time.now.send(:word_form, num, word)).to eq 'less than 2 minutes'
17
- end
18
- end
19
-
20
- context 'when number after decimal point is less than 5' do
21
- num = 1.4
22
- it 'is supposed to be rounded down' do
23
- expect(Time.now.send(:word_form, num, word)).to eq 'more than 1 minute'
24
- end
25
- end
26
- end
27
-
28
- describe '#friendly_format' do
29
- context 'when less than a minute' do
30
- time = Time.now - 30
31
- it 'returns string of moment ago' do
32
- expect(time.friendly_format).to eq 'a moment ago'
33
- end
34
- end
35
-
36
- context 'when from 1 minute to less 60 minute' do
37
- time = Time.now - 60
38
- it 'returns in minute format' do
39
- expect(time.friendly_format).to include '1 minute ago'
40
- end
41
- end
42
-
43
- context 'when from 1 hour to less than 24 hours' do
44
- time = Time.now - 60 * 60
45
- it 'returns in hour format' do
46
- expect(time.friendly_format).to include '1 hour ago'
47
- end
48
- end
49
-
50
- context 'when from 1 day to less than 7 days' do
51
- time = Time.now - 60 * 60 * 24
52
- it 'return in day format' do
53
- expect(time.friendly_format).to include '1 day ago'
54
- end
55
- end
56
-
57
- context 'when from 1 week to less than 4 weeks' do
58
- time = Time.now - 60 * 60 * 24 * 7
59
- it 'returns in week format' do
60
- expect(time.friendly_format).to include '1 week ago'
61
- end
62
- end
63
-
64
- context 'when from 1 month to less than 12 months' do
65
- time = Time.now - 60 * 60 * 24 * 30
66
- it 'returns in month format' do
67
- expect(time.friendly_format).to include '1 month ago'
68
- end
69
- end
70
-
71
- context 'when from 1 year to less than 10 years' do
72
- time = Time.now - 60 * 60 * 24 * 365
73
- it 'returns in year format' do
74
- expect(time.friendly_format).to include '1 year ago'
75
- end
76
- end
77
-
78
- context 'when more than or equal 5 years' do
79
- time = Time.now - 60 * 60 * 24 * 365 * 5
80
- it 'returns full format' do
81
- # match regular expression (Thu, Nov 17th 2016 at 17:50 UTC)
82
- expect(time.friendly_format).to match(/((Sun)|(Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat))(,\s)((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))(\s)[0-9]{1,2}((st)|(nd)|(rd)|(th))(\s)[0-9]{4}(\s)(at)(\s)[0-9]{1,2}(:)[0-9]{1,2}(\s)[A-Z]{3}/)
83
- end
84
- end
85
- end
86
- end
1
+ require 'spec_helper'
2
+
3
+ describe Time do
4
+ it 'has a version number' do
5
+ expect(FriendlyTimestamp::VERSION).not_to be nil
6
+ end
7
+
8
+ describe 'word_form' do
9
+ # make sure that return more than or less than phrase
10
+ # make sure that number is no decimal form
11
+ # make sure that it returns appropriate singular and plural form of word
12
+ word = 'minute'
13
+ context 'when number after decimal point is equal or more than 5' do
14
+ num = 1.5
15
+ it 'is supposed to be rounded up' do
16
+ expect(Time.now.word_form(num, word)).to eq 'less than 2 minutes'
17
+ end
18
+ end
19
+
20
+ context 'when number after decimal point is less than 5' do
21
+ num = 1.4
22
+ it 'is supposed to be rounded down' do
23
+ expect(Time.now.word_form(num, word)).to eq 'more than 1 minute'
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '#friendly_format' do
29
+ context 'when less than a minute' do
30
+ time = Time.now - 30
31
+ it 'returns string of moment ago' do
32
+ expect(time.friendly_format).to eq 'a moment ago'
33
+ end
34
+ end
35
+
36
+ context 'when from 1 minute to less 60 minute' do
37
+ time = Time.now - 60
38
+ it 'returns in minute format' do
39
+ expect(time.friendly_format).to include '1 minute ago'
40
+ end
41
+ end
42
+
43
+ context 'when from 1 hour to less than 24 hours' do
44
+ time = Time.now - 60 * 60
45
+ it 'returns in hour format' do
46
+ expect(time.friendly_format).to include '1 hour ago'
47
+ end
48
+ end
49
+
50
+ context 'when from 1 day to less than 7 days' do
51
+ time = Time.now - 60 * 60 * 24
52
+ it 'return in day format' do
53
+ expect(time.friendly_format).to include '1 day ago'
54
+ end
55
+ end
56
+
57
+ context 'when from 1 week to less than 4 weeks' do
58
+ time = Time.now - 60 * 60 * 24 * 7
59
+ it 'returns in week format' do
60
+ expect(time.friendly_format).to include '1 week ago'
61
+ end
62
+ end
63
+
64
+ context 'when from 1 month to less than 12 months' do
65
+ time = Time.now - 60 * 60 * 24 * 30
66
+ it 'returns in month format' do
67
+ expect(time.friendly_format).to include '1 month ago'
68
+ end
69
+ end
70
+
71
+ context 'when from 1 year to less than 5 years' do
72
+ time = Time.now - 60 * 60 * 24 * 365
73
+ it 'returns in year format' do
74
+ expect(time.friendly_format).to include '1 year ago'
75
+ end
76
+ end
77
+
78
+ context 'when more than or equal 5 years' do
79
+ time = Time.now - 60 * 60 * 24 * 365 * 5
80
+ it 'returns full format' do
81
+ # match regular expression (Thu, Nov 17th 2016 at 17:50 UTC)
82
+ expect(time.friendly_format).to match(/((Sun)|(Mon)|(Tue)|(Wed)|(Thu)|(Fri)|(Sat))(,\s)((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))(\s)[0-9]{1,2}((st)|(nd)|(rd)|(th))(\s)[0-9]{4}(\s)(at)(\s)[0-9]{1,2}(:)[0-9]{1,2}(\s)[A-Z]{3}/)
83
+ end
84
+ end
85
+ end
86
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,2 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'friendly_timestamp'
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'friendly_timestamp'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_timestamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuroun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ files:
65
65
  - app/assets/javascripts/friendly_timestamp.js
66
66
  - bin/console
67
67
  - bin/setup
68
+ - lib/core_extensions/time/friendly_timestamp.rb
68
69
  - lib/friendly_timestamp.rb
69
70
  - lib/friendly_timestamp/engine.rb
70
71
  - lib/friendly_timestamp/version.rb
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  version: '0'
91
92
  requirements: []
92
93
  rubyforge_project:
93
- rubygems_version: 2.5.2
94
+ rubygems_version: 2.6.13
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: A gem for display time and date based on local time zone in verbal informal