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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe42dea32866719b9df3b106e76b6e637a79896c
4
- data.tar.gz: 36e9ce5de6e746da4db57ed5e78ec4557000fb0a
3
+ metadata.gz: ac731a50647898c03ac78d6a3b28f0035a8cd084
4
+ data.tar.gz: 51e0cfb23c2e9e37dfc7fd986e82e0f495d2baa9
5
5
  SHA512:
6
- metadata.gz: cf66448ec73c94b4f2f5c60140b0d445ebaaca0cd908f90374c2533e15d99f12a82ec59ecc17ee176a869aeb5b05e1b1a34863691c2db4f7b046a941fad29dae
7
- data.tar.gz: 51c3eecb0c11c8d473550c324a29603315ce98d4dd6fe2d5b8c36322c3651825eacb485e27b8f1b3d6529954c0eca62e5d25799884823e4d1f05c2dcb7401154
6
+ metadata.gz: af67e6cc0e4fa6bc52e8356f56a3ac99dda323c8716ef36f23ffe356ed05c67748084428850303fd527341e37a74669aacd3b87eb3cb032932e04db3c9b834d1
7
+ data.tar.gz: 168fdc74d095e38b911009a55a74d6856098d5bad729b133f1e7955103a66f56d879cad97bcaeb1a7078d3b68fbe6b441631c1672cce86c4b856901f092370ed
@@ -12,7 +12,7 @@ module TimeOverlap
12
12
  4 -> min_overlap (hours, integer)
13
13
  "
14
14
  def count(from, to, time_zone, my_time_zone, min_overlap)
15
- TimeOverlap.count(
15
+ TimeOverlap::Calculator.count(
16
16
  from: from.to_i,
17
17
  to: to.to_i,
18
18
  time_zone: time_zone,
@@ -6,26 +6,78 @@ module TimeOverlap
6
6
  @format = format
7
7
  end
8
8
 
9
- def self.print(*args)
10
- new(*args).print
9
+ def self.generate_output(*args)
10
+ new(*args).generate_output
11
11
  end
12
12
 
13
- def print
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
- separator
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
- separator
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#.strftime("%T %:z")
91
+ time.strftime("%T %:z")
40
92
  end
41
93
  end
42
94
  end
@@ -1,3 +1,3 @@
1
1
  module TimeOverlap
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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
- # TODO: add meeting time to choose overlap 1 or overlap 2
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
- end_time = Time.new(
27
- current_year,
28
- current_month,
29
- current_day,
30
- to,
31
- 0,
32
- 0,
33
- Time.zone_offset(time_zone)
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
- duration = (end_time - start_time).to_i / 60 / 60
37
- offset = duration - min_overlap
38
-
39
- start_time_in_my_time_zone = start_time.in_time_zone(my_time_zone)
40
- end_time_in_my_time_zone = end_time.in_time_zone(my_time_zone)
41
-
42
- x_start_time = (start_time - min_overlap * 60 * 60).in_time_zone(my_time_zone)
43
- x_end_time = (end_time - offset * 60 * 60).in_time_zone(my_time_zone)
44
-
45
- y_start_time = (end_time - min_overlap * 60 * 60).in_time_zone(my_time_zone)
46
- y_end_time = (y_start_time + duration * 60 * 60).in_time_zone(my_time_zone)
47
-
48
- data = {
49
- original: {
50
- start: start_time,
51
- end: end_time
52
- },
53
- full_overlap: {
54
- start: start_time_in_my_time_zone,
55
- end: end_time_in_my_time_zone
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
- Presenter.print(data)
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.0
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 00:00:00.000000000 Z
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport