timespans 0.0.1 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/LICENSE.txt +20 -0
- data/lib/abstractive/timespans.rb +66 -54
- data/timespans.gemspec +3 -1
- metadata +32 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8dc92ab2859a96e479a8c8e187d37d62bc31a91
|
4
|
+
data.tar.gz: 0bceeb41b59bd8cc777ed43c8a6ddc328612237f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 978bebd579db048882ad87e67849526035a64d3bd0424a88b696da0015e2d1167bc31babe07e9eebb04c21ed1c4f6055e23bec67398905a7e15c606994fa4f5e
|
7
|
+
data.tar.gz: 9c9fe2d2cd0bc22ffd334fb35c6b630d48d562136969c9789b94df65ac9ed8b2cb68fa8739d4980f1fff53a537643fa71cc8ce00ccc98947e87c3feb0ae2d07e
|
data/.gitignore
CHANGED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 digitalextremist //
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,67 +1,79 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'time'
|
3
|
+
require 'hitimes'
|
4
|
+
require 'abstractive'
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
module Methods
|
6
|
+
class Abstractive::TimeSpans
|
7
|
+
module Methods
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
MINUTE = 60
|
10
|
+
HOUR = MINUTE*60
|
11
|
+
DAY = HOUR*24
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
def plus_span(base, add)
|
39
|
-
add = day_decimal(add) unless add.is_a?(Float)
|
40
|
-
_ = DateTime.jd(base.to_datetime.jd + add)
|
41
|
-
DateTime.strptime(_.strftime('%FT%T')+base.strftime('%:z'))
|
42
|
-
end
|
43
|
-
def minus_span(base, sub)
|
44
|
-
sub = day_decimal(sub) unless sub.is_a?(Float)
|
45
|
-
_ = DateTime.jd(base.to_datetime.jd - sub)
|
46
|
-
DateTime.strptime(_.strftime('%FT%T')+base.strftime('%:z'))
|
13
|
+
def notated_time_length(span)
|
14
|
+
span = time_spans(span) unless span.is_a? Array
|
15
|
+
length = ""
|
16
|
+
length += "#{span[0]}d " if span[0] > 0
|
17
|
+
length += "#{span[1]}h " if span[1] > 0
|
18
|
+
length += "#{span[2]}m " if span[2] > 0
|
19
|
+
length += "#{span[3]}s "
|
20
|
+
length += "#{span[2]}ms " if span[3] > 0
|
21
|
+
length.strip
|
22
|
+
end
|
23
|
+
alias :readable_duration :notated_time_length
|
24
|
+
|
25
|
+
def day_decimal(span)
|
26
|
+
span = time_spans(span) if span.is_a? Fixnum
|
27
|
+
hms = span[1]*HOUR+span[2]*MINUTE+span[3]
|
28
|
+
span[0].to_f + (hms.to_f/DAY.to_f)
|
29
|
+
end
|
30
|
+
|
31
|
+
def time_spans(length)
|
32
|
+
milliseconds = nil
|
33
|
+
puts(length.class.name)
|
34
|
+
length = length.dup
|
35
|
+
if length.is_a?(Float)
|
36
|
+
milliseconds = ((length - length.floor) * 100).to_i
|
37
|
+
length = length.to_i
|
47
38
|
end
|
39
|
+
days = (length / DAY).floor
|
40
|
+
length = length % DAY if days > 0
|
41
|
+
hours = (length / HOUR).floor
|
42
|
+
length = length % HOUR if hours > 0
|
43
|
+
minutes = (length / MINUTE).floor
|
44
|
+
length = length % MINUTE if minutes > 0
|
45
|
+
seconds = length
|
46
|
+
[days, hours, minutes, seconds, milliseconds]
|
48
47
|
end
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
def plus_span(base, add)
|
50
|
+
add = day_decimal(add) unless add.is_a?(Float)
|
51
|
+
_ = DateTime.jd(base.to_datetime.jd + add)
|
52
|
+
DateTime.strptime(_.strftime('%FT%T')+base.strftime('%:z'))
|
53
|
+
end
|
52
54
|
|
53
|
-
def
|
54
|
-
|
55
|
+
def minus_span(base, sub)
|
56
|
+
sub = day_decimal(sub) unless sub.is_a?(Float)
|
57
|
+
_ = DateTime.jd(base.to_datetime.jd - sub)
|
58
|
+
DateTime.strptime(_.strftime('%FT%T')+base.strftime('%:z'))
|
59
|
+
end
|
60
|
+
|
61
|
+
def duration(start, finish)
|
62
|
+
finish.to_i - start.to_i
|
63
|
+
end
|
64
|
+
end
|
55
65
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
66
|
+
include Methods
|
67
|
+
extend Methods
|
68
|
+
|
69
|
+
def initialize(i); @i = i end
|
70
|
+
def to_i; @i end
|
71
|
+
|
72
|
+
class << self
|
73
|
+
def at(text, format=STANDARD_FORMAT)
|
74
|
+
DateTime.strptime(text, format).to_time
|
75
|
+
rescue => ex
|
76
|
+
Abstractive[:logger].exception(ex,"Trouble turning string into DateTime and then Time object.")
|
65
77
|
end
|
66
78
|
end
|
67
79
|
end
|
data/timespans.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
4
|
gem.name = "timespans"
|
5
|
-
gem.version = "0.0.
|
5
|
+
gem.version = "0.0.9"
|
6
6
|
gem.platform = Gem::Platform::RUBY
|
7
7
|
gem.summary = "Time delineation and organization utilities."
|
8
8
|
gem.description = "Time delineation and organization utilities."
|
@@ -17,4 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|examples|spec|features)/}) }
|
19
19
|
gem.require_path = "lib"
|
20
|
+
gem.add_runtime_dependency "abstractive"
|
21
|
+
gem.add_runtime_dependency "hitimes", ">= 1.2.2"
|
20
22
|
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timespans
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- digitalextremist //
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
-
dependencies:
|
11
|
+
date: 2015-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - '>='
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: abstractive
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.2.2
|
33
|
+
name: hitimes
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.2
|
13
41
|
description: Time delineation and organization utilities.
|
14
42
|
email:
|
15
43
|
- code@extremist.digital
|
@@ -19,6 +47,7 @@ extra_rdoc_files: []
|
|
19
47
|
files:
|
20
48
|
- .gitignore
|
21
49
|
- Gemfile
|
50
|
+
- LICENSE.txt
|
22
51
|
- README.md
|
23
52
|
- Rakefile
|
24
53
|
- lib/abstractive/timespans.rb
|