time_range 0.0.2 → 0.0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/time_range.rb +21 -0
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72ca2f5e7ebd8cec9c05472b26e7aff6285ce96c
4
- data.tar.gz: ae8d2dea30bda80e84c67197dc62c0e60a38dce5
3
+ metadata.gz: 0d88e729415b77d4848e9a00bb14ee10fabf8263
4
+ data.tar.gz: 0aad31f8b9f8d321973fcb056ee1592b4dee4e30
5
5
  SHA512:
6
- metadata.gz: d5a43fde93f57c9c1cdd3da640d1f8b99dee442854196b964cd007fd217b79e51502a5caedfedceb6e9f630d5d0d0920a51ee8391a26511a837e7b9ff1dd7699
7
- data.tar.gz: 17e9d669040e8c40fd0a2fc7917bcd702e657106165290463b91e5f188fcc2f91ba06cb552cb6edfc3d427b139693f7c5941b4b2ea2a7641ae3c2b6aeeba9471
6
+ metadata.gz: ee4b2114feff2cf1991740b2cdfc75cf3d599031092861bbbc555c55c43e62ce7adb40330a27336339effc702b396a7e1cc20893f1e5f1d2bb99c91d858124f3
7
+ data.tar.gz: e2769c0e428fe4c77d753c39cd7bfcf7048f7e456a8f5730401fcd8316df2de35a048412b507c496528730e7dc3e910396ef0e9616b65f975860dba92e006804
@@ -24,6 +24,10 @@ WRONG_ARG = "is not time"
24
24
  # range2 = TimeRange.new(Time.now - 10, Time.now + 10)
25
25
  # # => 2013-09-13 23:50:31 +0400..2013-09-13 23:50:51 +0400
26
26
  #
27
+ # Calculate length of time_range in seconds
28
+ # range2.length
29
+ # # => 20.00000462
30
+ #
27
31
  # range.fully_include?(range2)
28
32
  # # => true
29
33
  #
@@ -47,6 +51,10 @@ WRONG_ARG = "is not time"
47
51
  # # => [2013-09-14 00:00:00 +0400..2013-09-14 00:55:51 +0400,
48
52
  # # 2013-09-14 01:00:51 +0400..2013-09-14 01:05:51 +0400,
49
53
  # # 2013-09-14 01:10:51 +0400..2013-09-14 23:59:59 +0400]
54
+ #
55
+ # Calculate sum of lengths for several time ranges
56
+ # TimeRange.sum_length(TimeRange.for_date(Date.today), TimeRange.for_date(Date.today + 1))
57
+ # => 172798.0
50
58
  class TimeRange < Range
51
59
 
52
60
  alias_method :orig_init, :initialize
@@ -79,6 +87,10 @@ class TimeRange < Range
79
87
  self.include?(time_rage.begin) && self.include?(time_rage.end)
80
88
  end
81
89
 
90
+ def length
91
+ self.end - self.begin
92
+ end
93
+
82
94
  def subtract(*ranges)
83
95
  ranges = ranges.flatten.sort{|a, b| a.begin <=> b.begin}
84
96
  return self if ranges.empty?
@@ -133,4 +145,13 @@ class TimeRange < Range
133
145
  return result.is_a?(Array) ? result.flatten : result
134
146
  end
135
147
  end
148
+
149
+ def self.sum_length(tranges)
150
+ result = 0.0
151
+ tranges.each do |range|
152
+ result += range.length
153
+ end
154
+ result
155
+ end
156
+
136
157
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_range
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Boltnev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-19 00:00:00.000000000 Z
11
+ date: 2013-10-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Time ranges Intersection, union, etc
14
14
  email: ilya@boltnev.com
@@ -18,7 +18,8 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/time_range.rb
20
20
  homepage: https://github.com/boltnev/time_ranges
21
- licenses: []
21
+ licenses:
22
+ - MIT
22
23
  metadata: {}
23
24
  post_install_message:
24
25
  rdoc_options: []