workpattern 0.5.0 → 0.6.0
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 +5 -5
- data/.gitignore +8 -20
- data/.travis.yml +18 -12
- data/{CHANGELOG → CHANGELOG.md} +19 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/LICENSE.txt +21 -0
- data/README.md +2 -27
- data/Rakefile +0 -0
- data/lib/workpattern.rb +5 -73
- data/lib/workpattern/clock.rb +0 -0
- data/lib/workpattern/constants.rb +72 -0
- data/lib/workpattern/day.rb +245 -0
- data/lib/workpattern/version.rb +1 -1
- data/lib/workpattern/week.rb +119 -296
- data/lib/workpattern/week_pattern.rb +144 -0
- data/lib/workpattern/workpattern.rb +73 -125
- data/script/console +0 -0
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- data/workpattern.gemspec +32 -20
- metadata +21 -33
- data/lib/workpattern/utility/base.rb +0 -27
- data/test/test_clock.rb +0 -29
- data/test/test_helper.rb +0 -2
- data/test/test_week.rb +0 -532
- data/test/test_workpattern.rb +0 -307
- data/test/test_workpattern_module.rb +0 -88
data/script/console
CHANGED
File without changes
|
data/script/destroy
CHANGED
File without changes
|
data/script/generate
CHANGED
File without changes
|
data/script/txt2html
CHANGED
File without changes
|
data/workpattern.gemspec
CHANGED
@@ -1,27 +1,39 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "workpattern/version"
|
4
3
|
|
5
|
-
|
6
|
-
s.name = "workpattern"
|
7
|
-
s.version = Workpattern::VERSION
|
8
|
-
s.authors = ["Barrie Callender"]
|
9
|
-
s.email = ["barrie@callenb.org"]
|
10
|
-
s.homepage = "http://github.com/callenb/workpattern"
|
11
|
-
s.summary = %q{Calculates dates and durations whilst taking into account working and non-working periods down to a minute}
|
12
|
-
s.description = %q{Calculates dates and durations whilst taking into account working and non-working times down to a minute. Business working time with holidays are a breeze.}
|
13
|
-
s.license = 'MIT'
|
4
|
+
require_relative "lib/workpattern/version"
|
14
5
|
|
15
|
-
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "workpattern"
|
8
|
+
spec.version = Workpattern::VERSION
|
9
|
+
spec.authors = ["Barrie Callender"]
|
10
|
+
spec.email = ["barrie@callenb.org"]
|
16
11
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
spec.summary = "Calculates dates and durations whilst taking into account working and non-working periods down to a minute"
|
13
|
+
spec.description = "Calculates dates and durations whilst taking into account working and non-working times down to a minute. Business working time with holidays are a breeze."
|
14
|
+
spec.homepage = "http://workpattern.org"
|
15
|
+
spec.license = "MIT"
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
spec.metadata["homepage_url"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/callenb/workpattern"
|
20
|
+
spec.metadata["changelog_uri"] = "https://workpattern.org/2021/02/25/changelog.html"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.require_paths = ["lib"]
|
27
28
|
|
29
|
+
# Uncomment to register a new dependency of your gem
|
30
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
31
|
+
|
32
|
+
# For more information and examples about making a new gem, checkout our
|
33
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
34
|
+
spec.add_runtime_dependency 'tzinfo'
|
35
|
+
spec.add_runtime_dependency 'sorted_set' if RUBY_VERSION >= "2.4"
|
36
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workpattern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barrie Callender
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -25,33 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: sorted_set
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.9.2
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.9.2
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
31
|
+
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
38
|
+
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
40
|
+
version: '0'
|
55
41
|
description: Calculates dates and durations whilst taking into account working and
|
56
42
|
non-working times down to a minute. Business working time with holidays are a breeze.
|
57
43
|
email:
|
@@ -62,30 +48,33 @@ extra_rdoc_files: []
|
|
62
48
|
files:
|
63
49
|
- ".gitignore"
|
64
50
|
- ".travis.yml"
|
65
|
-
- CHANGELOG
|
51
|
+
- CHANGELOG.md
|
52
|
+
- CODE_OF_CONDUCT.md
|
66
53
|
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- LICENSE.txt
|
67
56
|
- README.md
|
68
57
|
- Rakefile
|
69
58
|
- lib/workpattern.rb
|
70
59
|
- lib/workpattern/clock.rb
|
71
|
-
- lib/workpattern/
|
60
|
+
- lib/workpattern/constants.rb
|
61
|
+
- lib/workpattern/day.rb
|
72
62
|
- lib/workpattern/version.rb
|
73
63
|
- lib/workpattern/week.rb
|
64
|
+
- lib/workpattern/week_pattern.rb
|
74
65
|
- lib/workpattern/workpattern.rb
|
75
66
|
- script/console
|
76
67
|
- script/destroy
|
77
68
|
- script/generate
|
78
69
|
- script/txt2html
|
79
|
-
- test/test_clock.rb
|
80
|
-
- test/test_helper.rb
|
81
|
-
- test/test_week.rb
|
82
|
-
- test/test_workpattern.rb
|
83
|
-
- test/test_workpattern_module.rb
|
84
70
|
- workpattern.gemspec
|
85
|
-
homepage: http://
|
71
|
+
homepage: http://workpattern.org
|
86
72
|
licenses:
|
87
73
|
- MIT
|
88
|
-
metadata:
|
74
|
+
metadata:
|
75
|
+
homepage_url: http://workpattern.org
|
76
|
+
source_code_uri: https://github.com/callenb/workpattern
|
77
|
+
changelog_uri: https://workpattern.org/2021/02/25/changelog.html
|
89
78
|
post_install_message:
|
90
79
|
rdoc_options: []
|
91
80
|
require_paths:
|
@@ -101,8 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
90
|
- !ruby/object:Gem::Version
|
102
91
|
version: '0'
|
103
92
|
requirements: []
|
104
|
-
|
105
|
-
rubygems_version: 2.6.7
|
93
|
+
rubygems_version: 3.0.9
|
106
94
|
signing_key:
|
107
95
|
specification_version: 4
|
108
96
|
summary: Calculates dates and durations whilst taking into account working and non-working
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Workpattern
|
2
|
-
# Mixins expected to be used in more than one class
|
3
|
-
#
|
4
|
-
# @since 0.2.0
|
5
|
-
#
|
6
|
-
# @private
|
7
|
-
module Base
|
8
|
-
# Holds local timezone info
|
9
|
-
@@tz = nil
|
10
|
-
|
11
|
-
# Converts a date like object into utc
|
12
|
-
#
|
13
|
-
def to_utc(date)
|
14
|
-
date.to_time.utc
|
15
|
-
end
|
16
|
-
# Converts a date like object into local time
|
17
|
-
#
|
18
|
-
def to_local(date)
|
19
|
-
date.to_time.getgm
|
20
|
-
end
|
21
|
-
|
22
|
-
# Retrieves the local timezone
|
23
|
-
def timezone
|
24
|
-
@@tz || @@tz = TZInfo::Timezone.get(Time.now.zone)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/test/test_clock.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestClock < MiniTest::Test #:nodoc:
|
4
|
-
def setup
|
5
|
-
end
|
6
|
-
|
7
|
-
def test_must_create_midnight_default
|
8
|
-
clock = Workpattern::Clock.new
|
9
|
-
|
10
|
-
assert_equal 0, clock.minutes, 'total default minutes'
|
11
|
-
assert_equal 0, clock.hour, 'default hour is zero'
|
12
|
-
assert_equal 0, clock.min, 'default minute is zero'
|
13
|
-
time = clock.time
|
14
|
-
assert time.is_a?(DateTime), 'must return a DateTime object'
|
15
|
-
assert_equal 0, time.hour, 'hour in the day must be zero'
|
16
|
-
assert_equal 0, time.min, 'minute in the day must be zero'
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_must_account_for_out_of_range_values
|
20
|
-
clock = Workpattern::Clock.new(27, 80)
|
21
|
-
|
22
|
-
assert_equal 1700, clock.minutes, 'total minutes'
|
23
|
-
assert_equal 4, clock.hour, 'hour is 4'
|
24
|
-
assert_equal 20, clock.min, 'minute is 20'
|
25
|
-
time = clock.time
|
26
|
-
assert time.is_a?(DateTime), 'must return a DateTime object'
|
27
|
-
assert_equal DateTime.new(1963, 6, 10, 4, 20), time
|
28
|
-
end
|
29
|
-
end
|
data/test/test_helper.rb
DELETED
data/test/test_week.rb
DELETED
@@ -1,532 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestWeek < MiniTest::Test #:nodoc:
|
4
|
-
include Workpattern::Base
|
5
|
-
def setup
|
6
|
-
start = Time.gm(2000, 1, 3)
|
7
|
-
finish = Time.gm(2000, 1, 9)
|
8
|
-
|
9
|
-
@w_week = Workpattern::Week.new(start, finish, 1)
|
10
|
-
|
11
|
-
@r_week = Workpattern::Week.new(start, finish, 0)
|
12
|
-
|
13
|
-
@p_week = Workpattern::Week.new(start, finish, 1)
|
14
|
-
@p_week.workpattern(:weekend, Workpattern.clock(0, 0),
|
15
|
-
Workpattern.clock(23, 59), 0)
|
16
|
-
@p_week.workpattern(:weekday, Workpattern.clock(0, 0),
|
17
|
-
Workpattern.clock(8, 59), 0)
|
18
|
-
@p_week.workpattern(:weekday, Workpattern.clock(12, 30),
|
19
|
-
Workpattern.clock(13, 0), 0)
|
20
|
-
@p_week.workpattern(:weekday, Workpattern.clock(17, 0),
|
21
|
-
Workpattern.clock(23, 59), 0)
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_must_create_a_w_week
|
25
|
-
start = Time.gm(2000, 1, 1, 11, 3)
|
26
|
-
finish = Time.gm(2005, 12, 31, 16, 41)
|
27
|
-
w_week = week(start, finish, 1)
|
28
|
-
assert_equal Time.gm(start.year, start.month, start.day),
|
29
|
-
w_week.start
|
30
|
-
assert_equal Time.gm(finish.year, finish.month, finish.day),
|
31
|
-
w_week.finish
|
32
|
-
assert_equal 3_156_480, w_week.total # 2192 days
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_create_w_week_of_3_concecutive_days
|
36
|
-
start = Time.gm(2000, 1, 2, 11, 3) # Sunday
|
37
|
-
finish = Time.gm(2000, 1, 4, 16, 41) # Tuesday
|
38
|
-
w_week = week(start, finish, 1)
|
39
|
-
assert_equal Time.gm(start.year, start.month,
|
40
|
-
start.day), w_week.start
|
41
|
-
assert_equal Time.gm(finish.year, finish.month, finish.day),
|
42
|
-
w_week.finish
|
43
|
-
assert_equal 1_440 * 3, w_week.total # 3 days
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_create_working_week_friday_to_sunday
|
47
|
-
start = Time.gm(2000, 1, 7, 11, 3) # Friday
|
48
|
-
finish = Time.gm(2000, 1, 9, 16, 41) # Sunday
|
49
|
-
w_week = week(start, finish, 1)
|
50
|
-
assert_equal Time.gm(start.year, start.month, start.day),
|
51
|
-
w_week.start
|
52
|
-
assert_equal Time.gm(finish.year, finish.month, finish.day),
|
53
|
-
w_week.finish
|
54
|
-
assert_equal 1_440 * 3, w_week.total # 3 days
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_create_working_week_thursday_to_sunday
|
58
|
-
start = Time.gm(2000, 1, 6, 11, 3) # Thursday
|
59
|
-
finish = Time.gm(2000, 1, 8, 16, 41) # Sunday
|
60
|
-
w_week = week(start, finish, 1)
|
61
|
-
assert_equal Time.gm(start.year, start.month, start.day),
|
62
|
-
w_week.start
|
63
|
-
assert_equal Time.gm(finish.year, finish.month, finish.day),
|
64
|
-
w_week.finish
|
65
|
-
assert_equal 1_440 * 3, w_week.total # 3 days
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_must_create_a_resting_week
|
69
|
-
start = Time.gm(2000, 1, 1, 11, 3)
|
70
|
-
finish = Time.gm(2005, 12, 31, 16, 41)
|
71
|
-
resting_week = week(start, finish, 0)
|
72
|
-
assert_equal Time.gm(start.year, start.month, start.day),
|
73
|
-
resting_week.start
|
74
|
-
assert_equal Time.gm(finish.year, finish.month, finish.day),
|
75
|
-
resting_week.finish
|
76
|
-
assert_equal 0, resting_week.total # 2192
|
77
|
-
assert_equal 0, resting_week.week_total
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_must_duplicate_all_of_a_week
|
81
|
-
start = Time.gm(2000, 1, 1, 11, 3)
|
82
|
-
finish = Time.gm(2005, 12, 31, 16, 41)
|
83
|
-
week = week(start, finish, 1)
|
84
|
-
new_week = week.duplicate
|
85
|
-
assert_equal Time.gm(start.year, start.month, start.day),
|
86
|
-
new_week.start
|
87
|
-
assert_equal Time.gm(finish.year, finish.month, finish.day),
|
88
|
-
new_week.finish
|
89
|
-
assert_equal 3_156_480, new_week.total # 2192
|
90
|
-
week.workpattern(:weekend, Workpattern.clock(0, 0),
|
91
|
-
Workpattern.clock(23, 59), 0)
|
92
|
-
assert_equal 3_156_480, new_week.total # 2192
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_must_set_week_pattern_correctly
|
96
|
-
start = Time.gm(2000, 1, 3)
|
97
|
-
finish = Time.gm(2000, 1, 9)
|
98
|
-
|
99
|
-
pattern_week = Workpattern::Week.new(start, finish, 1)
|
100
|
-
assert_equal start, pattern_week.start
|
101
|
-
assert_equal finish, pattern_week.finish
|
102
|
-
assert_equal 10_080, pattern_week.week_total
|
103
|
-
pattern_week.workpattern(:weekend, Workpattern.clock(0, 0),
|
104
|
-
Workpattern.clock(23, 59), 0)
|
105
|
-
assert_equal 7_200, pattern_week.week_total
|
106
|
-
pattern_week.workpattern(:weekday, Workpattern.clock(0, 0),
|
107
|
-
Workpattern.clock(8, 59), 0)
|
108
|
-
assert_equal 4_500, pattern_week.week_total
|
109
|
-
pattern_week.workpattern(:weekday, Workpattern.clock(12, 30),
|
110
|
-
Workpattern.clock(13, 0), 0)
|
111
|
-
assert_equal 4_345, pattern_week.week_total
|
112
|
-
pattern_week.workpattern(:weekday, Workpattern.clock(17, 0),
|
113
|
-
Workpattern.clock(23, 59), 0)
|
114
|
-
assert_equal 2_245, pattern_week.week_total
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_must_set_patterns_correctly
|
118
|
-
start = Time.gm(2000, 1, 1, 0, 0)
|
119
|
-
finish = Time.gm(2005, 12, 31, 8, 59)
|
120
|
-
w_week = week(start, finish, 1)
|
121
|
-
assert_equal 10_080, w_week.week_total
|
122
|
-
w_week.workpattern(:all, start, finish, 0)
|
123
|
-
assert_equal 6_300, w_week.week_total
|
124
|
-
w_week.workpattern(:sun, start, finish, 1)
|
125
|
-
assert_equal 6_840, w_week.week_total
|
126
|
-
w_week.workpattern(:mon, start, finish, 1)
|
127
|
-
assert_equal 7_380, w_week.week_total
|
128
|
-
w_week.workpattern(:all, clock(18, 0), clock(18, 19), 0)
|
129
|
-
assert_equal 7_240, w_week.week_total
|
130
|
-
w_week.workpattern(:all, clock(0, 0), clock(23, 59), 0)
|
131
|
-
assert_equal 0, w_week.week_total
|
132
|
-
w_week.workpattern(:all, clock(0, 0), clock(0, 0), 1)
|
133
|
-
assert_equal 7, w_week.week_total
|
134
|
-
w_week.workpattern(:all, clock(23, 59), clock(23, 59), 1)
|
135
|
-
assert_equal 14, w_week.week_total
|
136
|
-
w_week.workpattern(:all, clock(0, 0), clock(23, 59), 1)
|
137
|
-
assert_equal 10_080, w_week.week_total
|
138
|
-
w_week.workpattern(:weekend, clock(0, 0), clock(23, 59), 0)
|
139
|
-
assert_equal 7_200, w_week.week_total
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_must_add_minutes_in_a_w_week_result_in_same_day
|
143
|
-
r_date, r_duration, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31),
|
144
|
-
29)
|
145
|
-
assert_equal Time.gm(2000, 1, 3, 8, 0), r_date
|
146
|
-
refute m_flag
|
147
|
-
assert_equal 0, r_duration
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_must_add_minutes_in_a_w_week_result_in_next_day
|
151
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 990)
|
152
|
-
assert_equal Time.gm(2000, 1, 4, 0, 1), r_date
|
153
|
-
refute m_flag
|
154
|
-
assert_equal 0, r_dur
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_must_add_minutes_in_a_w_week_result_in_later_day
|
158
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 2430)
|
159
|
-
assert_equal Time.gm(2000, 1, 5, 0, 1), r_date
|
160
|
-
refute m_flag
|
161
|
-
assert_equal 0, r_dur
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_must_add_minutes_in_a_w_week_result_in_start_next_day
|
165
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 989)
|
166
|
-
assert_equal Time.gm(2000, 1, 4, 0, 0), r_date
|
167
|
-
refute m_flag
|
168
|
-
assert_equal 0, r_dur
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_must_add_0_minutes_in_a_w_week
|
172
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 0)
|
173
|
-
assert_equal Time.gm(2000, 1, 3, 7, 31), r_date
|
174
|
-
refute m_flag
|
175
|
-
assert_equal 0, r_dur
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_must_add_too_many_minutes_in_a_w_week
|
179
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 3, 7, 31), 9630)
|
180
|
-
assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
|
181
|
-
refute m_flag
|
182
|
-
assert_equal 1, r_dur
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_must_add_minutes_in_a_resting_week
|
186
|
-
r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 3, 7, 31), 29)
|
187
|
-
assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
|
188
|
-
refute m_flag
|
189
|
-
assert_equal 29, r_dur
|
190
|
-
end
|
191
|
-
|
192
|
-
def test_must_add_minutes_from_start_of_resting_week
|
193
|
-
r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 3, 0, 0), 990)
|
194
|
-
assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
|
195
|
-
refute m_flag
|
196
|
-
assert_equal 990, r_dur
|
197
|
-
end
|
198
|
-
|
199
|
-
def test_must_add_minutes_to_last_minute_of_a_resting_week
|
200
|
-
r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 9, 23, 59), 2430)
|
201
|
-
assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
|
202
|
-
refute m_flag
|
203
|
-
assert_equal 2_430, r_dur
|
204
|
-
end
|
205
|
-
|
206
|
-
def test_must_add_zero_minutes_in_a_resting_week
|
207
|
-
r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 3, 7, 31), 0)
|
208
|
-
assert_equal Time.gm(2000, 1, 3, 7, 31), r_date
|
209
|
-
refute m_flag
|
210
|
-
assert_equal 0, r_dur
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_must_add_minutes_from_working_in_a_pattern_week_result_in_same_day
|
214
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 110)
|
215
|
-
assert_equal Time.gm(2000, 1, 3, 12, 1), r_date
|
216
|
-
refute m_flag
|
217
|
-
assert_equal 0, r_dur
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_must_add_minutes_from_resting_in_a_pattern_week_result_in_same_day
|
221
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 12, 45), 126)
|
222
|
-
assert_equal Time.gm(2000, 1, 3, 15, 7), r_date
|
223
|
-
refute m_flag
|
224
|
-
assert_equal 0, r_dur
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_must_add_minutes_from_working_in_a_pattern_week_result_in_next_day
|
228
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 379)
|
229
|
-
assert_equal Time.gm(2000, 1, 4, 9, 1), r_date
|
230
|
-
refute m_flag
|
231
|
-
assert_equal 0, r_dur
|
232
|
-
end
|
233
|
-
|
234
|
-
def test_must_add_minutes_from_resting_in_a_pattern_week_result_in_next_day
|
235
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 12, 45), 240)
|
236
|
-
assert_equal Time.gm(2000, 1, 4, 9, 1), r_date
|
237
|
-
refute m_flag
|
238
|
-
assert_equal 0, r_dur
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_must_add_minutes_from_working_in_a_pattern_week_result_in_later_day
|
242
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 828)
|
243
|
-
assert_equal Time.gm(2000, 1, 5, 9, 1), r_date
|
244
|
-
refute m_flag
|
245
|
-
assert_equal 0, r_dur
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_must_add_minutes_from_resting_in_a_w_week_result_in_later_day
|
249
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 12, 45), 689)
|
250
|
-
assert_equal Time.gm(2000, 1, 5, 9, 1), r_date
|
251
|
-
refute m_flag
|
252
|
-
assert_equal 0, r_dur
|
253
|
-
end
|
254
|
-
|
255
|
-
def test_must_add_0_minutes_from_working_in_a_resting_week
|
256
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 0)
|
257
|
-
assert_equal Time.gm(2000, 1, 3, 10, 11), r_date
|
258
|
-
refute m_flag
|
259
|
-
assert_equal 0, r_dur
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_must_add_0_minutes_from_resting_in_a_resting_week
|
263
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 12, 45), 0)
|
264
|
-
assert_equal Time.gm(2000, 1, 3, 12, 45), r_date
|
265
|
-
refute m_flag
|
266
|
-
assert_equal 0, r_dur
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_must_add_too_many_minutes_in_a_pattern__week
|
270
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 3, 10, 11), 2175)
|
271
|
-
assert_equal Time.gm(2000, 1, 10, 0, 0), r_date
|
272
|
-
refute m_flag
|
273
|
-
assert_equal 1, r_dur
|
274
|
-
end
|
275
|
-
|
276
|
-
def test_must_subtract_minutes_in_a_w_week_result_in_same_day
|
277
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -29)
|
278
|
-
assert_equal Time.gm(2000, 1, 8, 7, 2), r_date
|
279
|
-
refute m_flag
|
280
|
-
assert_equal 0, r_dur
|
281
|
-
end
|
282
|
-
|
283
|
-
def test_must_subtract_minutes_in_a_w_week_result_in_previous_day
|
284
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -452)
|
285
|
-
assert_equal Time.gm(2000, 1, 7, 23, 59), r_date
|
286
|
-
refute m_flag
|
287
|
-
assert_equal 0, r_dur
|
288
|
-
end
|
289
|
-
|
290
|
-
def test_must_subtract_minutes_in_a_w_week_result_in_earlier_day
|
291
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -1892)
|
292
|
-
assert_equal Time.gm(2000, 1, 6, 23, 59), r_date
|
293
|
-
refute m_flag
|
294
|
-
assert_equal 0, r_dur
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_must_subtract_minutes_in_a_w_week_result_at_start_of_day
|
298
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -451)
|
299
|
-
assert_equal Time.gm(2000, 1, 8, 0, 0), r_date
|
300
|
-
refute m_flag
|
301
|
-
assert_equal 0, r_dur
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_must_subtract_minutes_in_a_w_week_result_at_start_of_previous_day
|
305
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -1891)
|
306
|
-
assert_equal Time.gm(2000, 1, 7, 0, 0), r_date
|
307
|
-
refute m_flag
|
308
|
-
assert_equal 0, r_dur
|
309
|
-
end
|
310
|
-
|
311
|
-
def test_must_subtract_too_many_minutes_from_a_w_week
|
312
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 8, 7, 31), -7652)
|
313
|
-
assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
|
314
|
-
assert m_flag
|
315
|
-
assert_equal -1, r_dur
|
316
|
-
end
|
317
|
-
|
318
|
-
def test_must_subtract_1_minute_from_start_of_next_day_after_w_week
|
319
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 9, 0, 0), -1, true)
|
320
|
-
assert_equal Time.gm(2000, 1, 9, 23, 59), r_date
|
321
|
-
refute m_flag
|
322
|
-
assert_equal 0, r_dur
|
323
|
-
end
|
324
|
-
|
325
|
-
def test_must_subtract_2_minutes_from_start_of_next_day_after_w_week
|
326
|
-
r_date, r_dur, m_flag = @w_week.calc(Time.gm(2000, 1, 9, 0, 0), -2, true)
|
327
|
-
assert_equal Time.gm(2000, 1, 9, 23, 58), r_date
|
328
|
-
refute m_flag
|
329
|
-
assert_equal 0, r_dur
|
330
|
-
end
|
331
|
-
|
332
|
-
def test_must_subtract_minutes_from_last_day_in_a_resting_week
|
333
|
-
r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 10, 7, 31), -29)
|
334
|
-
assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
|
335
|
-
assert m_flag
|
336
|
-
assert_equal -29, r_dur
|
337
|
-
end
|
338
|
-
|
339
|
-
def test_must_subtract_minutes_from_middle_day_in_a_resting_week
|
340
|
-
r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 8, 7, 31), -452)
|
341
|
-
assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
|
342
|
-
assert m_flag
|
343
|
-
assert_equal -452, r_dur
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_must_subtract_minutes_from_start_of_resting_week
|
347
|
-
r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 3, 0, 0), -1892)
|
348
|
-
assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
|
349
|
-
assert m_flag
|
350
|
-
assert_equal -1_892, r_dur
|
351
|
-
end
|
352
|
-
|
353
|
-
def test_must_subtract_minutes_from_start_of_next_day_after_resting_week
|
354
|
-
r_date, r_dur, m_flag = @r_week.calc(Time.gm(2000, 1, 9, 0, 0), -1, true)
|
355
|
-
assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
|
356
|
-
assert m_flag
|
357
|
-
assert_equal -1, r_dur
|
358
|
-
end
|
359
|
-
|
360
|
-
def test_must_subtract_minutes_from_resting_day_in_a_pattern_week
|
361
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 8, 13, 29), -29)
|
362
|
-
assert_equal Time.gm(2000, 1, 7, 16, 31), r_date
|
363
|
-
refute m_flag
|
364
|
-
assert_equal 0, r_dur
|
365
|
-
end
|
366
|
-
|
367
|
-
def test_must_subtract_minutes_from_working_day_in_a_pattern_week
|
368
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 13, 29), -29)
|
369
|
-
assert_equal Time.gm(2000, 1, 7, 12, 29), r_date
|
370
|
-
refute m_flag
|
371
|
-
assert_equal 0, r_dur
|
372
|
-
end
|
373
|
-
|
374
|
-
def test_must_subtract_minutes_in_a_pattern_week_result_in_previous_day
|
375
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 9, 1), -2)
|
376
|
-
assert_equal Time.gm(2000, 1, 6, 16, 59), r_date
|
377
|
-
refute m_flag
|
378
|
-
assert_equal 0, r_dur
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_must_subtract_minutes_in_a_pattern_week_result_in_earlier_day
|
382
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 13, 29), -240)
|
383
|
-
assert_equal Time.gm(2000, 1, 6, 16, 58), r_date
|
384
|
-
refute m_flag
|
385
|
-
assert_equal 0, r_dur
|
386
|
-
end
|
387
|
-
|
388
|
-
def test_must_subtract_minutes_in_a_pattern_week_result_at_start_of_day
|
389
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 13, 29), -238)
|
390
|
-
assert_equal Time.gm(2000, 1, 7, 9, 0), r_date
|
391
|
-
refute m_flag
|
392
|
-
assert_equal 0, r_dur
|
393
|
-
end
|
394
|
-
|
395
|
-
def test_must_subtract_minutes_in_a_pattern_week_result_at_start_of_prev_day
|
396
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 13, 29), -687)
|
397
|
-
assert_equal Time.gm(2000, 1, 6, 9, 0), r_date
|
398
|
-
refute m_flag
|
399
|
-
assert_equal 0, r_dur
|
400
|
-
end
|
401
|
-
|
402
|
-
def test_must_subtract_too_many_minutes_from_a_pattern_week
|
403
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 7, 9, 0), -1797)
|
404
|
-
assert_equal Time.gm(2000, 1, 2, 0, 0), r_date
|
405
|
-
assert m_flag
|
406
|
-
assert_equal -1, r_dur
|
407
|
-
end
|
408
|
-
|
409
|
-
def test_must_subtract_1_minute_from_start_of_next_day_after_pattern_week
|
410
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 9, 0, 0), -1, true)
|
411
|
-
assert_equal Time.gm(2000, 1, 7, 16, 59), r_date
|
412
|
-
refute m_flag
|
413
|
-
assert_equal 0, r_dur
|
414
|
-
end
|
415
|
-
|
416
|
-
def test_must_subtract_2_minutes_from_start_of_next_day_after_pattern_week
|
417
|
-
r_date, r_dur, m_flag = @p_week.calc(Time.gm(2000, 1, 9, 0, 0), -2, true)
|
418
|
-
assert_equal Time.gm(2000, 1, 7, 16, 58), r_date
|
419
|
-
refute m_flag
|
420
|
-
assert_equal 0, r_dur
|
421
|
-
end
|
422
|
-
|
423
|
-
def must_diff_day_week_day_in_patterned_week
|
424
|
-
start = Time.gm(2013, 9, 23, 0, 0)
|
425
|
-
finish = Time.gm(2013, 10, 20, 23, 59)
|
426
|
-
w_week = week(start, finish, 1)
|
427
|
-
w_week.workpattern :all, Workpattern.clock(0, 0),
|
428
|
-
Workpattern.clock(8, 59), 0
|
429
|
-
w_week.workpattern :all, Workpattern.clock(12, 0),
|
430
|
-
Workpattern.clock(12, 59), 0
|
431
|
-
w_week.workpattern :all, Workpattern.clock(18, 0),
|
432
|
-
Workpattern.clock(23, 59), 0
|
433
|
-
s_date = Time.gm(2013, 10, 3, 16, 0)
|
434
|
-
f_date = Time.gm(2013, 10, 15, 12, 30)
|
435
|
-
duration, start = w_week.diff(s_date, f_date)
|
436
|
-
|
437
|
-
assert_equal 5_640, duration
|
438
|
-
assert_equal Time.gm(2013, 10, 15, 12, 30), start
|
439
|
-
end
|
440
|
-
|
441
|
-
def test_must_calculate_difference_between_dates_in_w_week
|
442
|
-
late_date = Time.gm(2000, 1, 6, 9, 32)
|
443
|
-
early_date = Time.gm(2000, 1, 6, 8, 20)
|
444
|
-
result_dur, r_date = @w_week.diff(early_date, late_date)
|
445
|
-
assert_equal 72, result_dur
|
446
|
-
assert_equal late_date, r_date
|
447
|
-
end
|
448
|
-
|
449
|
-
def test_must_calculate_difference_between_dates_in_resting_week
|
450
|
-
late_date = Time.gm(2000, 1, 6, 9, 32)
|
451
|
-
early_date = Time.gm(2000, 1, 6, 8, 20)
|
452
|
-
result_dur, r_date = @r_week.diff(early_date, late_date)
|
453
|
-
assert_equal 0, result_dur
|
454
|
-
assert_equal late_date, r_date
|
455
|
-
end
|
456
|
-
|
457
|
-
def test_must_calculate_difference_between_dates_in_pattern_week
|
458
|
-
late_date = Time.gm(2000, 1, 6, 13, 1)
|
459
|
-
early_date = Time.gm(2000, 1, 6, 12, 29)
|
460
|
-
result_dur, r_date = @p_week.diff(early_date, late_date)
|
461
|
-
assert_equal 1, result_dur
|
462
|
-
assert_equal late_date, r_date
|
463
|
-
end
|
464
|
-
|
465
|
-
def test_must_diff_from_last_day_of_patterned_week
|
466
|
-
# #issue 15
|
467
|
-
start = Time.gm(2013, 9, 23, 0, 0)
|
468
|
-
finish = Time.gm(2013, 9, 26, 23, 59)
|
469
|
-
w_week = week(start, finish, 1)
|
470
|
-
w_week.workpattern :all, Workpattern.clock(0, 0),
|
471
|
-
Workpattern.clock(8, 59), 0
|
472
|
-
w_week.workpattern :all, Workpattern.clock(12, 0),
|
473
|
-
Workpattern.clock(12, 59), 0
|
474
|
-
w_week.workpattern :all, Workpattern.clock(18, 0),
|
475
|
-
Workpattern.clock(23, 59), 0
|
476
|
-
|
477
|
-
s_date = Time.gm(2013, 9, 26, 17, 0)
|
478
|
-
f_date = Time.gm(2013, 9, 27, 10, 0)
|
479
|
-
duration, start = w_week.diff(s_date, f_date)
|
480
|
-
|
481
|
-
assert_equal 60, duration
|
482
|
-
assert_equal Time.gm(2013, 9, 27, 0, 0), start
|
483
|
-
end
|
484
|
-
|
485
|
-
def test_must_diff_long_distances_beyond_end_of_patterned_week
|
486
|
-
start = Time.gm(2013, 9, 23, 0, 0)
|
487
|
-
finish = Time.gm(2013, 10, 20, 23, 59)
|
488
|
-
w_week = week(start, finish, 1)
|
489
|
-
w_week.workpattern :all, Workpattern.clock(0, 0),
|
490
|
-
Workpattern.clock(8, 59), 0
|
491
|
-
w_week.workpattern :all, Workpattern.clock(12, 0),
|
492
|
-
Workpattern.clock(12, 59), 0
|
493
|
-
w_week.workpattern :all, Workpattern.clock(18, 0),
|
494
|
-
Workpattern.clock(23, 59), 0
|
495
|
-
|
496
|
-
s_date = Time.gm(2013, 9, 26, 17, 0)
|
497
|
-
f_date = Time.gm(2018, 9, 27, 10, 0)
|
498
|
-
duration, start = w_week.diff(s_date, f_date)
|
499
|
-
|
500
|
-
assert_equal 11_580, duration
|
501
|
-
assert_equal Time.gm(2013, 10, 21, 0, 0), start
|
502
|
-
end
|
503
|
-
|
504
|
-
def test_must_diff_long_distances_within_patterned_week
|
505
|
-
start = Time.gm(2013, 9, 23, 0, 0)
|
506
|
-
finish = Time.gm(2013, 10, 20, 23, 59)
|
507
|
-
w_week = week(start, finish, 1)
|
508
|
-
w_week.workpattern :all, Workpattern.clock(0, 0),
|
509
|
-
Workpattern.clock(8, 59), 0
|
510
|
-
w_week.workpattern :all, Workpattern.clock(12, 0),
|
511
|
-
Workpattern.clock(12, 59), 0
|
512
|
-
w_week.workpattern :all, Workpattern.clock(18, 0),
|
513
|
-
Workpattern.clock(23, 59), 0
|
514
|
-
|
515
|
-
s_date = Time.gm(2013, 9, 26, 17, 0)
|
516
|
-
f_date = Time.gm(2013, 10, 15, 10, 0)
|
517
|
-
duration, start = w_week.diff(s_date, f_date)
|
518
|
-
|
519
|
-
assert_equal 8_760, duration
|
520
|
-
assert_equal Time.gm(2013, 10, 15, 10, 0), start
|
521
|
-
end
|
522
|
-
|
523
|
-
private
|
524
|
-
|
525
|
-
def week(start, finish, type)
|
526
|
-
Workpattern::Week.new(start, finish, type)
|
527
|
-
end
|
528
|
-
|
529
|
-
def clock(hour, min)
|
530
|
-
Workpattern.clock(hour, min)
|
531
|
-
end
|
532
|
-
end
|