jenna_time 0.1
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 +7 -0
- data/README.md +53 -0
- data/lib/jenna_time.rb +38 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3c2f2346a27a8505e941c6b7e0b228dde7b8144
|
4
|
+
data.tar.gz: 8282c541b306470e29d1d3800502d49dc75f190c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7181552ea07f88be1399103741e03fc3e8001b457460969f18f0fd61bdbb6694357cca05f23cab04f23b7d97c58608815a6784a7f3b26f32260cf47e5e5c9113
|
7
|
+
data.tar.gz: 2c26f042c7ff11e14d8401281dc1524c1d394fea623e6de1811db6fde2484d0a9aa6c1f7ecc491552dbd05d686cd6999ab7adf73b397af6943cb6f2447cf9d08
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
## About
|
2
|
+
|
3
|
+
This gem will display the distance between two Ruby datetime objects in the form of a very short textual description.
|
4
|
+
|
5
|
+
## JennaTime Gem
|
6
|
+
|
7
|
+
```
|
8
|
+
require 'jenna_time'
|
9
|
+
include JennaTime
|
10
|
+
JennaTime::duration(Time.now()-10)
|
11
|
+
# => "10s"
|
12
|
+
```
|
13
|
+
|
14
|
+
## API
|
15
|
+
|
16
|
+
* JennaTime::duration(starttime,endtime) - outputs the time distance in a shorthand format between starttime and endtime
|
17
|
+
* JennaTime::duration(endtime) - outputs the time distance in a shorthand format between Time.now() and endtime
|
18
|
+
|
19
|
+
## Description
|
20
|
+
|
21
|
+
It follows the following rules:
|
22
|
+
|
23
|
+
* 0 (no difference) # => __''__
|
24
|
+
* 1 <-> 59 secs # => __[1-59]s__
|
25
|
+
* 60 secs <-> 1 min, 29 secs # => __1m__
|
26
|
+
* 1 min, 30 secs <-> 44 mins, 29 secs # => __[2..44]m__
|
27
|
+
* 44 mins, 30 secs <-> 89 mins, 29 secs # => __~1h__
|
28
|
+
* 89 mins, 30 secs <-> 23 hrs, 59 mins, 29 secs # => __~[2..24]h__
|
29
|
+
* 23 hrs, 59 mins, 30 secs <-> 41 hrs, 59 mins, 29 secs # => __~1d__
|
30
|
+
* 41 hrs, 59 mins, 30 secs <-> 29 days, 23 hrs, 59 mins, 29 secs # => __[2..29]d__
|
31
|
+
* 29 days, 23 hrs, 59 mins, 30 secs <-> 44 days, 23 hrs, 59 mins, 29 secs # => __1mo__
|
32
|
+
* 44 days, 23 hrs, 59 mins, 30 secs <-> 59 days, 23 hrs, 59 mins, 29 secs # => __2mo__
|
33
|
+
* 59 days, 23 hrs, 59 mins, 30 secs <-> 1 yr minus 1 sec # => __[2..12]mo__
|
34
|
+
* 1 yr <-> 1 yr, 3 months # => __1y__
|
35
|
+
* 1 yr, 3 months <-> 1 yr, 9 months # => __1y__
|
36
|
+
* 1 yr, 9 months <-> 2 yr minus 1 sec # => __~2y__
|
37
|
+
* 2 yrs <-> max time or date # => __[years]y__
|
38
|
+
|
39
|
+
It abbreviates the time so 'less than a minute' becomes '<1m' and 'about 1 year' becomes '~1y'.
|
40
|
+
|
41
|
+
If there are less than 60 seconds left then it will display in the format of '36s'.
|
42
|
+
|
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'.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The 'Jenna Time' gem is available to everyone under the terms of the MIT open source licence.
|
48
|
+
Take a look at the LICENSE file in the code.
|
49
|
+
|
50
|
+
Copyright (c) 2016 BBC
|
51
|
+
|
52
|
+
|
53
|
+
|
data/lib/jenna_time.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'active_support/core_ext/object/acts_like'
|
3
|
+
include ActionView::Helpers::DateHelper
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
module JennaTime
|
7
|
+
def self.duration(starttime, endtime=Time.now())
|
8
|
+
remaining_seconds = Integer(endtime.to_time - starttime.to_time)
|
9
|
+
if remaining_seconds == 0
|
10
|
+
return ""
|
11
|
+
end
|
12
|
+
if(remaining_seconds <= -1)
|
13
|
+
sign = "-"
|
14
|
+
else
|
15
|
+
sign = ""
|
16
|
+
end
|
17
|
+
if remaining_seconds > -59 and remaining_seconds < 59
|
18
|
+
remaining_seconds.to_s + "s"
|
19
|
+
else
|
20
|
+
wordy_time = ActionView::Helpers::DateHelper.distance_of_time_in_words(starttime, endtime)
|
21
|
+
|
22
|
+
approximation = ""
|
23
|
+
if wordy_time =~ /.*about.*/ or
|
24
|
+
wordy_time =~ /.*almost.*/
|
25
|
+
approximation = "~"
|
26
|
+
end
|
27
|
+
|
28
|
+
wordy_time =~ /(\d+)\s(.)/
|
29
|
+
number = $1
|
30
|
+
unit = $2
|
31
|
+
|
32
|
+
if wordy_time =~ /.*month.*/
|
33
|
+
unit = "mo"
|
34
|
+
end
|
35
|
+
"#{approximation}#{sign}#{number}#{unit}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenna_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BBC
|
8
|
+
- Jenna Brown
|
9
|
+
- David Craddock
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: actionview
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.2.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: 4.2.6
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rspec
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '3.2'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '3.2'
|
43
|
+
description: A gem to display the distance between two datetimes in a compact string
|
44
|
+
format
|
45
|
+
email:
|
46
|
+
- david.craddock@bbc.co.uk
|
47
|
+
executables: []
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- README.md
|
52
|
+
- lib/jenna_time.rb
|
53
|
+
homepage: https://github.com/bbc/jenna_time
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.6.4
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Jenna Time Distance Format
|
77
|
+
test_files: []
|