time-lord 0.1.5 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -4,7 +4,7 @@
4
4
  # development environment upon cd'ing into the directory
5
5
 
6
6
  # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
- environment_id="ruby-1.9.2-p180@time-lord"
7
+ environment_id="ruby-1.9.3-p0@time-lord"
8
8
 
9
9
  #
10
10
  # First we attempt to load the desired environment directly from the environment
data/README.md CHANGED
@@ -1,53 +1,135 @@
1
1
  time-lord
2
+ =========
3
+
4
+ **Current Version**: 0.1.5
5
+
6
+ `time-lord` is a gem that builds on the Time class to give more human expressions.
7
+ It adds a lot of nifty little ideas present in Rails helpers to the time class.
8
+ Nothing too fancy, just a little human touch to data.
9
+
10
+
11
+ Examples
12
+ --------
13
+
14
+ To use `time-lord` you need a Time, Date, or DateTime object.
15
+ You can pass an object that doesn't act like those, but you'll have to tell it to try and parse.
16
+ Even then it might not be able to, so be careful and just send Time-likes.
17
+ Here's an example or two:
18
+
19
+ ``` ruby
20
+ Time.now.ago_in_words
21
+ # => "just now"
22
+
23
+ olden_times = Time.parse("1942-04-01")
24
+
25
+ "I was dancing with Queen Elizabeth #{olden_times.ago_in_words} from now!"
26
+
27
+ # => "I was dancing with Queen Elizabeth 7 decades ago from now!"
28
+ ```
29
+
30
+ There's a lot more to come hopefully.
31
+ Time is fun.
32
+
33
+
34
+ Installing
35
+ ----------
36
+
37
+ **Requirements**
38
+
39
+ 1. Any Ruby with a Time class
40
+ 2. Any Gem manager
41
+ 3. A blue telephone box
42
+
43
+ Like any other gem you can install it via the `gem` command:
44
+
45
+ ``` terminal
46
+ $ gem install time-lord
47
+ ```
48
+
49
+ Although I suggest using `bundler`:
50
+
51
+ ``` ruby
52
+ gem 'time-lord', '0.1.5'
53
+ ```
54
+
55
+
56
+ **Testing**
57
+
58
+ To make sure you did everything right, just do the following:
59
+
60
+ ```
61
+ $ ruby -e "puts Time.now.ago_in_words"
62
+ > just now
63
+ ```
64
+
65
+
66
+ Issues & Documentation
67
+ ----------------------
68
+
69
+ * [Documentation](https://github.com/krainboltgreene/time-lord/wiki)
70
+ * [Issues](https://github.com/krainboltgreene/time-lord/issues)
71
+
72
+ Absolutely feel free to contribute, please!
73
+
74
+
75
+ Changelog
2
76
  ---------
3
- The ruby gem `time-lord` gives extra (needed) methods to the ruby `time` class.
4
- Originally started as gem that gave dwevelopers the `time-ago-in-words` method for the `time` class.
5
- It evolved into a multi-part boost to the `Time` class.
6
77
 
78
+ **v0.1.5**
79
+
80
+ * Changed the name of the gem, added some tests
7
81
 
8
- *postscript* This gem was previously called "time-ago-in-words".
9
- I changed this, obviously.
82
+ **v0.1.0**
10
83
 
84
+ * I didn't track changelogs when this version was released
11
85
 
12
- examples
13
- ========
14
- Examples:
15
- >> Time.now.ago_in_words # => "just now"
16
- >> Time.parse("1942-04-01").ago_in_words # => "7 decades ago"
17
86
 
87
+ Contributing
88
+ ------------
18
89
 
19
- future
20
- ======
21
- >> Time.yesterday
22
- >> Time.last_month
23
- >> Time.last_year
24
- >> Time.now - 1.year
25
- >> Time.now + 15.days
26
- >> Time.last_month.last_day_of_the_month
27
- >> Time.last_day_of_year
90
+ * **Fork** the repository
91
+ * **Clone the repository** locally, or **edit via Github**
92
+ * Create a **new branch** using the [Git Flow Standard](http://yakiloo.com/getting-started-git-flow/) conventions
93
+ * Commit **often** and **when important**
94
+ * **DO NOT CHANGE** ANY OF THESE (without making a new branch for *that* change):
95
+ * `*.gemspec`
96
+ * `Rakefile`
97
+ * `.rvmrc`
98
+ * `.gitignore`
99
+ * Any part of the git history
100
+ * **Write tests** specifically for the changes you've made, if no test exist
101
+ * **Push** your feature or hotfix branch to Github.
102
+ * Make a **Pull Request**
28
103
 
29
- install
30
- =======
31
- `gem install time-lord`
32
104
 
105
+ Credits
106
+ -------
33
107
 
34
- contribute
35
- ==========
36
- Whatever you're cool with, really.
108
+ * [Simon Hørup Eskildsen](https://github.com/Sirupsen)
109
+ * [Henrik Enggaard](mailto: https://github.com/henrikh)
110
+ * [James Larkby-Lahet](https://github.com/wolfwood)
37
111
 
38
112
 
39
- authors
40
- =======
41
- * https://github.com/krainboltgreene
42
- * https://github.com/sirupsen
113
+ License
114
+ -------
43
115
 
116
+ Copyright (c) 2011 Kurtis Rainbolt-Greene
44
117
 
45
- helpers
46
- =======
47
- * https://github.com/wolfwood
48
- * https://github.com/henrikh
118
+ Permission is hereby granted, free of charge, to any person obtaining
119
+ a copy of this software and associated documentation files (the
120
+ "Software"), to deal in the Software without restriction, including
121
+ without limitation the rights to use, copy, modify, merge, publish,
122
+ distribute, sublicense, and/or sell copies of the Software, and to
123
+ permit persons to whom the Software is furnished to do so, subject to
124
+ the following conditions:
49
125
 
126
+ The above copyright notice and this permission notice shall be
127
+ included in all copies or substantial portions of the Software.
50
128
 
51
- credits
52
- =======
53
- * The guy who did the Rails version. I'll find out sometime.
129
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
130
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
131
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
132
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
133
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
134
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
135
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -20,22 +20,21 @@ class Time
20
20
  Eon = 1.0/0
21
21
 
22
22
  def ago_in_words
23
-
24
23
  # Find the time difference between the time provided and the current time.
25
24
  difference = get_time_difference_from self
26
25
 
27
26
  # Catch less than 1 second differences.
28
- return "just now" if difference < 1
27
+ return "just now" if (-1...1) === difference
29
28
 
30
29
  name = get_unit_name_from difference
31
30
  amount = get_unit_amount_from difference
32
- count = get_unit_count_from difference, amount
31
+ count = get_unit_count_from(difference, amount).abs
33
32
 
34
33
  # Determine if unit name needs pluralization.
35
34
  name += "s" if count > 1
36
35
 
37
36
  # Return the remaining string.
38
- "#{count} #{name} ago"
37
+ difference >= 0 ? "#{count} #{name} ago" : "in #{count} #{name}"
39
38
  end
40
39
 
41
40
  private
@@ -49,7 +48,7 @@ class Time
49
48
  end
50
49
 
51
50
  def get_unit_name_from difference
52
- case difference
51
+ case difference.abs
53
52
  when Second...Minute then "second"
54
53
  when Minute...Hour then "minute"
55
54
  when Hour...Day then "hour"
@@ -64,7 +63,7 @@ class Time
64
63
  end
65
64
 
66
65
  def get_unit_amount_from difference
67
- case difference
66
+ case difference.abs
68
67
  when Second...Minute then Second
69
68
  when Minute...Hour then Minute
70
69
  when Hour...Day then Hour
@@ -79,4 +78,6 @@ class Time
79
78
  end
80
79
 
81
80
  alias_method :time_ago_in_words, :ago_in_words
81
+ alias_method :distance_in_words, :ago_in_words
82
+ alias_method :time_distance_in_words, :ago_in_words
82
83
  end
@@ -1,3 +1,3 @@
1
1
  module TimeLord
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -13,90 +13,108 @@ describe Time do
13
13
  describe "seconds" do
14
14
  before do
15
15
  @past = Time.now - 30 * Time::Second
16
+ @future = Time.now + 30 * Time::Second
16
17
  end
17
18
 
18
19
  it 'returns the correct string' do
19
20
  @past.time_ago_in_words.must_equal "30 seconds ago"
21
+ @future.distance_in_words.must_equal "in 30 seconds"
20
22
  end
21
23
  end
22
24
 
23
25
  describe "minutes" do
24
26
  before do
25
27
  @past = Time.now - 15 * Time::Minute
28
+ @future = Time.now + 15 * Time::Minute
26
29
  end
27
30
 
28
31
  it 'returns the correct string' do
29
32
  @past.time_ago_in_words.must_equal "15 minutes ago"
33
+ @future.distance_in_words.must_equal "in 15 minutes"
30
34
  end
31
35
  end
32
36
 
33
37
  describe "singular form for 1" do
34
38
  before do
35
39
  @past = Time.now - 1 * Time::Minute
40
+ @future = Time.now + 1 * Time::Minute
36
41
  end
37
42
 
38
43
  it 'returns the correct string' do
39
44
  @past.time_ago_in_words.must_equal "1 minute ago"
45
+ @future.distance_in_words.must_equal "in 1 minute"
40
46
  end
41
47
  end
42
48
 
43
49
  describe 'hours' do
44
50
  before do
45
51
  @past = Time.now - 4 * Time::Hour
52
+ @future = Time.now + 4 * Time::Hour
46
53
  end
47
54
 
48
55
  it 'returns the correct string' do
49
56
  @past.time_ago_in_words.must_equal "4 hours ago"
57
+ @future.distance_in_words.must_equal "in 4 hours"
50
58
  end
51
59
  end
52
60
 
53
61
  describe 'days' do
54
62
  before do
55
63
  @past = Time.now - 3 * Time::Day
64
+ @future = Time.now + 3 * Time::Day
56
65
  end
57
66
 
58
67
  it 'returns the correct string' do
59
68
  @past.time_ago_in_words.must_equal "3 days ago"
69
+ @future.distance_in_words.must_equal "in 3 days"
60
70
  end
61
71
  end
62
72
 
63
73
  describe 'weeks' do
64
74
  before do
65
75
  @past = Time.now - 2 * Time::Week
76
+ @future = Time.now + 2 * Time::Week
66
77
  end
67
78
 
68
79
  it 'returns the correct string' do
69
80
  @past.time_ago_in_words.must_equal "2 weeks ago"
81
+ @future.distance_in_words.must_equal "in 2 weeks"
70
82
  end
71
83
  end
72
84
 
73
85
  describe 'months' do
74
86
  before do
75
87
  @past = Time.now - 7 * Time::Month
88
+ @future = Time.now + 7 * Time::Month
76
89
  end
77
90
 
78
91
  it 'returns the correct string' do
79
92
  @past.time_ago_in_words.must_equal "7 months ago"
93
+ @future.distance_in_words.must_equal "in 7 months"
80
94
  end
81
95
  end
82
96
 
83
97
  describe 'years' do
84
98
  before do
85
99
  @past = Time.now - 3 * Time::Year
100
+ @future = Time.now + 3 * Time::Year
86
101
  end
87
102
 
88
103
  it 'returns the correct string' do
89
104
  @past.time_ago_in_words.must_equal "3 years ago"
105
+ @future.distance_in_words.must_equal "in 3 years"
90
106
  end
91
107
  end
92
108
 
93
109
  describe 'millennium' do
94
110
  before do
95
111
  @past = Time.now - 4 * Time::Millennium
112
+ @future = Time.now + 4 * Time::Millennium
96
113
  end
97
114
 
98
115
  it 'returns the correct string' do
99
116
  @past.time_ago_in_words.must_equal "4 millenniums ago"
117
+ @future.distance_in_words.must_equal "in 4 millenniums"
100
118
  end
101
119
  end
102
120
  end
@@ -17,4 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rake"
20
22
  end
metadata CHANGED
@@ -1,31 +1,36 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: time-lord
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
4
5
  prerelease:
5
- version: 0.1.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Kurtis Rainbolt-Greene
9
- - "Simon H\xC3\xB8rup Eskildsen"
9
+ - Simon Hørup Eskildsen
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-03-16 00:00:00 -07:00
15
- default_executable:
16
- dependencies: []
17
-
13
+ date: 2011-11-30 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: &2152296180 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *2152296180
18
26
  description: This is a gem that adds a ton of extras to the Time class.
19
- email:
27
+ email:
20
28
  - kurtisrainboltgreene@gmail.com
21
29
  - sirup@sirupsen.com
22
30
  executables: []
23
-
24
31
  extensions: []
25
-
26
32
  extra_rdoc_files: []
27
-
28
- files:
33
+ files:
29
34
  - .gitignore
30
35
  - .rvmrc
31
36
  - .yardoc/checksums
@@ -56,34 +61,36 @@ files:
56
61
  - test/base.rb
57
62
  - test/helper.rb
58
63
  - time-lord.gemspec
59
- has_rdoc: true
60
64
  homepage: http://github.com/krainboltgreene/time-lord#README
61
65
  licenses: []
62
-
63
66
  post_install_message:
64
67
  rdoc_options: []
65
-
66
- require_paths:
68
+ require_paths:
67
69
  - lib
68
- required_ruby_version: !ruby/object:Gem::Requirement
70
+ required_ruby_version: !ruby/object:Gem::Requirement
69
71
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: "0"
74
- required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ segments:
77
+ - 0
78
+ hash: 504416042286362366
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
80
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: "0"
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ segments:
86
+ - 0
87
+ hash: 504416042286362366
80
88
  requirements: []
81
-
82
89
  rubyforge_project:
83
- rubygems_version: 1.6.2
90
+ rubygems_version: 1.8.10
84
91
  signing_key:
85
92
  specification_version: 3
86
93
  summary: Adding various bonuses to the Time class.
87
- test_files:
94
+ test_files:
88
95
  - test/base.rb
89
96
  - test/helper.rb