workpattern 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/CHANGELOG +6 -0
- data/Gemfile.lock +2 -2
- data/lib/workpattern/day.rb +21 -21
- data/lib/workpattern/hour.rb +35 -35
- data/lib/workpattern/version.rb +1 -1
- data/lib/workpattern/workpattern.rb +29 -9
- data/script/console +0 -0
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- data/test/test_hour.rb +32 -32
- metadata +5 -10
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YWVlYjQ0YTY1NzVhMzRjN2QzZWZkNzZjZTBmOTM4ODAyNjFmZDFiYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NjBhMzUyNWZkYWYzMzk3ZmIyN2ZlNTM1ZjcwMGQ5YjZjM2QwYzFlNA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDllNzljYmEyMzBiMjY3ZDIwYWNhMWE0YWQwNWUxNTMxZGQ3ZDQzNTdmNGU2
|
10
|
+
YWI1OGYwNDZiOTU2NWViZWZmYjRkZmQzY2I5NDg1ODhmNjhjOGUyYjUwMDFh
|
11
|
+
MzllYTIwNGQ3ODY4NTMxNWNmZTk1MDEwNjU2ZTlmNjliNjU2M2Y=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjgwZmM2ZTU1YjE0MzhkYTVkYzU2MTU0YmRhOWZkYzIyZDdhNzZmNmY0MWI3
|
14
|
+
OWNkN2MwNmMzOWIxYjg1ODE5MDM3MzFhYWIzMTJjOTMwMjMwMzlkMWViZWU0
|
15
|
+
MTMzYWFmMzRiZWEzMzA1NmE3YTllMTBhMmJlMzA3ZmJkYWQ0YTg=
|
data/.gitignore
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## Workpattern v0.3.2 (Mar 14, 2013) ##
|
2
|
+
|
3
|
+
* Changed methods on Hour module so as to not clash with Rails (#10) * Barrie Callender *
|
4
|
+
* Applied DRY principle to workpattern method in Workpattern class * Barrie Callender *
|
5
|
+
* Removed file from emacs backup * Barrie Callender *
|
6
|
+
|
1
7
|
## Workpattern v0.3.1 (Oct 14, 2012) ##
|
2
8
|
|
3
9
|
* RDOC documentation not right on rubydoc.info (#5) * Barrie Callender *
|
data/Gemfile.lock
CHANGED
data/lib/workpattern/day.rb
CHANGED
@@ -74,17 +74,17 @@ module Workpattern
|
|
74
74
|
def workpattern(start_time,finish_time,type)
|
75
75
|
|
76
76
|
if start_time.hour==finish_time.hour
|
77
|
-
@values[start_time.hour]=@values[start_time.hour].
|
77
|
+
@values[start_time.hour]=@values[start_time.hour].wp_workpattern(start_time.min,finish_time.min,type)
|
78
78
|
else
|
79
79
|
test_hour=start_time.hour
|
80
|
-
@values[test_hour]=@values[test_hour].
|
80
|
+
@values[test_hour]=@values[test_hour].wp_workpattern(start_time.min,59,type)
|
81
81
|
|
82
82
|
while ((test_hour+1)<finish_time.hour)
|
83
83
|
test_hour+=1
|
84
|
-
@values[test_hour]=@values[test_hour].
|
84
|
+
@values[test_hour]=@values[test_hour].wp_workpattern(0,59,type)
|
85
85
|
end
|
86
86
|
|
87
|
-
@values[finish_time.hour]=@values[finish_time.hour].
|
87
|
+
@values[finish_time.hour]=@values[finish_time.hour].wp_workpattern(0,finish_time.min,type)
|
88
88
|
end
|
89
89
|
set_attributes
|
90
90
|
end
|
@@ -166,15 +166,15 @@ module Workpattern
|
|
166
166
|
end
|
167
167
|
|
168
168
|
if (start_hour==finish_hour)
|
169
|
-
retval=@values[start_hour].
|
169
|
+
retval=@values[start_hour].wp_minutes(start_min,finish_min)
|
170
170
|
else
|
171
171
|
|
172
|
-
retval=@values[start_hour].
|
172
|
+
retval=@values[start_hour].wp_minutes(start_min,59)
|
173
173
|
while (start_hour+1<finish_hour)
|
174
|
-
retval+=@values[start_hour+1].
|
174
|
+
retval+=@values[start_hour+1].wp_total
|
175
175
|
start_hour+=1
|
176
176
|
end
|
177
|
-
retval+=@values[finish_hour].
|
177
|
+
retval+=@values[finish_hour].wp_minutes(0,finish_min)
|
178
178
|
end
|
179
179
|
|
180
180
|
return retval
|
@@ -191,11 +191,11 @@ module Workpattern
|
|
191
191
|
@last_min=nil
|
192
192
|
@total=0
|
193
193
|
0.upto(@hours-1) {|index|
|
194
|
-
@first_hour=index if ((@first_hour.nil?) && (@values[index].
|
195
|
-
@first_min=@values[index].
|
196
|
-
@last_hour=index if (@values[index].
|
197
|
-
@last_min=@values[index].
|
198
|
-
@total+=@values[index].
|
194
|
+
@first_hour=index if ((@first_hour.nil?) && (@values[index].wp_total!=0))
|
195
|
+
@first_min=@values[index].wp_first if ((@first_min.nil?) && (!@values[index].wp_first.nil?))
|
196
|
+
@last_hour=index if (@values[index].wp_total!=0)
|
197
|
+
@last_min=@values[index].wp_last if (@values[index].wp_total!=0)
|
198
|
+
@total+=@values[index].wp_total
|
199
199
|
}
|
200
200
|
end
|
201
201
|
|
@@ -247,17 +247,17 @@ module Workpattern
|
|
247
247
|
duration=0
|
248
248
|
time=first_working_minute(time)
|
249
249
|
else
|
250
|
-
minutes_this_hour=@values[time.hour].
|
250
|
+
minutes_this_hour=@values[time.hour].wp_minutes(0,time.min-1)
|
251
251
|
this_hour=time.hour
|
252
252
|
until (duration==0)
|
253
253
|
if (minutes_this_hour<duration.abs)
|
254
254
|
duration+=minutes_this_hour
|
255
255
|
time = time - (MINUTE*time.min) - HOUR
|
256
256
|
this_hour-=1
|
257
|
-
minutes_this_hour=@values[this_hour].
|
257
|
+
minutes_this_hour=@values[this_hour].wp_total
|
258
258
|
else
|
259
259
|
next_hour=(time.min==0)
|
260
|
-
time,duration=@values[this_hour].
|
260
|
+
time,duration=@values[this_hour].wp_calc(time,duration, next_hour)
|
261
261
|
end
|
262
262
|
end
|
263
263
|
end
|
@@ -279,9 +279,9 @@ module Workpattern
|
|
279
279
|
result_date= time.next_day - (HOUR*time.hour) - (MINUTE*time.min)
|
280
280
|
duration = duration - available_minutes
|
281
281
|
else
|
282
|
-
total=@values[time.hour].
|
282
|
+
total=@values[time.hour].wp_minutes(time.min,59)
|
283
283
|
if (total==duration) # this hour satisfies
|
284
|
-
result_date=time - (MINUTE*time.min) + (MINUTE*@values[time.hour].
|
284
|
+
result_date=time - (MINUTE*time.min) + (MINUTE*@values[time.hour].wp_last) + MINUTE
|
285
285
|
duration = 0
|
286
286
|
else
|
287
287
|
result_date = time
|
@@ -290,9 +290,9 @@ module Workpattern
|
|
290
290
|
duration-=total
|
291
291
|
result_date=result_date + HOUR - (MINUTE*result_date.min)
|
292
292
|
else
|
293
|
-
result_date,duration=@values[result_date.hour].
|
293
|
+
result_date,duration=@values[result_date.hour].wp_calc(result_date,duration)
|
294
294
|
end
|
295
|
-
total=@values[result_date.hour].
|
295
|
+
total=@values[result_date.hour].wp_total
|
296
296
|
end
|
297
297
|
end
|
298
298
|
end
|
@@ -317,7 +317,7 @@ module Workpattern
|
|
317
317
|
# @return [Integer] number of remaining working minutes
|
318
318
|
#
|
319
319
|
def minutes_left_in_hour(start)
|
320
|
-
return @values[start.hour].
|
320
|
+
return @values[start.hour].wp_diff(start.min,60)
|
321
321
|
end
|
322
322
|
|
323
323
|
end
|
data/lib/workpattern/hour.rb
CHANGED
@@ -10,8 +10,8 @@ module Workpattern
|
|
10
10
|
#
|
11
11
|
# @return [Integer] working minutes in the hour
|
12
12
|
#
|
13
|
-
def
|
14
|
-
return
|
13
|
+
def wp_total
|
14
|
+
return wp_minutes(0,59)
|
15
15
|
end
|
16
16
|
|
17
17
|
# Sets the minutes to either working (type=1) or resting (type=0)
|
@@ -20,17 +20,17 @@ module Workpattern
|
|
20
20
|
# @param [Integer] finish minute at end of range
|
21
21
|
# @param [Integer] type defines whether working (1) or resting (0)
|
22
22
|
#
|
23
|
-
def
|
24
|
-
return
|
25
|
-
return
|
23
|
+
def wp_workpattern(start,finish,type)
|
24
|
+
return wp_working(start,finish) if type==1
|
25
|
+
return wp_resting(start,finish) if type==0
|
26
26
|
end
|
27
27
|
|
28
28
|
# Returns the first working minute in the hour or 60 if there are no working minutes
|
29
29
|
#
|
30
30
|
# @return [Integer] first working minute or 60 if none found
|
31
31
|
#
|
32
|
-
def
|
33
|
-
0.upto(59) {|minute| return minute if self.
|
32
|
+
def wp_first
|
33
|
+
0.upto(59) {|minute| return minute if self.wp_minutes(minute,minute)==1}
|
34
34
|
return nil
|
35
35
|
end
|
36
36
|
|
@@ -38,8 +38,8 @@ module Workpattern
|
|
38
38
|
#
|
39
39
|
# @return [Integer] last working minute or nil if none found
|
40
40
|
#
|
41
|
-
def
|
42
|
-
59.downto(0) {|minute| return minute if self.
|
41
|
+
def wp_last
|
42
|
+
59.downto(0) {|minute| return minute if self.wp_minutes(minute,minute)==1}
|
43
43
|
return nil
|
44
44
|
end
|
45
45
|
|
@@ -48,8 +48,8 @@ module Workpattern
|
|
48
48
|
# @param [Integer] start is the minute being tested
|
49
49
|
# @return [Boolean] true if minute is working, otherwise false
|
50
50
|
#
|
51
|
-
def
|
52
|
-
return true if
|
51
|
+
def wp_working?(start)
|
52
|
+
return true if wp_minutes(start,start)==1
|
53
53
|
return false
|
54
54
|
end
|
55
55
|
|
@@ -59,9 +59,9 @@ module Workpattern
|
|
59
59
|
# @param [Integer] finish last minute in range
|
60
60
|
# @return [Integer] number of minutes from <tt>start</tt> to <tt>finish</tt> inclusive
|
61
61
|
#
|
62
|
-
def
|
62
|
+
def wp_minutes(start,finish)
|
63
63
|
start,finish=finish,start if start > finish
|
64
|
-
return (self &
|
64
|
+
return (self & wp_mask(start,finish)).to_s(2).count('1')
|
65
65
|
end
|
66
66
|
|
67
67
|
# Returns the DateTime and remainding minutes when adding a duration to a minute in the hour.
|
@@ -72,12 +72,12 @@ module Workpattern
|
|
72
72
|
# @param [Boolean] next_hour used in subtraction to specify the starting point as midnight (00:00 the next day)
|
73
73
|
# @return [DateTime,Integer,Boolean] The <tt>DateTime</tt> calculated along with remaining minutes and a flag indicating if starting point is next hour
|
74
74
|
#
|
75
|
-
def
|
75
|
+
def wp_calc(time,duration,next_hour=false)
|
76
76
|
|
77
77
|
if (duration<0)
|
78
|
-
return
|
78
|
+
return wp_subtract(time,duration, next_hour)
|
79
79
|
elsif (duration>0)
|
80
|
-
return
|
80
|
+
return wp_add(time,duration)
|
81
81
|
else
|
82
82
|
return time,duration
|
83
83
|
end
|
@@ -88,10 +88,10 @@ module Workpattern
|
|
88
88
|
# @param [Integer] finish last minute in range
|
89
89
|
# @return [Integer] number of working minutes in the range
|
90
90
|
#
|
91
|
-
def
|
91
|
+
def wp_diff(start,finish)
|
92
92
|
start,finish=finish,start if start > finish
|
93
93
|
return 0 if start==finish
|
94
|
-
return (self &
|
94
|
+
return (self & wp_mask(start,finish-1)).to_s(2).count('1')
|
95
95
|
end
|
96
96
|
|
97
97
|
private
|
@@ -101,8 +101,8 @@ module Workpattern
|
|
101
101
|
# @param [Integer] start is first minute in the range
|
102
102
|
# @param [Integer] finish is last minute in the range
|
103
103
|
#
|
104
|
-
def
|
105
|
-
return self |
|
104
|
+
def wp_working(start,finish)
|
105
|
+
return self | wp_mask(start,finish)
|
106
106
|
end
|
107
107
|
|
108
108
|
# sets a resting pattern
|
@@ -110,8 +110,8 @@ module Workpattern
|
|
110
110
|
# @param [Integer] start is first minute in the range
|
111
111
|
# @param [Integer] finish is last minute in the range
|
112
112
|
#
|
113
|
-
def
|
114
|
-
return self & ((2**60-1)-
|
113
|
+
def wp_resting(start,finish)
|
114
|
+
return self & ((2**60-1)-wp_mask(start,finish))
|
115
115
|
end
|
116
116
|
|
117
117
|
# Creates a bit mask of 1's over the specified range
|
@@ -119,7 +119,7 @@ module Workpattern
|
|
119
119
|
# @param [Integer] start is first minute in the range
|
120
120
|
# @param [Integer] finish is the last minute in the range
|
121
121
|
#
|
122
|
-
def
|
122
|
+
def wp_mask(start,finish)
|
123
123
|
return ((2**(finish+1)-1)-(2**start-1))
|
124
124
|
end
|
125
125
|
|
@@ -129,9 +129,9 @@ module Workpattern
|
|
129
129
|
# @param [Integer] duration is the number of minutes to add and can be negative (subtraction)
|
130
130
|
# @return [DateTime, Integer] The resulting DateTime and any remaining minutes
|
131
131
|
#
|
132
|
-
def
|
132
|
+
def wp_add(time,duration)
|
133
133
|
start = time.min
|
134
|
-
available_minutes=
|
134
|
+
available_minutes=wp_minutes(start,59)
|
135
135
|
|
136
136
|
if ((duration-available_minutes)>=0)
|
137
137
|
result_date = time + HOUR - (MINUTE*start)
|
@@ -139,15 +139,15 @@ module Workpattern
|
|
139
139
|
elsif ((duration-available_minutes)==0)
|
140
140
|
result_date = time - (MINUTE*start) + last + 1
|
141
141
|
result_remainder = 0
|
142
|
-
elsif (
|
142
|
+
elsif (wp_minutes(start,start+duration-1)==duration)
|
143
143
|
result_date = time + (MINUTE*duration)
|
144
144
|
result_remainder = 0
|
145
145
|
else
|
146
146
|
step = start + duration
|
147
|
-
duration-=
|
147
|
+
duration-=wp_minutes(start,step)
|
148
148
|
until (duration==0)
|
149
149
|
step+=1
|
150
|
-
duration-=
|
150
|
+
duration-=wp_minutes(step,step)
|
151
151
|
end
|
152
152
|
step+=1
|
153
153
|
result_date = time + (MINUTE*step)
|
@@ -162,31 +162,31 @@ module Workpattern
|
|
162
162
|
# @param [Boolean] next_hour indicates if the 59th second is the first one to be included
|
163
163
|
# @return [DateTime, Integer] The resulting DateTime and any remaining minutes
|
164
164
|
#
|
165
|
-
def
|
165
|
+
def wp_subtract(time,duration,next_hour)
|
166
166
|
if next_hour
|
167
|
-
if
|
167
|
+
if wp_working?(59)
|
168
168
|
duration+=1
|
169
169
|
time=time+(MINUTE*59)
|
170
|
-
return
|
170
|
+
return wp_calc(time,duration)
|
171
171
|
end
|
172
172
|
else
|
173
173
|
start=time.min
|
174
174
|
available_minutes=0
|
175
|
-
available_minutes =
|
175
|
+
available_minutes = wp_minutes(0,start-1) if start > 0
|
176
176
|
end
|
177
177
|
|
178
178
|
if ((duration + available_minutes)<=0)
|
179
179
|
result_date = time - (MINUTE*start)
|
180
180
|
result_remainder = duration+available_minutes
|
181
|
-
elsif (
|
181
|
+
elsif (wp_minutes(start+duration,start-1)==duration.abs)
|
182
182
|
result_date = time + (MINUTE*duration)
|
183
183
|
result_remainder = 0
|
184
184
|
else
|
185
185
|
step = start + duration
|
186
|
-
duration+=
|
186
|
+
duration+=wp_minutes(step,start-1)
|
187
187
|
until (duration==0)
|
188
188
|
step-=1
|
189
|
-
duration+=
|
189
|
+
duration+=wp_minutes(step,step)
|
190
190
|
end
|
191
191
|
result_date = time - (MINUTE * (start-step))
|
192
192
|
result_remainder = 0
|
data/lib/workpattern/version.rb
CHANGED
@@ -29,6 +29,16 @@ module Workpattern
|
|
29
29
|
#
|
30
30
|
attr_reader :name, :base, :span, :from, :to, :weeks
|
31
31
|
|
32
|
+
# Class for handling persistence in user's own way
|
33
|
+
#
|
34
|
+
def self.persistence_class=(klass)
|
35
|
+
@@persistence = klass
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.persistence?
|
39
|
+
@@persistence ||= nil
|
40
|
+
end
|
41
|
+
|
32
42
|
# The new <tt>Workpattern</tt> object is created with all working minutes.
|
33
43
|
#
|
34
44
|
# @param [String] name Every workpattern has a unique name
|
@@ -119,6 +129,8 @@ module Workpattern
|
|
119
129
|
:work_type => WORK}
|
120
130
|
|
121
131
|
args.merge! opts
|
132
|
+
|
133
|
+
@@persistence.store( name: @name, workpattern: args) if self.class.persistence?
|
122
134
|
|
123
135
|
args[:start] = dmy_date(args[:start])
|
124
136
|
args[:finish] = dmy_date(args[:finish])
|
@@ -132,9 +144,7 @@ module Workpattern
|
|
132
144
|
current_wp=find_weekpattern(upd_start)
|
133
145
|
if (current_wp.start == upd_start)
|
134
146
|
if (current_wp.finish > upd_finish)
|
135
|
-
clone_wp=current_wp.
|
136
|
-
current_wp.adjust(upd_finish+1,current_wp.finish)
|
137
|
-
clone_wp.adjust(upd_start,upd_finish)
|
147
|
+
clone_wp=clone_and_adjust_current_wp(current_wp, upd_finish+1,current_wp.finish,upd_start,upd_finish)
|
138
148
|
clone_wp.workpattern(args[:days],from_time,to_time,args[:work_type])
|
139
149
|
@weeks<< clone_wp
|
140
150
|
upd_start=upd_finish+1
|
@@ -143,18 +153,14 @@ module Workpattern
|
|
143
153
|
upd_start=current_wp.finish + 1
|
144
154
|
end
|
145
155
|
else
|
146
|
-
clone_wp=current_wp.
|
147
|
-
current_wp.adjust(current_wp.start,upd_start-1)
|
148
|
-
clone_wp.adjust(upd_start,clone_wp.finish)
|
156
|
+
clone_wp=clone_and_adjust_current_wp(current_wp, current_wp.start,upd_start-1,upd_start)
|
149
157
|
if (clone_wp.finish <= upd_finish)
|
150
158
|
clone_wp.workpattern(args[:days],from_time,to_time,args[:work_type])
|
151
159
|
@weeks<< clone_wp
|
152
160
|
upd_start=clone_wp.finish+1
|
153
161
|
else
|
154
|
-
after_wp=clone_wp
|
155
|
-
after_wp.adjust(upd_finish+1,after_wp.finish)
|
162
|
+
after_wp=clone_and_adjust_current_wp(clone_wp, upd_start,upd_finish,upd_finish+1)
|
156
163
|
@weeks<< after_wp
|
157
|
-
clone_wp.adjust(upd_start,upd_finish)
|
158
164
|
clone_wp.workpattern(args[:days],from_time,to_time,args[:work_type])
|
159
165
|
@weeks<< clone_wp
|
160
166
|
upd_start=clone_wp.finish+1
|
@@ -278,6 +284,20 @@ module Workpattern
|
|
278
284
|
return Clock.new(date.hour,date.min)
|
279
285
|
end
|
280
286
|
|
287
|
+
private
|
288
|
+
|
289
|
+
# Handles cloning of Week Pattern including date adjustments
|
290
|
+
#
|
291
|
+
def clone_and_adjust_current_wp(current_wp, current_start,current_finish,clone_start,clone_finish=nil)
|
292
|
+
clone_wp=current_wp.duplicate
|
293
|
+
current_wp.adjust(current_start,current_finish)
|
294
|
+
if (clone_finish.nil?)
|
295
|
+
clone_wp.adjust(clone_start,clone_wp.finish)
|
296
|
+
else
|
297
|
+
clone_wp.adjust(clone_start,clone_finish)
|
298
|
+
end
|
299
|
+
return clone_wp
|
300
|
+
end
|
281
301
|
end
|
282
302
|
end
|
283
303
|
|
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/test/test_hour.rb
CHANGED
@@ -9,24 +9,24 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
9
9
|
|
10
10
|
must "ceate a working hour" do
|
11
11
|
working_hour = Workpattern::WORKING_HOUR
|
12
|
-
assert_equal 60, working_hour.
|
12
|
+
assert_equal 60, working_hour.wp_total,"working total minutes"
|
13
13
|
end
|
14
14
|
|
15
15
|
must "ceate a resting hour" do
|
16
16
|
resting_hour = Workpattern::RESTING_HOUR
|
17
|
-
assert_equal 0, resting_hour.
|
17
|
+
assert_equal 0, resting_hour.wp_total,"resting total minutes"
|
18
18
|
end
|
19
19
|
|
20
20
|
must "set patterns correctly" do
|
21
21
|
working_hour = Workpattern::WORKING_HOUR
|
22
|
-
working_hour = working_hour.
|
23
|
-
working_hour = working_hour.
|
24
|
-
working_hour = working_hour.
|
25
|
-
assert_equal 38,working_hour.
|
26
|
-
assert_equal 1, working_hour.
|
27
|
-
assert_equal 58, working_hour.
|
28
|
-
assert !working_hour.
|
29
|
-
assert working_hour.
|
22
|
+
working_hour = working_hour.wp_workpattern(0,0,0)
|
23
|
+
working_hour = working_hour.wp_workpattern(59,59,0)
|
24
|
+
working_hour = working_hour.wp_workpattern(11,30,0)
|
25
|
+
assert_equal 38,working_hour.wp_total, "total working minutes"
|
26
|
+
assert_equal 1, working_hour.wp_first, "first minute of the day"
|
27
|
+
assert_equal 58, working_hour.wp_last, "last minute of the day"
|
28
|
+
assert !working_hour.wp_working?(0)
|
29
|
+
assert working_hour.wp_working?(1)
|
30
30
|
end
|
31
31
|
|
32
32
|
must 'add minutes in a working hour' do
|
@@ -43,7 +43,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
43
43
|
[2000,12,31,23,59,1,2001,1,1,0,0,0]
|
44
44
|
].each{|y,m,d,h,n,add,yr,mr,dr,hr,nr,rem|
|
45
45
|
start=DateTime.new(y,m,d,h,n)
|
46
|
-
result,remainder = working_hour.
|
46
|
+
result,remainder = working_hour.wp_calc(start,add)
|
47
47
|
assert_equal DateTime.new(yr,mr,dr,hr,nr), result, "result calc(#{start},#{add})"
|
48
48
|
assert_equal rem, remainder, "remainder calc(#{start},#{add})"
|
49
49
|
}
|
@@ -63,7 +63,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
63
63
|
[2000,12,31,23,59,1,2001,1,1,0,0,1]
|
64
64
|
].each{|y,m,d,h,n,add,yr,mr,dr,hr,nr,rem|
|
65
65
|
start=DateTime.new(y,m,d,h,n)
|
66
|
-
result,remainder = resting_hour.
|
66
|
+
result,remainder = resting_hour.wp_calc(start,add)
|
67
67
|
assert_equal DateTime.new(yr,mr,dr,hr,nr), result, "result calc(#{start},#{add})"
|
68
68
|
assert_equal rem, remainder, "remainder calc(#{start},#{add})"
|
69
69
|
}
|
@@ -73,8 +73,8 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
73
73
|
must 'add minutes in a patterned hour' do
|
74
74
|
|
75
75
|
pattern_hour = Workpattern::WORKING_HOUR
|
76
|
-
pattern_hour = pattern_hour.
|
77
|
-
pattern_hour = pattern_hour.
|
76
|
+
pattern_hour = pattern_hour.wp_workpattern(1,10,0)
|
77
|
+
pattern_hour = pattern_hour.wp_workpattern(55,59,0)
|
78
78
|
[
|
79
79
|
[2000,1,1,0,0,3,2000,1,1,0,13,0],
|
80
80
|
[2000,1,1,0,0,0,2000,1,1,0,0,0],
|
@@ -86,7 +86,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
86
86
|
[2000,12,31,23,59,1,2001,1,1,0,0,1]
|
87
87
|
].each{|y,m,d,h,n,add,yr,mr,dr,hr,nr,rem|
|
88
88
|
start=DateTime.new(y,m,d,h,n)
|
89
|
-
result,remainder = pattern_hour.
|
89
|
+
result,remainder = pattern_hour.wp_calc(start,add)
|
90
90
|
assert_equal DateTime.new(yr,mr,dr,hr,nr), result, "result calc(#{start},#{add})"
|
91
91
|
assert_equal rem, remainder, "remainder calc(#{start},#{add})"
|
92
92
|
}
|
@@ -106,7 +106,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
106
106
|
[2001,1,1,0,0,-1,2001,1,1,0,0,-1]
|
107
107
|
].each{|y,m,d,h,n,add,yr,mr,dr,hr,nr,rem|
|
108
108
|
start=DateTime.new(y,m,d,h,n)
|
109
|
-
result,remainder = working_hour.
|
109
|
+
result,remainder = working_hour.wp_calc(start,add)
|
110
110
|
assert_equal DateTime.new(yr,mr,dr,hr,nr), result, "result calc(#{start},#{add})"
|
111
111
|
assert_equal rem, remainder, "remainder calc(#{start},#{add})"
|
112
112
|
}
|
@@ -126,7 +126,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
126
126
|
[2001,1,1,0,0,-1,2001,1,1,0,0,-1]
|
127
127
|
].each{|y,m,d,h,n,add,yr,mr,dr,hr,nr,rem|
|
128
128
|
start=DateTime.new(y,m,d,h,n)
|
129
|
-
result,remainder = resting_hour.
|
129
|
+
result,remainder = resting_hour.wp_calc(start,add)
|
130
130
|
assert_equal DateTime.new(yr,mr,dr,hr,nr), result, "result calc(#{start},#{add})"
|
131
131
|
assert_equal rem, remainder, "remainder calc(#{start},#{add})"
|
132
132
|
}
|
@@ -136,8 +136,8 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
136
136
|
must 'subtract minutes in a patterned hour' do
|
137
137
|
|
138
138
|
pattern_hour = Workpattern::WORKING_HOUR
|
139
|
-
pattern_hour = pattern_hour.
|
140
|
-
pattern_hour = pattern_hour.
|
139
|
+
pattern_hour = pattern_hour.wp_workpattern(1,10,0)
|
140
|
+
pattern_hour = pattern_hour.wp_workpattern(55,59,0)
|
141
141
|
[
|
142
142
|
[2000,1,1,0,0,-3,2000,1,1,0,0,-3],
|
143
143
|
[2000,1,1,0,0,0,2000,1,1,0,0,0],
|
@@ -149,7 +149,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
149
149
|
[2001,1,1,23,59,-1,2001,1,1,23,54,0]
|
150
150
|
].each{|y,m,d,h,n,add,yr,mr,dr,hr,nr,rem|
|
151
151
|
start=DateTime.new(y,m,d,h,n)
|
152
|
-
result,remainder = pattern_hour.
|
152
|
+
result,remainder = pattern_hour.wp_calc(start,add)
|
153
153
|
assert_equal DateTime.new(yr,mr,dr,hr,nr), result, "result calc(#{start},#{add})"
|
154
154
|
assert_equal rem, remainder, "remainder calc(#{start},#{add})"
|
155
155
|
}
|
@@ -170,16 +170,16 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
170
170
|
[0,0,1,1,0,0],
|
171
171
|
[59,59,1,2,0,59]
|
172
172
|
].each{|start,finish,type,total,first,last|
|
173
|
-
working_hour = working_hour.
|
174
|
-
assert_equal total,working_hour.
|
175
|
-
assert_equal first, working_hour.
|
176
|
-
assert_equal last, working_hour.
|
173
|
+
working_hour = working_hour.wp_workpattern(start,finish,type)
|
174
|
+
assert_equal total,working_hour.wp_total, "total working minutes #{j}"
|
175
|
+
assert_equal first, working_hour.wp_first, "first minute of the day #{j}"
|
176
|
+
assert_equal last, working_hour.wp_last, "last minute of the day #{j}"
|
177
177
|
start.upto(finish) {|i| control[i]=type}
|
178
178
|
0.upto(59) {|i|
|
179
179
|
if (control[i]==0)
|
180
|
-
assert !working_hour.
|
180
|
+
assert !working_hour.wp_working?(i)
|
181
181
|
else
|
182
|
-
assert working_hour.
|
182
|
+
assert working_hour.wp_working?(i)
|
183
183
|
end
|
184
184
|
}
|
185
185
|
j+=1
|
@@ -201,7 +201,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
201
201
|
[59,0,59],
|
202
202
|
[60,0,60]
|
203
203
|
].each {|start,finish,result|
|
204
|
-
assert_equal result, working_hour.
|
204
|
+
assert_equal result, working_hour.wp_diff(start,finish),"diff(#{start},#{finish})"
|
205
205
|
}
|
206
206
|
|
207
207
|
end
|
@@ -220,7 +220,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
220
220
|
[59,0,0],
|
221
221
|
[60,0,0]
|
222
222
|
].each {|start,finish,result|
|
223
|
-
assert_equal result, resting_hour.
|
223
|
+
assert_equal result, resting_hour.wp_diff(start,finish),"diff(#{start},#{finish})"
|
224
224
|
}
|
225
225
|
|
226
226
|
end
|
@@ -228,9 +228,9 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
228
228
|
must "calculate difference between minutes in pattern hour" do
|
229
229
|
|
230
230
|
pattern_hour = Workpattern::WORKING_HOUR
|
231
|
-
pattern_hour = pattern_hour.
|
232
|
-
pattern_hour = pattern_hour.
|
233
|
-
pattern_hour = pattern_hour.
|
231
|
+
pattern_hour = pattern_hour.wp_workpattern(1,10,0)
|
232
|
+
pattern_hour = pattern_hour.wp_workpattern(55,59,0)
|
233
|
+
pattern_hour = pattern_hour.wp_workpattern(59,59,1)
|
234
234
|
|
235
235
|
[[0,0,0],
|
236
236
|
[0,1,1],
|
@@ -244,7 +244,7 @@ class TestHour < Test::Unit::TestCase #:nodoc:
|
|
244
244
|
[59,0,45],
|
245
245
|
[60,0,46]
|
246
246
|
].each {|start,finish,result|
|
247
|
-
assert_equal result, pattern_hour.
|
247
|
+
assert_equal result, pattern_hour.wp_diff(start,finish),"diff(#{start},#{finish})"
|
248
248
|
}
|
249
249
|
end
|
250
250
|
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: workpattern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Barrie Callender
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -65,27 +62,25 @@ files:
|
|
65
62
|
- workpattern.gemspec
|
66
63
|
homepage: ''
|
67
64
|
licenses: []
|
65
|
+
metadata: {}
|
68
66
|
post_install_message:
|
69
67
|
rdoc_options: []
|
70
68
|
require_paths:
|
71
69
|
- lib
|
72
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
71
|
requirements:
|
75
72
|
- - ! '>='
|
76
73
|
- !ruby/object:Gem::Version
|
77
74
|
version: '0'
|
78
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
76
|
requirements:
|
81
77
|
- - ! '>='
|
82
78
|
- !ruby/object:Gem::Version
|
83
79
|
version: '0'
|
84
80
|
requirements: []
|
85
81
|
rubyforge_project: workpattern
|
86
|
-
rubygems_version:
|
82
|
+
rubygems_version: 2.0.3
|
87
83
|
signing_key:
|
88
|
-
specification_version:
|
84
|
+
specification_version: 4
|
89
85
|
summary: temporal calculations
|
90
86
|
test_files: []
|
91
|
-
has_rdoc:
|