time_sentence 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +78 -1
- data/lib/time_sentence/version.rb +1 -1
- metadata +1 -1
data/Readme.md
CHANGED
@@ -1 +1,78 @@
|
|
1
|
-
|
1
|
+
# Time Sentence
|
2
|
+
|
3
|
+
Time Sentence lets you transform any number of seconds into a human-readable sentence. Love lets you transform suffering
|
4
|
+
into joy.
|
5
|
+
|
6
|
+
## Basic Usage
|
7
|
+
|
8
|
+
You can use the `time_sentence` method on any number or the Time.sentence class method to get the same result
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
1.hour.time_sentence #=> "1 hour"
|
12
|
+
168.hours.time_sentence #=> "1 week"
|
13
|
+
9999.seconds.time_sentence #=> "2 hours, 46 minutes, 39 seconds"
|
14
|
+
123456876543.seconds.time_sentence #=> "4 millennia, 25 decades, 2 years"
|
15
|
+
|
16
|
+
Time.sentence(1.hour) #=> "1 hour"
|
17
|
+
Time.sentence(168.hours) #=> "1 week"
|
18
|
+
Time.sentence(9999.seconds) #=> "2 hours, 46 minutes, 39 seconds"
|
19
|
+
Time.sentence(123456876543.seconds) #=> "4 millennia, 25 decades, 2 years"
|
20
|
+
```
|
21
|
+
|
22
|
+
## Advanced Usage
|
23
|
+
|
24
|
+
### Specificity
|
25
|
+
|
26
|
+
Time_Sentence assumes that you won't want more than 3 terms in your sentence, so it chooses the largest unit it can,
|
27
|
+
then displays the next smaller 2 (that don't equal 0) as well. For example:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
123456877.seconds.time_sentence #=> "4 years, 3 months, 21 hours"
|
31
|
+
```
|
32
|
+
|
33
|
+
Normally if you have a number on the scale of years, it doesn't matter how many, say, seconds there are. The number
|
34
|
+
above represents 4 years, 3 months, 0 weeks, 0 days, 21 hours, and probably some number if minutes and seconds.
|
35
|
+
|
36
|
+
If we actually *do* care about those minutes and seconds, we can pass a specificity argument in to make the sentence
|
37
|
+
more (or less specific). For example:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
123456877.seconds.time_sentence #=> "4 years, 3 months, 21 hours"
|
41
|
+
123456877.seconds.time_sentence(1) #=> "4 years"
|
42
|
+
123456877.seconds.time_sentence(2) #=> "4 years, 3 months"
|
43
|
+
123456877.seconds.time_sentence(3) #=> "4 years, 3 months, 21 hours"
|
44
|
+
123456877.seconds.time_sentence(4) #=> "4 years, 3 months, 21 hours, 34 minutes"
|
45
|
+
123456877.seconds.time_sentence(5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds"
|
46
|
+
|
47
|
+
Time.sentence(123456877.seconds, 5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds"
|
48
|
+
```
|
49
|
+
|
50
|
+
### Past Times
|
51
|
+
|
52
|
+
Passing a negative number into the method will generate a sentence about the past:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
-123456877.seconds.time_sentence(5) #=> "4 years, 3 months, 21 hours, 34 minutes, 37 seconds ago"
|
56
|
+
```
|
57
|
+
|
58
|
+
### Now
|
59
|
+
|
60
|
+
Passing 0 into the method will simply return "now"
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
0.seconds.time_sentence #=> "now"
|
64
|
+
```
|
65
|
+
|
66
|
+
# Contributors
|
67
|
+
|
68
|
+
time_sentence is solely Pete Michaud's (me@petermichaud.com) fault, so blame him for everything.
|
69
|
+
|
70
|
+
# License
|
71
|
+
|
72
|
+
(The MIT License)
|
73
|
+
|
74
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
75
|
+
|
76
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
77
|
+
|
78
|
+
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|