time_overlap 0.1.0 → 0.1.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 +4 -4
- data/lib/time_overlap/cli.rb +1 -1
- data/lib/time_overlap/presenter.rb +58 -6
- data/lib/time_overlap/version.rb +1 -1
- data/lib/time_overlap.rb +97 -55
- 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: ac731a50647898c03ac78d6a3b28f0035a8cd084
|
4
|
+
data.tar.gz: 51e0cfb23c2e9e37dfc7fd986e82e0f495d2baa9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af67e6cc0e4fa6bc52e8356f56a3ac99dda323c8716ef36f23ffe356ed05c67748084428850303fd527341e37a74669aacd3b87eb3cb032932e04db3c9b834d1
|
7
|
+
data.tar.gz: 168fdc74d095e38b911009a55a74d6856098d5bad729b133f1e7955103a66f56d879cad97bcaeb1a7078d3b68fbe6b441631c1672cce86c4b856901f092370ed
|
data/lib/time_overlap/cli.rb
CHANGED
@@ -6,26 +6,78 @@ module TimeOverlap
|
|
6
6
|
@format = format
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.
|
10
|
-
new(*args).
|
9
|
+
def self.generate_output(*args)
|
10
|
+
new(*args).generate_output
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
13
|
+
def show_it(s, e)
|
14
|
+
print"|AM| "
|
15
|
+
# puts (s.hour..e.hour).inspect
|
16
|
+
|
17
|
+
(0..23).each do |hour|
|
18
|
+
print ' |NOON| ' if hour == 12
|
19
|
+
|
20
|
+
if s.hour < e.hour
|
21
|
+
if (s.hour..e.hour).cover?(hour)
|
22
|
+
if e.hour != hour
|
23
|
+
print "[✓]"
|
24
|
+
else
|
25
|
+
print "[ ]"
|
26
|
+
end
|
27
|
+
else
|
28
|
+
print "[ ]"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
if s.hour <= 12
|
32
|
+
if (e.hour..s.hour).cover?(hour)
|
33
|
+
if e.hour != hour
|
34
|
+
print "[✓]"
|
35
|
+
else
|
36
|
+
print "[ ]"
|
37
|
+
end
|
38
|
+
else
|
39
|
+
print "[ ]"
|
40
|
+
end
|
41
|
+
else
|
42
|
+
if (e.hour..s.hour).cover?(hour)
|
43
|
+
print "[ ]"
|
44
|
+
else
|
45
|
+
if e.hour != hour
|
46
|
+
print "[✓]"
|
47
|
+
else
|
48
|
+
print "[ ]"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
print " |PM|"
|
56
|
+
puts ""
|
57
|
+
separator
|
58
|
+
end
|
59
|
+
|
60
|
+
def generate_output
|
14
61
|
puts "Original:"
|
15
62
|
puts "#{formated_time(@data[:original][:start])} - #{formated_time(@data[:original][:end])}"
|
63
|
+
|
16
64
|
separator
|
17
65
|
|
18
66
|
puts "Full overlap:"
|
19
67
|
puts "#{formated_time(@data[:full_overlap][:start])} - #{formated_time(@data[:full_overlap][:end])}"
|
20
|
-
|
68
|
+
|
69
|
+
show_it(@data[:full_overlap][:start], @data[:full_overlap][:end])
|
21
70
|
|
22
71
|
puts "Overlap 1:"
|
23
72
|
puts "#{formated_time(@data[:overlap_1][:start])} - #{formated_time(@data[:overlap_1][:end])}"
|
24
|
-
|
73
|
+
|
74
|
+
show_it(@data[:overlap_1][:start], @data[:overlap_1][:end])
|
25
75
|
|
26
76
|
puts "Overlap 2:"
|
27
77
|
puts "#{formated_time(@data[:overlap_2][:start])} - #{formated_time(@data[:overlap_2][:end])}"
|
28
78
|
|
79
|
+
show_it(@data[:overlap_2][:start], @data[:overlap_2][:end])
|
80
|
+
|
29
81
|
@data
|
30
82
|
end
|
31
83
|
|
@@ -36,7 +88,7 @@ module TimeOverlap
|
|
36
88
|
end
|
37
89
|
|
38
90
|
def formated_time(time)
|
39
|
-
time
|
91
|
+
time.strftime("%T %:z")
|
40
92
|
end
|
41
93
|
end
|
42
94
|
end
|
data/lib/time_overlap/version.rb
CHANGED
data/lib/time_overlap.rb
CHANGED
@@ -5,65 +5,107 @@ require 'time'
|
|
5
5
|
require 'active_support/core_ext/time'
|
6
6
|
|
7
7
|
module TimeOverlap
|
8
|
+
class Calculator
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
def self.count(from:, to:, time_zone:, my_time_zone:, min_overlap:)
|
12
|
-
current_year = Time.current.year
|
13
|
-
current_month = Time.current.month
|
14
|
-
current_day = Time.current.day
|
15
|
-
|
16
|
-
start_time = Time.new(
|
17
|
-
current_year,
|
18
|
-
current_month,
|
19
|
-
current_day,
|
20
|
-
from,
|
21
|
-
0,
|
22
|
-
0,
|
23
|
-
Time.zone_offset(time_zone)
|
24
|
-
)
|
10
|
+
# TODO: add meeting time to choose overlap 1 or overlap 2
|
25
11
|
|
26
|
-
|
27
|
-
current_year
|
28
|
-
current_month
|
29
|
-
current_day
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
12
|
+
def initialize(from:, to:, time_zone:, my_time_zone:, min_overlap:)
|
13
|
+
@current_year = Time.current.year
|
14
|
+
@current_month = Time.current.month
|
15
|
+
@current_day = Time.current.day
|
16
|
+
@from = from
|
17
|
+
@to = to
|
18
|
+
@time_zone = time_zone
|
19
|
+
@my_time_zone = my_time_zone
|
20
|
+
@min_overlap = min_overlap
|
21
|
+
|
22
|
+
@duration = (end_time - start_time).to_i / 60 / 60
|
23
|
+
|
24
|
+
@data = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.count(*args)
|
28
|
+
self.new(*args).execute
|
29
|
+
end
|
30
|
+
|
31
|
+
def execute
|
32
|
+
offset = duration - min_overlap
|
33
|
+
|
34
|
+
start_time_in_my_time_zone = start_time.in_time_zone(my_time_zone)
|
35
|
+
end_time_in_my_time_zone = end_time.in_time_zone(my_time_zone)
|
36
|
+
|
37
|
+
x_start_time = (start_time - offset * 60 * 60).in_time_zone(my_time_zone)
|
38
|
+
x_end_time = (end_time - offset * 60 * 60).in_time_zone(my_time_zone)
|
35
39
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
},
|
57
|
-
overlap_1: {
|
58
|
-
start: x_start_time,
|
59
|
-
end: x_end_time
|
60
|
-
},
|
61
|
-
overlap_2: {
|
62
|
-
start: y_start_time,
|
63
|
-
end: y_end_time
|
40
|
+
y_start_time = (end_time - min_overlap * 60 * 60).in_time_zone(my_time_zone)
|
41
|
+
y_end_time = (y_start_time + duration * 60 * 60).in_time_zone(my_time_zone)
|
42
|
+
|
43
|
+
@data = {
|
44
|
+
original: {
|
45
|
+
start: start_time,
|
46
|
+
end: end_time
|
47
|
+
},
|
48
|
+
full_overlap: {
|
49
|
+
start: start_time_in_my_time_zone,
|
50
|
+
end: end_time_in_my_time_zone
|
51
|
+
},
|
52
|
+
overlap_1: {
|
53
|
+
start: x_start_time,
|
54
|
+
end: x_end_time
|
55
|
+
},
|
56
|
+
overlap_2: {
|
57
|
+
start: y_start_time,
|
58
|
+
end: y_end_time
|
59
|
+
}
|
64
60
|
}
|
65
|
-
}
|
66
61
|
|
67
|
-
|
62
|
+
check
|
63
|
+
Presenter.new(@data).generate_output
|
64
|
+
@data
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
attr_reader(
|
70
|
+
:current_year,
|
71
|
+
:current_month,
|
72
|
+
:current_day,
|
73
|
+
:from,
|
74
|
+
:to,
|
75
|
+
:time_zone,
|
76
|
+
:my_time_zone,
|
77
|
+
:min_overlap,
|
78
|
+
:data,
|
79
|
+
:duration
|
80
|
+
)
|
81
|
+
|
82
|
+
def start_time
|
83
|
+
@start_time ||= Time.new(
|
84
|
+
current_year,
|
85
|
+
current_month,
|
86
|
+
current_day,
|
87
|
+
from,
|
88
|
+
0,
|
89
|
+
0,
|
90
|
+
Time.zone_offset(time_zone)
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def end_time
|
95
|
+
@end_time ||= Time.new(
|
96
|
+
current_year,
|
97
|
+
current_month,
|
98
|
+
current_day,
|
99
|
+
to,
|
100
|
+
0,
|
101
|
+
0,
|
102
|
+
Time.zone_offset(time_zone)
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def check
|
107
|
+
raise "Wrong Overlap 1" unless (data[:overlap_1][:end] - data[:overlap_1][:start]).to_i / 60 / 60 == duration
|
108
|
+
raise "Wrong Overlap 2" unless (data[:overlap_2][:end] - data[:overlap_2][:start]).to_i / 60 / 60 == duration
|
109
|
+
end
|
68
110
|
end
|
69
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_overlap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafał Trojanowski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|