jenna_time 0.1.2 → 0.1.3
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/Gemfile +0 -1
- data/README.md +1 -3
- data/lib/jenna_time.rb +19 -0
- data/spec/jenna_time.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 659af458f317d4c930a307090309231ef1d1ed4c
|
4
|
+
data.tar.gz: d61f9094081342559e5033d9ac1472f57395df00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6889b3f7c349914f458766e8fbfd59dac39d6b2cf17fc6095c3dcfe8b27d5470a233de31a294832fb31209b4635580a915ea1fad6e926b8233730e7d7bac37b
|
7
|
+
data.tar.gz: 05751d073445eb9a3339857b10a2a9278a6e25688bc24d5a55869956a1aa0edddf2a4be138e1562b1b485b3494dbf7e757163cc4b7076b1c088559d88ebb3df6
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -36,11 +36,9 @@ It follows the following rules:
|
|
36
36
|
* 1 yr, 9 months <-> 2 yr minus 1 sec # => __~2y__
|
37
37
|
* 2 yrs <-> max time or date # => __[years]y__
|
38
38
|
|
39
|
-
It abbreviates the time so 'less than a minute' becomes '<1m' and 'about 1 year' becomes '~1y'.
|
40
|
-
|
41
39
|
If there are less than 60 seconds left then it will display in the format of '36s'.
|
42
40
|
|
43
|
-
If starttime is greater than endtime then it will express the time distance in the same way, except there will be a negative sign at the start, e.g. '-30s', '
|
41
|
+
If starttime is greater than endtime then it will express the time distance in the same way, except there will be a negative sign at the start, e.g. '-30s', '~-1yr'.
|
44
42
|
|
45
43
|
## License
|
46
44
|
|
data/lib/jenna_time.rb
CHANGED
@@ -4,7 +4,23 @@ include ActionView::Helpers::DateHelper
|
|
4
4
|
require 'date'
|
5
5
|
|
6
6
|
module JennaTime
|
7
|
+
|
8
|
+
def self.verify_argument(time)
|
9
|
+
unless time.is_a?(DateTime) or time.is_a?(Time)
|
10
|
+
begin
|
11
|
+
DateTime.parse(time)
|
12
|
+
rescue
|
13
|
+
raise InvalidDateTimeArgument.new("Invalid argument: #{time.to_s}")
|
14
|
+
end
|
15
|
+
else
|
16
|
+
time
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
7
20
|
def self.duration(starttime, endtime=Time.now())
|
21
|
+
starttime = verify_argument(starttime)
|
22
|
+
endtime = verify_argument(endtime)
|
23
|
+
|
8
24
|
remaining_seconds = Integer(endtime.to_time - starttime.to_time)
|
9
25
|
if remaining_seconds == 0
|
10
26
|
return ""
|
@@ -35,4 +51,7 @@ module JennaTime
|
|
35
51
|
"#{approximation}#{sign}#{number}#{unit}"
|
36
52
|
end
|
37
53
|
end
|
54
|
+
|
55
|
+
class InvalidDateTimeArgument < StandardError
|
56
|
+
end
|
38
57
|
end
|
data/spec/jenna_time.rb
CHANGED
@@ -102,4 +102,13 @@ describe "Time duration testing" do
|
|
102
102
|
starttime = Time.now
|
103
103
|
expect(JennaTime::duration(starttime)).to eq('')
|
104
104
|
end
|
105
|
+
it "If we supply an invalid starttime then the appropriate error should be raised" do
|
106
|
+
starttime = 'error'
|
107
|
+
expect{JennaTime::duration(starttime)}.to raise_error(JennaTime::InvalidDateTimeArgument)
|
108
|
+
end
|
109
|
+
it "If we supply an string starttime and endtime then it should parse it appropriately" do
|
110
|
+
starttime = '2016-06-17 12:24:15 +0100'
|
111
|
+
endtime = '2016-06-17 12:24:38 +0100'
|
112
|
+
expect{JennaTime::duration(starttime,endtime)}.to_not raise_error
|
113
|
+
end
|
105
114
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jenna_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BBC
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-06-
|
13
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: actionview
|