jenna_time 0.1.2 → 0.1.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: 1ce6c79bb1913ebe6ef6638ebdd4fe86443f3e30
4
- data.tar.gz: 5fc2545e368a7d5ec5e00a94ce0b841a975a0c6e
3
+ metadata.gz: 659af458f317d4c930a307090309231ef1d1ed4c
4
+ data.tar.gz: d61f9094081342559e5033d9ac1472f57395df00
5
5
  SHA512:
6
- metadata.gz: 8308a8daa320c0c130f6a7d3e84108b7c43274533debd6b876362ad7da1c3a58b6dc2fbc17bb434d96d7be87d955ba56dacf406d536a6bc9dc044cb700e9ca1d
7
- data.tar.gz: 40ffa0599fddfabf9fd1565761191e4e0c05957ba671a82a57ac6938df9f1a413fc00a7d5f2d31f5e1e8739e6a85817c4f3fea114c0a24567227c498ed6fd213
6
+ metadata.gz: d6889b3f7c349914f458766e8fbfd59dac39d6b2cf17fc6095c3dcfe8b27d5470a233de31a294832fb31209b4635580a915ea1fad6e926b8233730e7d7bac37b
7
+ data.tar.gz: 05751d073445eb9a3339857b10a2a9278a6e25688bc24d5a55869956a1aa0edddf2a4be138e1562b1b485b3494dbf7e757163cc4b7076b1c088559d88ebb3df6
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
-
3
2
  gemspec
4
3
 
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', '-~1yr'.
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.2
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-14 00:00:00.000000000 Z
13
+ date: 2016-06-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionview