time_overlap 0.1.1 → 0.1.2

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: ac731a50647898c03ac78d6a3b28f0035a8cd084
4
- data.tar.gz: 51e0cfb23c2e9e37dfc7fd986e82e0f495d2baa9
3
+ metadata.gz: e669bba185d150189f3a3b3d39a5e2580fe504a8
4
+ data.tar.gz: 040f0a671e8033280f98dd97e9835fa48e65c21c
5
5
  SHA512:
6
- metadata.gz: af67e6cc0e4fa6bc52e8356f56a3ac99dda323c8716ef36f23ffe356ed05c67748084428850303fd527341e37a74669aacd3b87eb3cb032932e04db3c9b834d1
7
- data.tar.gz: 168fdc74d095e38b911009a55a74d6856098d5bad729b133f1e7955103a66f56d879cad97bcaeb1a7078d3b68fbe6b441631c1672cce86c4b856901f092370ed
6
+ metadata.gz: 2b60df8d43e896651ea4ad0eb24b2a1f087dc8688360d669e3d20999881fa5d8685c2a3de1129d5e1d967228daa6c0b84fb29e4dff4be08dd92a8c7a9f31d92b
7
+ data.tar.gz: 67daa85fa3d19669f63b89386f30cf06dc48d09ae7677ba3b0a48b8cbcaa15ec73778ab0e1e1fca1c90f8051c9976a7261352f3c218ac04b257597ce3e46cf86
data/Gemfile.lock CHANGED
@@ -1,21 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- time_overlap (0.1.0)
4
+ time_overlap (0.1.1)
5
5
  activesupport
6
+ colorize
6
7
  thor
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- activesupport (5.2.2)
12
+ activesupport (5.2.3)
12
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
14
  i18n (>= 0.7, < 2)
14
15
  minitest (~> 5.1)
15
16
  tzinfo (~> 1.1)
16
- concurrent-ruby (1.1.4)
17
+ colorize (0.8.1)
18
+ concurrent-ruby (1.1.5)
17
19
  diff-lcs (1.3)
18
- i18n (1.5.3)
20
+ i18n (1.6.0)
19
21
  concurrent-ruby (~> 1.0)
20
22
  minitest (5.11.3)
21
23
  rake (10.5.0)
@@ -42,11 +44,11 @@ PLATFORMS
42
44
  ruby
43
45
 
44
46
  DEPENDENCIES
45
- bundler (~> 1.16)
47
+ bundler (~> 2.0)
46
48
  rake (~> 10.0)
47
49
  rspec (~> 3.0)
48
50
  time_overlap!
49
51
  timecop
50
52
 
51
53
  BUNDLED WITH
52
- 1.16.5
54
+ 2.0.1
data/README.md CHANGED
@@ -1,8 +1,21 @@
1
1
  # TimeOverlap
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/time_overlap`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ TODO: Add meeting time!!!!!!!!!!!!!!!!!!!
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ Simple command line tool that allows to find overlap hours between two time zones, with visualization.
6
+
7
+ ```
8
+ $ time_overlap count 8 16 +00:00 Bangkok 4
9
+ ```
10
+
11
+ ![screenshot](http://i68.tinypic.com/mi1npd.png)
12
+
13
+ Assuming that you are in Bangkok and the target time zone is UTC +0
14
+ and you want to cover 4 hours - from 8:00 to 16:00.
15
+
16
+ In most cases it suggests 2 options (cover first 4 hours: 8-12 or last: 12-16).
17
+
18
+ More info: https://www.daxx.com/blog/offshore-team/time-difference-offshore-development
6
19
 
7
20
  ## Installation
8
21
 
@@ -22,7 +35,6 @@ Or install it yourself as:
22
35
 
23
36
  ## Usage
24
37
 
25
- TODO: Write usage instructions here
26
38
 
27
39
  ## Development
28
40
 
data/lib/time_overlap.rb CHANGED
@@ -1,111 +1,11 @@
1
+ require 'time'
2
+ require 'active_support/core_ext/time'
3
+
1
4
  require "time_overlap/version"
2
5
  require "time_overlap/presenter"
3
6
  require "time_overlap/cli"
4
- require 'time'
5
- require 'active_support/core_ext/time'
7
+ require "time_overlap/calculator"
6
8
 
7
9
  module TimeOverlap
8
- class Calculator
9
-
10
- # TODO: add meeting time to choose overlap 1 or overlap 2
11
-
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)
39
-
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
- }
60
- }
61
-
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
10
 
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
110
- end
111
11
  end
@@ -0,0 +1,112 @@
1
+ module TimeOverlap
2
+ class Calculator
3
+
4
+ def initialize(from:, to:, time_zone:, my_time_zone:, min_overlap:)
5
+ @current_year = Time.current.year
6
+ @current_month = Time.current.month
7
+ @current_day = Time.current.day
8
+ @from = from
9
+ @to = to
10
+ @time_zone = time_zone
11
+ @my_time_zone = my_time_zone
12
+ @min_overlap = min_overlap
13
+ @start_time = set_time(from)
14
+ @end_time = set_time(to)
15
+ @duration = (end_time - start_time).to_i / 60 / 60
16
+
17
+ @data = {}
18
+ end
19
+
20
+ def self.count(*args)
21
+ self.new(*args).execute
22
+ end
23
+
24
+ def execute
25
+ offset = duration - min_overlap
26
+
27
+ start_time_in_my_time_zone = start_time.in_time_zone(my_time_zone)
28
+ end_time_in_my_time_zone = end_time.in_time_zone(my_time_zone)
29
+
30
+ x_start_time = (start_time - offset * 60 * 60).in_time_zone(my_time_zone)
31
+ x_end_time = (end_time - offset * 60 * 60).in_time_zone(my_time_zone)
32
+
33
+ y_start_time = (end_time - min_overlap * 60 * 60).in_time_zone(my_time_zone)
34
+ y_end_time = (y_start_time + duration * 60 * 60).in_time_zone(my_time_zone)
35
+
36
+ @data = {
37
+ original: {
38
+ start: start_time,
39
+ end: end_time
40
+ },
41
+ full_overlap: {
42
+ start: start_time_in_my_time_zone,
43
+ end: end_time_in_my_time_zone
44
+ },
45
+ overlap_1: {
46
+ start: x_start_time,
47
+ end: x_end_time
48
+ },
49
+ overlap_2: {
50
+ start: y_start_time,
51
+ end: y_end_time
52
+ }
53
+ }
54
+
55
+ puts @data.inspect
56
+
57
+ if x_start_time == y_start_time && x_end_time == y_end_time
58
+ @data.delete(:overlap_2)
59
+ end
60
+
61
+ throw_errors!
62
+ Presenter.new(@data).generate_output
63
+ end
64
+
65
+ private
66
+
67
+ attr_reader(
68
+ :start_time,
69
+ :end_time,
70
+ :from,
71
+ :to,
72
+ :time_zone,
73
+ :my_time_zone,
74
+ :min_overlap,
75
+ :data,
76
+ :duration
77
+ )
78
+
79
+ def set_time(hour)
80
+ offset = Time.zone_offset(time_zone)
81
+
82
+ if offset.nil?
83
+ zone = ActiveSupport::TimeZone[time_zone]
84
+ offset = zone.utc_offset
85
+ end
86
+
87
+ raise 'Wrong time_zone' if offset.nil?
88
+
89
+ Time.new(
90
+ @current_year,
91
+ @current_month,
92
+ @current_day,
93
+ hour,
94
+ 0,
95
+ 0,
96
+ offset
97
+ )
98
+ end
99
+
100
+ def throw_errors!
101
+ if @min_overlap > @duration
102
+ raise "Min overlap must be lower that duration"
103
+ end
104
+
105
+ raise "Wrong Overlap 1" unless (data[:overlap_1][:end] - data[:overlap_1][:start]).to_i / 60 / 60 == duration
106
+
107
+ if data[:overlap_2] && (data[:overlap_2][:end] - data[:overlap_2][:start]).to_i / 60 / 60 != duration
108
+ raise "Wrong Overlap 2"
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,6 +1,17 @@
1
+ require 'colorize'
2
+
1
3
  module TimeOverlap
2
4
  class Presenter
3
5
 
6
+ AM = "AM ".freeze
7
+ PM = " PM".freeze
8
+ NOON = " 12:00 "
9
+ SIX_AM = " 6:00 "
10
+ SIX_PM = " 6:00 "
11
+
12
+ AVAILABLE_SLOT = "|█| "
13
+ EMPTY_SLOT = "[ ] "
14
+
4
15
  def initialize(data, format = '%T%:z')
5
16
  @data = data
6
17
  @format = format
@@ -10,85 +21,114 @@ module TimeOverlap
10
21
  new(*args).generate_output
11
22
  end
12
23
 
13
- def show_it(s, e)
14
- print"|AM| "
15
- # puts (s.hour..e.hour).inspect
24
+ def generate_output
25
+ puts "Original:"
26
+ puts "#{formated_time(@data[:original][:start], false)} - #{formated_time(@data[:original][:end])}".green
27
+ timeline(@data[:original][:start], @data[:original][:end])
28
+ puts "Full overlap:"
29
+ puts "#{formated_time(@data[:full_overlap][:start], false)} - #{formated_time(@data[:full_overlap][:end])}".green
30
+ timeline(@data[:full_overlap][:start], @data[:full_overlap][:end])
31
+ puts "Overlap 1:"
32
+ puts "#{formated_time(@data[:overlap_1][:start], false)} - #{formated_time(@data[:overlap_1][:end])}".green
33
+ timeline(@data[:overlap_1][:start], @data[:overlap_1][:end])
34
+
35
+ if @data[:overlap_2]
36
+ puts "Overlap 2:"
37
+ puts "#{formated_time(@data[:overlap_2][:start], false)} - #{formated_time(@data[:overlap_2][:end])}".green
38
+ timeline(@data[:overlap_2][:start], @data[:overlap_2][:end])
39
+ end
40
+
41
+ @data
42
+ end
43
+
44
+ private
45
+
46
+ def separator
47
+ puts (" " * 102)
48
+ end
49
+
50
+ def formated_time(time, zone=true)
51
+ format = "%T"
52
+ format.concat(" (%:z)") if zone
53
+ time.strftime(format)
54
+ end
55
+
56
+ def get_color(hour)
57
+ case hour
58
+ when 0..5
59
+ then :blue
60
+ when 6..7
61
+ then :light_blue
62
+ when 8..17
63
+ then :light_yellow
64
+ when 18..21
65
+ then :light_blue
66
+ when 22..23
67
+ then :blue
68
+ end
69
+
70
+ end
71
+
72
+ def with_color(string, hour)
73
+ string.colorize(get_color(hour))
74
+ end
16
75
 
76
+ def timeline(start_time, end_time)
77
+ print " "
17
78
  (0..23).each do |hour|
18
- print ' |NOON| ' if hour == 12
79
+ printf("%-4s", hour)
80
+ end
81
+
82
+ puts ""
19
83
 
20
- if s.hour < e.hour
21
- if (s.hour..e.hour).cover?(hour)
22
- if e.hour != hour
23
- print "[✓]"
84
+ print AM
85
+
86
+ (0..23).each do |hour|
87
+ # print NOON if hour == 12
88
+ # print SIX_AM if hour == 6
89
+ # print SIX_PM if hour == 18
90
+
91
+ if start_time.hour < end_time.hour
92
+ if (start_time.hour..end_time.hour).cover?(hour)
93
+ if end_time.hour != hour
94
+ print with_color(AVAILABLE_SLOT, hour)
24
95
  else
25
- print "[ ]"
96
+ print with_color(EMPTY_SLOT, hour)
26
97
  end
27
98
  else
28
- print "[ ]"
99
+ print with_color(EMPTY_SLOT, hour)
29
100
  end
30
101
  else
31
- if s.hour <= 12
32
- if (e.hour..s.hour).cover?(hour)
33
- if e.hour != hour
34
- print "[✓]"
102
+ if start_time.hour <= 12
103
+ if (end_time.hour..start_time.hour).cover?(hour)
104
+ if end_time.hour != hour
105
+ print with_color(AVAILABLE_SLOT, hour)
35
106
  else
36
- print "[ ]"
107
+ print with_color(EMPTY_SLOT, hour)
37
108
  end
38
109
  else
39
- print "[ ]"
110
+ print with_color(EMPTY_SLOT, hour)
40
111
  end
41
112
  else
42
- if (e.hour..s.hour).cover?(hour)
43
- print "[ ]"
113
+ if (end_time.hour..start_time.hour).cover?(hour)
114
+ if (start_time.hour == hour)
115
+ print with_color(AVAILABLE_SLOT, hour)
116
+ else
117
+ print with_color(EMPTY_SLOT, hour)
118
+ end
44
119
  else
45
- if e.hour != hour
46
- print "[✓]"
120
+ if end_time.hour != hour
121
+ print with_color(AVAILABLE_SLOT, hour)
47
122
  else
48
- print "[ ]"
123
+ print with_color(EMPTY_SLOT, hour)
49
124
  end
50
125
  end
51
126
  end
52
127
  end
53
-
54
128
  end
55
- print " |PM|"
129
+ print PM
56
130
  puts ""
57
131
  separator
58
132
  end
59
-
60
- def generate_output
61
- puts "Original:"
62
- puts "#{formated_time(@data[:original][:start])} - #{formated_time(@data[:original][:end])}"
63
-
64
- separator
65
-
66
- puts "Full overlap:"
67
- puts "#{formated_time(@data[:full_overlap][:start])} - #{formated_time(@data[:full_overlap][:end])}"
68
-
69
- show_it(@data[:full_overlap][:start], @data[:full_overlap][:end])
70
-
71
- puts "Overlap 1:"
72
- puts "#{formated_time(@data[:overlap_1][:start])} - #{formated_time(@data[:overlap_1][:end])}"
73
-
74
- show_it(@data[:overlap_1][:start], @data[:overlap_1][:end])
75
-
76
- puts "Overlap 2:"
77
- puts "#{formated_time(@data[:overlap_2][:start])} - #{formated_time(@data[:overlap_2][:end])}"
78
-
79
- show_it(@data[:overlap_2][:start], @data[:overlap_2][:end])
80
-
81
- @data
82
- end
83
-
84
- private
85
-
86
- def separator
87
- puts "_" * 40
88
- end
89
-
90
- def formated_time(time)
91
- time.strftime("%T %:z")
92
- end
93
133
  end
94
134
  end
@@ -1,3 +1,3 @@
1
1
  module TimeOverlap
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/time_overlap.gemspec CHANGED
@@ -32,8 +32,9 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.add_dependency 'activesupport'
34
34
  spec.add_dependency 'thor'
35
+ spec.add_dependency 'colorize'
35
36
 
36
- spec.add_development_dependency "bundler", "~> 1.16"
37
+ spec.add_development_dependency "bundler", "~> 2.0"
37
38
  spec.add_development_dependency "rake", "~> 10.0"
38
39
  spec.add_development_dependency "rspec", "~> 3.0"
39
40
  spec.add_development_dependency "timecop"
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.1
4
+ version: 0.1.2
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-27 00:00:00.000000000 Z
11
+ date: 2019-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,20 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '1.16'
61
+ version: '2.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '1.16'
68
+ version: '2.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +130,7 @@ files:
116
130
  - bin/setup
117
131
  - exe/time_overlap
118
132
  - lib/time_overlap.rb
133
+ - lib/time_overlap/calculator.rb
119
134
  - lib/time_overlap/cli.rb
120
135
  - lib/time_overlap/presenter.rb
121
136
  - lib/time_overlap/version.rb