calc_working_hours 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/calc_working_hours.gemspec +2 -0
- data/lib/calc_working_hours.rb +4 -2
- data/lib/calc_working_hours/time_card.rb +25 -0
- data/lib/calc_working_hours/time_card_row.rb +114 -0
- data/lib/calc_working_hours/time_recorder.rb +32 -0
- data/lib/calc_working_hours/version.rb +1 -1
- data/lib/calc_working_hours/working_hours.rb +6 -3
- data/spec/calc_working_hours/data_sample.csv +128 -0
- data/spec/calc_working_hours/time_card_row_spec.rb +65 -0
- data/spec/calc_working_hours/time_card_spec.rb +14 -0
- data/spec/calc_working_hours/time_recorder_spec.rb +30 -0
- data/spec/calc_working_hours/working_hours_spec.rb +1 -1
- metadata +36 -9
data/calc_working_hours.gemspec
CHANGED
data/lib/calc_working_hours.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "calc_working_hours/version"
|
2
|
-
require "
|
2
|
+
require "active_support/dependencies"
|
3
3
|
|
4
4
|
module CalcWorkingHours
|
5
|
-
# Your code goes here...
|
6
5
|
end
|
6
|
+
|
7
|
+
ActiveSupport::Dependencies.autoload_paths << File.expand_path('..', __FILE__)
|
8
|
+
ActiveSupport::Dependencies.autoload_paths << File.expand_path('../calc_working_hours', __FILE__)
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module CalcWorkingHours
|
4
|
+
attr_reader :time_card_rows, :card_id, :working_hours
|
5
|
+
class TimeCard
|
6
|
+
def initialize(card_id)
|
7
|
+
@time_card_rows = []
|
8
|
+
@card_id = card_id
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_row(time_card_rows_obj)
|
13
|
+
@time_card_rows << time_card_rows_obj
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def total_working_hours
|
18
|
+
array_of_working_hours = []
|
19
|
+
@time_card_rows.each do |row|
|
20
|
+
array_of_working_hours << row.working_hours.time_string
|
21
|
+
end
|
22
|
+
@working_hours = WorkingHours.new("0:00").add_array_time(array_of_working_hours).time_string
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module CalcWorkingHours
|
6
|
+
|
7
|
+
class TimeCardRow
|
8
|
+
attr_reader :starting_time, :ending_time, :break_time, :working_hours, :date_string
|
9
|
+
def initialize(starting_time, ending_time, *break_time)
|
10
|
+
unless valid_time_format?(starting_time) && valid_time_format?(ending_time)
|
11
|
+
raise "failure initialize (invalid time format! TimeCardRow class)"
|
12
|
+
end
|
13
|
+
|
14
|
+
unless valid_time_order?(starting_time, ending_time)
|
15
|
+
raise "failure initialize (invalid time order! TimeCardRow class)"
|
16
|
+
end
|
17
|
+
|
18
|
+
unless break_time.empty?
|
19
|
+
unless valid_break_time?(break_time, starting_time, ending_time)
|
20
|
+
raise "failure initialize (invalid break time! TimeCardRow class)"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
break_time.each do |time|
|
25
|
+
unless valid_time_order?(time[0], time[1])
|
26
|
+
raise "failure initialize (invalid time order(break time)! TimeCardRow class)"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
total_break_time_string = "0:00"
|
31
|
+
unless break_time.empty?
|
32
|
+
total_break_time_string = total_break_time(break_time)
|
33
|
+
end
|
34
|
+
|
35
|
+
@starting_time = starting_time
|
36
|
+
@ending_time = ending_time
|
37
|
+
@break_time = break_time
|
38
|
+
@working_hours = WorkingHours.new(ending_time).minus_time(starting_time).minus_time(total_break_time_string)
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def set_date(date)
|
44
|
+
unless date.class == String
|
45
|
+
raise "failure set_date (date should string class)! TimeCardRow class"
|
46
|
+
end
|
47
|
+
@date_string = date
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def total_break_time(break_time)
|
54
|
+
total = WorkingHours.new("0:00")
|
55
|
+
break_time.each do |time|
|
56
|
+
total.add_time(time[1]).minus_time(time[0])
|
57
|
+
end
|
58
|
+
return total.time_string
|
59
|
+
end
|
60
|
+
|
61
|
+
def valid_time_card_row_format?(starting_time, ending_time)
|
62
|
+
# break_timeについてはvalid_break_timeでチェック
|
63
|
+
flag = false
|
64
|
+
if valid_time_format?(starting_time) && valid_time_format?(ending_time)
|
65
|
+
flag = true
|
66
|
+
end
|
67
|
+
return flag
|
68
|
+
end
|
69
|
+
|
70
|
+
def valid_time_format?(time)
|
71
|
+
flag = false
|
72
|
+
if time.class == String
|
73
|
+
if /(\d+):(\d+)/ =~ time
|
74
|
+
if ($1.to_i <= 48 && $1.to_i >= 0) && ($2.to_i < 60 && $2.to_i >= 0)
|
75
|
+
flag = true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
return flag
|
80
|
+
end
|
81
|
+
|
82
|
+
def valid_time_order?(first, second)
|
83
|
+
false
|
84
|
+
true if change_to_minute(first) < change_to_minute(second)
|
85
|
+
end
|
86
|
+
|
87
|
+
def valid_break_time?(break_time, starting_time, ending_time)
|
88
|
+
flag = false
|
89
|
+
break_time.each do |time|
|
90
|
+
if time.length == 2 && time.class == Array
|
91
|
+
if valid_time_format?(time[0]) && valid_time_format?(time[1])
|
92
|
+
time.each do |t|
|
93
|
+
if change_to_minute(starting_time) >= change_to_minute(t) || change_to_minute(ending_time) <= change_to_minute(t)
|
94
|
+
return flag = false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
flag = true
|
98
|
+
end
|
99
|
+
else
|
100
|
+
return flag = false
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
return flag
|
105
|
+
end
|
106
|
+
|
107
|
+
def change_to_minute(str)
|
108
|
+
/(\d+):(\d+)/ =~ str
|
109
|
+
return $1.to_i * 60 + $2.to_i
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require "csv"
|
3
|
+
|
4
|
+
module CalcWorkingHours
|
5
|
+
|
6
|
+
class TimeRecorder
|
7
|
+
attr_reader :time_cards
|
8
|
+
def initialize(path_to_csv, card_id_row, starting_time_row, ending_time_row, date_row, ignore_row_flag = 0, *break_time_rows)
|
9
|
+
time_cards = {}
|
10
|
+
option_of_csv = {:headers => true, :return_headers => false}
|
11
|
+
CSV.foreach(path_to_csv, option_of_csv) do |row|
|
12
|
+
if row[starting_time_row] != nil && row[ending_time_row] != nil && row[ignore_row_flag].to_i >= 1
|
13
|
+
break_times = []
|
14
|
+
unless break_time_rows.empty?
|
15
|
+
break_time_rows.each do |bt|
|
16
|
+
break_times << [row[bt[0]], row[bt[1]]] unless row[bt[0]] == nil || row[bt[1]] == nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if time_cards.has_key?(row[card_id_row])
|
21
|
+
time_cards[row[card_id_row]].add_row(TimeCardRow.new(row[starting_time_row], row[ending_time_row], *break_times).set_date(row[date_row]))
|
22
|
+
else
|
23
|
+
time_cards[row[card_id_row]] = TimeCard.new(row[card_id_row])
|
24
|
+
time_cards[row[card_id_row]].add_row(TimeCardRow.new(row[starting_time_row], row[ending_time_row], *break_times).set_date(row[date_row]))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@time_cards = time_cards
|
29
|
+
self
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -67,9 +67,12 @@ module CalcWorkingHours
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def change_to_time_string(minute)
|
70
|
-
hour = minute.div(60)
|
71
|
-
minute = minute % 60
|
72
|
-
|
70
|
+
hour = minute.div(60).to_s
|
71
|
+
minute = (minute % 60).to_s
|
72
|
+
if minute.length == 1
|
73
|
+
minute = "0" + minute
|
74
|
+
end
|
75
|
+
return hour + ":" + minute
|
73
76
|
end
|
74
77
|
|
75
78
|
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
"�J�[�h�ԍ�","�]�ƈ��ԍ�","�]�ƈ�����","�����ԍ�","�N/��/��","�V�t�g�ԍ�","����/�x���敪","�s�ݗ��R","�o�Αō�","�o�}�[�N","�O�o�ō�","�O�o�}�[�N","�ߑō�","�߃}�[�N","�ދΑō�","�ދ}�[�N","�R�����g"
|
2
|
+
0000000001,00000001,�����@������,2,2013/07/21,01,00,,09:55,0,14:30,0,16:30,0,21:03,0,
|
3
|
+
0000000001,00000001,�����@������,2,2013/07/22,01,00,,09:47,0,14:30,0,16:30,0,21:13,0,
|
4
|
+
0000000001,00000001,�����@������,2,2013/07/23,01,00,,09:59,0,14:30,0,16:30,0,21:09,0,
|
5
|
+
0000000001,00000001,�����@������,2,2013/07/24,01,00,,,0,,0,,0,,0,
|
6
|
+
0000000001,00000001,�����@������,2,2013/07/25,01,00,,,0,,0,,0,,0,
|
7
|
+
0000000001,00000001,�����@������,2,2013/07/26,01,00,,09:55,0,14:30,0,16:30,0,21:55,0,
|
8
|
+
0000000001,00000001,�����@������,2,2013/07/27,01,00,,09:40,0,14:30,0,16:30,0,21:00,0,
|
9
|
+
0000000001,00000001,�����@������,2,2013/07/28,01,00,,09:57,0,14:30,0,16:30,0,21:38,0,
|
10
|
+
0000000001,00000001,�����@������,2,2013/07/29,01,00,,10:00,0,14:30,0,16:30,0,21:00,0,
|
11
|
+
0000000001,00000001,�����@������,2,2013/07/30,01,00,,10:00,0,14:30,0,16:30,0,21:55,0,
|
12
|
+
0000000001,00000001,�����@������,2,2013/07/31,01,00,,,0,,0,,0,,0,
|
13
|
+
0000000001,00000001,�����@������,2,2013/08/01,01,00,,,0,,0,,0,,0,
|
14
|
+
0000000001,00000001,�����@������,2,2013/08/02,01,00,,10:01,0,14:30,0,16:30,0,21:43,0,
|
15
|
+
0000000001,00000001,�����@������,2,2013/08/03,01,00,,09:58,0,14:30,0,16:30,0,21:35,0,
|
16
|
+
0000000001,00000001,�����@������,2,2013/08/04,01,00,,10:01,0,14:30,0,16:30,0,21:43,0,
|
17
|
+
0000000001,00000001,�����@������,2,2013/08/05,01,00,,09:53,0,14:30,0,16:30,0,21:00,0,
|
18
|
+
0000000001,00000001,�����@������,2,2013/08/06,01,00,,09:38,0,14:30,0,16:30,0,21:59,0,
|
19
|
+
0000000001,00000001,�����@������,2,2013/08/07,01,00,,,0,,0,,0,,0,
|
20
|
+
0000000001,00000001,�����@������,2,2013/08/08,01,00,,,0,,0,,0,,0,
|
21
|
+
0000000001,00000001,�����@������,2,2013/08/09,01,00,,09:58,0,14:30,0,16:30,0,21:44,0,
|
22
|
+
0000000001,00000001,�����@������,2,2013/08/10,01,00,,09:59,0,14:30,0,16:30,0,21:30,0,
|
23
|
+
0000000001,00000001,�����@������,2,2013/08/11,01,00,,09:56,0,14:30,0,16:30,0,21:36,0,
|
24
|
+
0000000001,00000001,�����@������,2,2013/08/12,01,00,,10:03,0,14:30,0,16:30,0,21:56,0,
|
25
|
+
0000000001,00000001,�����@������,2,2013/08/13,01,00,,10:00,0,14:30,0,16:30,0,22:00,0,
|
26
|
+
0000000001,00000001,�����@������,2,2013/08/14,01,00,,10:00,0,14:30,0,16:30,0,22:03,0,
|
27
|
+
0000000001,00000001,�����@������,2,2013/08/15,01,00,,09:58,0,14:30,0,16:30,0,22:33,0,
|
28
|
+
0000000001,00000001,�����@������,2,2013/08/16,01,00,,10:03,0,14:30,0,16:30,0,22:22,0,
|
29
|
+
0000000001,00000001,�����@������,2,2013/08/17,01,00,,09:59,0,14:30,0,16:30,0,22:10,0,
|
30
|
+
0000000001,00000001,�����@������,2,2013/08/18,01,00,,10:02,0,14:30,0,16:30,0,21:30,0,
|
31
|
+
0000000001,00000001,�����@������,2,2013/08/19,01,00,,10:01,0,14:30,0,16:30,0,22:30,0,
|
32
|
+
0000000001,00000001,�����@������,2,2013/08/20,01,00,,09:32,0,14:30,0,16:30,0,22:21,0,
|
33
|
+
"�J�[�h�ԍ�","�]�ƈ��ԍ�","�]�ƈ�����","�����ԍ�","�N/��/��","�V�t�g�ԍ�","����/�x���敪","�s�ݗ��R","�o�Αō�","�o�}�[�N","�O�o�ō�","�O�o�}�[�N","�ߑō�","�߃}�[�N","�ދΑō�","�ދ}�[�N","�R�����g"
|
34
|
+
0000000002,00000002,�����@������,101,2013/07/21,20,00,,10:00,0,,0,,0,15:10,0,
|
35
|
+
0000000002,00000002,�����@������,101,2013/07/22,20,00,,10:30,0,15:09,0,17:50,0,20:03,0,
|
36
|
+
0000000002,00000002,�����@������,101,2013/07/23,20,00,,,0,,0,,0,,0,
|
37
|
+
0000000002,00000002,�����@������,101,2013/07/24,20,00,,,0,,0,,0,,0,
|
38
|
+
0000000002,00000002,�����@������,101,2013/07/25,20,00,,10:00,0,14:09,0,15:49,0,21:08,0,
|
39
|
+
0000000002,00000002,�����@������,101,2013/07/26,20,00,,10:00,0,14:12,0,15:48,0,21:27,0,
|
40
|
+
0000000002,00000002,�����@������,101,2013/07/27,20,00,,10:00,0,15:55,0,17:19,0,21:08,0,
|
41
|
+
0000000002,00000002,�����@������,101,2013/07/28,20,00,,11:24,0,,0,,0,14:28,0,
|
42
|
+
0000000002,00000002,�����@������,101,2013/07/29,20,00,,10:30,0,14:13,0,15:51,0,21:25,0,
|
43
|
+
0000000002,00000002,�����@������,101,2013/07/30,20,00,,10:30,0,14:09,0,14:49,0,20:27,0,
|
44
|
+
0000000002,00000002,�����@������,101,2013/07/31,20,00,,,0,,0,,0,,0,
|
45
|
+
0000000002,00000002,�����@������,101,2013/08/01,20,00,,,0,,0,,0,,0,
|
46
|
+
0000000002,00000002,�����@������,101,2013/08/02,20,00,,10:00,0,14:02,0,15:51,0,20:13,0,
|
47
|
+
0000000002,00000002,�����@������,101,2013/08/03,20,00,,10:00,0,14:00,0,15:49,0,19:05,0,
|
48
|
+
0000000002,00000002,�����@������,101,2013/08/04,20,00,,10:00,0,,0,,0,16:30,0,
|
49
|
+
0000000002,00000002,�����@������,101,2013/08/05,20,00,,10:30,0,14:13,0,15:53,0,21:29,0,
|
50
|
+
0000000002,00000002,�����@������,101,2013/08/06,20,00,,,0,,0,,0,,0,
|
51
|
+
0000000002,00000002,�����@������,101,2013/08/07,20,00,,11:00,0,,0,,0,15:05,0,
|
52
|
+
0000000002,00000002,�����@������,101,2013/08/08,20,00,,18:30,0,,0,,0,22:43,0,
|
53
|
+
0000000002,00000002,�����@������,101,2013/08/09,20,00,,10:30,0,14:16,0,16:11,0,20:12,0,
|
54
|
+
0000000002,00000002,�����@������,101,2013/08/10,20,00,,10:00,0,16:29,0,17:48,0,21:09,0,
|
55
|
+
0000000002,00000002,�����@������,101,2013/08/11,20,00,,10:00,0,,0,,0,15:05,0,
|
56
|
+
0000000002,00000002,�����@������,101,2013/08/12,20,00,,10:00,0,14:27,0,15:58,0,21:56,0,
|
57
|
+
0000000002,00000002,�����@������,101,2013/08/13,20,00,,,0,,0,,0,,0,
|
58
|
+
0000000002,00000002,�����@������,101,2013/08/14,20,00,,10:00,0,14:00,0,15:50,0,21:01,0,
|
59
|
+
0000000002,00000002,�����@������,101,2013/08/15,20,00,,10:00,0,14:09,0,15:52,0,21:09,0,
|
60
|
+
0000000002,00000002,�����@������,101,2013/08/16,20,00,,,0,,0,,0,,0,
|
61
|
+
0000000002,00000002,�����@������,101,2013/08/17,20,00,,10:00,0,14:08,0,15:49,0,21:07,0,
|
62
|
+
0000000002,00000002,�����@������,101,2013/08/18,20,00,,10:00,0,,0,,0,16:16,0,
|
63
|
+
0000000002,00000002,�����@������,101,2013/08/19,20,00,,10:30,0,14:32,0,16:46,0,21:06,0,
|
64
|
+
0000000002,00000002,�����@������,101,2013/08/20,20,00,,10:00,0,14:12,0,15:49,0,20:51,0,
|
65
|
+
"�J�[�h�ԍ�","�]�ƈ��ԍ�","�]�ƈ�����","�����ԍ�","�N/��/��","�V�t�g�ԍ�","����/�x���敪","�s�ݗ��R","�o�Αō�","�o�}�[�N","�O�o�ō�","�O�o�}�[�N","�ߑō�","�߃}�[�N","�ދΑō�","�ދ}�[�N","�R�����g"
|
66
|
+
0000000084,00000004,�����@��,102,2013/07/21,20,00,,12:00,0,,0,,0,17:04,0,
|
67
|
+
0000000084,00000004,�����@��,102,2013/07/22,20,00,,12:00,0,,0,,0,17:00,0,
|
68
|
+
0000000084,00000004,�����@��,102,2013/07/23,20,00,,12:00,0,,0,,0,17:02,0,
|
69
|
+
0000000084,00000004,�����@��,102,2013/07/24,20,00,,,0,,0,,0,,0,
|
70
|
+
0000000084,00000004,�����@��,102,2013/07/25,20,00,,11:00,0,,0,,0,16:06,0,
|
71
|
+
0000000084,00000004,�����@��,102,2013/07/26,20,00,,12:00,0,,0,,0,16:39,0,
|
72
|
+
0000000084,00000004,�����@��,102,2013/07/27,20,00,,12:00,0,,0,,0,17:07,0,
|
73
|
+
0000000084,00000004,�����@��,102,2013/07/28,20,00,,12:00,0,,0,,0,17:08,0,
|
74
|
+
0000000084,00000004,�����@��,102,2013/07/29,20,00,,12:00,0,,0,,0,17:06,0,
|
75
|
+
0000000084,00000004,�����@��,102,2013/07/30,20,00,,12:00,0,,0,,0,17:05,0,
|
76
|
+
0000000084,00000004,�����@��,102,2013/07/31,20,00,,,0,,0,,0,,0,
|
77
|
+
0000000084,00000004,�����@��,102,2013/08/01,20,00,,10:30,0,,0,,0,15:30,0,
|
78
|
+
0000000084,00000004,�����@��,102,2013/08/02,20,00,,12:00,0,,0,,0,16:51,0,
|
79
|
+
0000000084,00000004,�����@��,102,2013/08/03,20,00,,12:00,0,,0,,0,17:05,0,
|
80
|
+
0000000084,00000004,�����@��,102,2013/08/04,20,00,,12:00,0,,0,,0,17:04,0,
|
81
|
+
0000000084,00000004,�����@��,102,2013/08/05,20,00,,10:30,0,,0,,0,15:42,0,
|
82
|
+
0000000084,00000004,�����@��,102,2013/08/06,20,00,,12:00,0,,0,,0,17:21,0,
|
83
|
+
0000000084,00000004,�����@��,102,2013/08/07,20,00,,,0,,0,,0,,0,
|
84
|
+
0000000084,00000004,�����@��,102,2013/08/08,20,00,,12:00,0,,0,,0,16:35,0,
|
85
|
+
0000000084,00000004,�����@��,102,2013/08/09,20,00,,11:00,0,,0,,0,15:14,0,
|
86
|
+
0000000084,00000004,�����@��,102,2013/08/10,20,00,,12:00,0,,0,,0,17:05,0,
|
87
|
+
0000000084,00000004,�����@��,102,2013/08/11,20,00,,12:00,0,,0,,0,17:10,0,
|
88
|
+
0000000084,00000004,�����@��,102,2013/08/12,20,00,,12:00,0,,0,,0,17:13,0,
|
89
|
+
0000000084,00000004,�����@��,102,2013/08/13,20,00,,12:00,0,,0,,0,17:05,0,
|
90
|
+
0000000084,00000004,�����@��,102,2013/08/14,20,00,,,0,,0,,0,,0,
|
91
|
+
0000000084,00000004,�����@��,102,2013/08/15,20,00,,12:00,0,,0,,0,21:30,0,
|
92
|
+
0000000084,00000004,�����@��,102,2013/08/16,20,00,,12:00,0,17:04,0,17:46,0,22:22,0,������
|
93
|
+
0000000084,00000004,�����@��,102,2013/08/17,20,00,,12:00,0,17:07,0,17:59,0,22:27,0,������
|
94
|
+
0000000084,00000004,�����@��,102,2013/08/18,20,00,,12:00,0,,0,,0,17:05,0,
|
95
|
+
0000000084,00000004,�����@��,102,2013/08/19,20,00,,12:00,0,,0,,0,17:08,0,
|
96
|
+
0000000084,00000004,�����@��,102,2013/08/20,20,00,,12:00,0,,0,,0,17:02,0,
|
97
|
+
"�J�[�h�ԍ�","�]�ƈ��ԍ�","�]�ƈ�����","�����ԍ�","�N/��/��","�V�t�g�ԍ�","����/�x���敪","�s�ݗ��R","�o�Αō�","�o�}�[�N","�O�o�ō�","�O�o�}�[�N","�ߑō�","�߃}�[�N","�ދΑō�","�ދ}�[�N","�R�����g"
|
98
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/21,20,00,,,0,,0,,0,,0,
|
99
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/22,20,00,,10:30,0,,0,,0,15:32,0,
|
100
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/23,20,00,,10:30,0,,0,,0,15:31,0,
|
101
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/24,20,00,,,0,,0,,0,,0,
|
102
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/25,20,00,,10:30,0,,0,,0,15:40,0,
|
103
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/26,20,00,,,0,,0,,0,,0,
|
104
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/27,20,01,,10:30,0,,0,,0,16:16,0,
|
105
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/28,20,00,,,0,,0,,0,,0,
|
106
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/29,20,00,,10:30,0,,0,,0,15:39,0,
|
107
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/30,20,00,,10:30,0,,0,,0,15:50,0,
|
108
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/07/31,20,00,,,0,,0,,0,,0,
|
109
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/01,20,00,,,0,,0,,0,,0,
|
110
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/02,20,00,,10:30,0,,0,,0,15:46,0,
|
111
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/03,20,00,,,0,,0,,0,,0,
|
112
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/04,20,01,,10:30,0,,0,,0,15:53,0,
|
113
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/05,20,00,,,0,,0,,0,,0,
|
114
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/06,20,00,,10:30,0,,0,,0,16:02,0,
|
115
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/07,20,00,,10:30,0,,0,,0,15:30,0,
|
116
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/08,20,00,,,0,,0,,0,,0,
|
117
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/09,20,00,,10:30,0,,0,,0,15:45,0,
|
118
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/10,20,00,,,0,,0,,0,,0,
|
119
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/11,20,01,,10:30,0,,0,,0,16:30,0,
|
120
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/12,20,00,,,0,,0,,0,,0,
|
121
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/13,20,00,,10:30,0,,0,,0,16:12,0,
|
122
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/14,20,00,,10:30,0,,0,,0,16:30,0,
|
123
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/15,20,00,,,0,,0,,0,,0,
|
124
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/16,20,00,,10:30,0,,0,,0,16:26,0,
|
125
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/17,20,01,,10:30,0,16:02,0,17:55,0,22:02,0,������
|
126
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/18,20,00,,,0,,0,,0,,0,
|
127
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/19,20,00,,,0,,0,,0,,0,
|
128
|
+
0000000005,00000016,�ȂɁ@�ʂ˂�,102,2013/08/20,20,00,,10:30,0,,0,,0,15:47,0,
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
include CalcWorkingHours
|
5
|
+
|
6
|
+
describe TimeCardRow do
|
7
|
+
context "始業9:00、終業19:00、休憩11:00〜12:00、15:00〜16:00のとき" do
|
8
|
+
before do
|
9
|
+
@time_card_row = TimeCardRow.new("9:00", "19:00", ["11:00", "12:00"], ["15:00", "16:00"])
|
10
|
+
end
|
11
|
+
|
12
|
+
it "始業時間は9:00となっている" do
|
13
|
+
@time_card_row.starting_time.should == "9:00"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "終業時間は19:00となっている" do
|
17
|
+
@time_card_row.ending_time.should == "19:00"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "労働時間は8:00となっている" do
|
21
|
+
@time_card_row.working_hours.time_string.should == "8:00"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "set_dateにDateクラスのオブジェクトを渡すことで日付を設定できる" do
|
25
|
+
@time_card_row.set_date("2013/8/1").date_string.class.should == String
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context "適正な時間設定と、不適な設定時間を設定したとき" do
|
31
|
+
it "始業22:00、終業28:00は適正な始業・終業時間設定(0:00〜48:00)なので、エラーは発生しないこと" do
|
32
|
+
proc{ TimeCardRow.new("22:00", "28:00") }.should_not raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it "始業44:00、終業50:00は不適正な始業・終業時間設定なので、エラーが発生すること" do
|
36
|
+
proc{ TimeCardRow.new("44:00", "50:00") }.should raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it "始業四:00、終業5:00は不適正な時間フォーマットなので、エラーが発生すること" do
|
40
|
+
proc{ TimeCardRow.new("四:00", "5:00") }.should raise_error
|
41
|
+
end
|
42
|
+
|
43
|
+
it "始業9:00、終業19:00の時系列に誤りが無いので、エラーは発生しないこと" do
|
44
|
+
proc { TimeCardRow.new("9:00", "19:00") }.should_not raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it "始業18:00、終業8:00は時系列が誤っているので、エラーが発生すること" do
|
48
|
+
proc { TimeCardRow.new("18:00", "9:00") }.should raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
it "始業8:00、終業19:00、休憩12:00〜11:00は時系列が誤っているので、エラーが発生すること" do
|
52
|
+
proc { TimeCardRow.new("8:00", "19:00", ["12:00", "10:00"]) }.should raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it "始業8:00、終業19:00、休憩12:00は休憩時間設定が誤っているので、エラーが発生すること" do
|
56
|
+
proc { TimeCardRow.new("8:00", "19:00", "12:00") }.should raise_error
|
57
|
+
end
|
58
|
+
|
59
|
+
it "始業8:00、終業19:00、休憩7:00〜11:00は時系列が誤っているので、エラーが発生すること" do
|
60
|
+
proc { TimeCardRow.new("8:00", "19:00", ["7:00", "10:00"]) }.should raise_error
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
include CalcWorkingHours
|
5
|
+
|
6
|
+
describe TimeRecorder do
|
7
|
+
context "data_sample.csvの通りTimeRecorderが与えられている場合" do
|
8
|
+
before do
|
9
|
+
path_to_csv = File.expand_path(File.dirname(__FILE__)) + "/data_sample.csv"
|
10
|
+
@time_recorder = TimeRecorder.new(path_to_csv, 0, 8, 14, 4, 0, [10, 12])
|
11
|
+
end
|
12
|
+
|
13
|
+
it "タイムカードのデータが5件あること" do
|
14
|
+
@time_recorder.time_cards.size.should == 4
|
15
|
+
end
|
16
|
+
|
17
|
+
it "タイムカードのidが0000000001の人物の出勤日数は25日であること" do
|
18
|
+
@time_recorder.time_cards["0000000001"].time_card_rows.size.should == 25
|
19
|
+
end
|
20
|
+
|
21
|
+
it "タイムカードのidが0000000002の人物の5番目の出勤日は2013/07/27であること" do
|
22
|
+
@time_recorder.time_cards["0000000002"].time_card_rows[4].date_string.should == "2013/07/27"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "タイムカードのidが0000000084の人物の総労働時間は149:12であること" do
|
26
|
+
@time_recorder.time_cards["0000000084"].total_working_hours.should == "149:12"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -38,7 +38,7 @@ describe WorkingHours do
|
|
38
38
|
@working_hours.minus_time("2:25").minus_time("3:00").time_string.should == "2:20"
|
39
39
|
end
|
40
40
|
|
41
|
-
it '["1:10", "2:20", "3:30", "4:40"]を足すと、19:35
|
41
|
+
it '["1:10", "2:20", "3:30", "4:40"]を足すと、19:35になること(add_array_timeは配列を渡すと合計する)' do
|
42
42
|
@working_hours.add_array_time(["1:10", "2:20", "3:30", "4:40"]).time_string.should == "19:25"
|
43
43
|
end
|
44
44
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calc_working_hours
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-21 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70321991304440 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.3'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70321991304440
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70321991303700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70321991303700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70321991302820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,18 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70321991302820
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activesupport
|
49
|
+
requirement: &70321991301920 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70321991301920
|
47
58
|
description: 例えば、173:08のような表記の時間を計算するライブラリです
|
48
59
|
email:
|
49
60
|
- ''
|
@@ -60,8 +71,15 @@ files:
|
|
60
71
|
- Rakefile
|
61
72
|
- calc_working_hours.gemspec
|
62
73
|
- lib/calc_working_hours.rb
|
74
|
+
- lib/calc_working_hours/time_card.rb
|
75
|
+
- lib/calc_working_hours/time_card_row.rb
|
76
|
+
- lib/calc_working_hours/time_recorder.rb
|
63
77
|
- lib/calc_working_hours/version.rb
|
64
78
|
- lib/calc_working_hours/working_hours.rb
|
79
|
+
- spec/calc_working_hours/data_sample.csv
|
80
|
+
- spec/calc_working_hours/time_card_row_spec.rb
|
81
|
+
- spec/calc_working_hours/time_card_spec.rb
|
82
|
+
- spec/calc_working_hours/time_recorder_spec.rb
|
65
83
|
- spec/calc_working_hours/working_hours_spec.rb
|
66
84
|
- spec/calc_working_hours_spec.rb
|
67
85
|
- spec/spec_helper.rb
|
@@ -78,12 +96,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
96
|
- - ! '>='
|
79
97
|
- !ruby/object:Gem::Version
|
80
98
|
version: '0'
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
hash: 2137619453684458958
|
81
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
103
|
none: false
|
83
104
|
requirements:
|
84
105
|
- - ! '>='
|
85
106
|
- !ruby/object:Gem::Version
|
86
107
|
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: 2137619453684458958
|
87
111
|
requirements: []
|
88
112
|
rubyforge_project:
|
89
113
|
rubygems_version: 1.8.10
|
@@ -91,7 +115,10 @@ signing_key:
|
|
91
115
|
specification_version: 3
|
92
116
|
summary: 時間計算
|
93
117
|
test_files:
|
118
|
+
- spec/calc_working_hours/data_sample.csv
|
119
|
+
- spec/calc_working_hours/time_card_row_spec.rb
|
120
|
+
- spec/calc_working_hours/time_card_spec.rb
|
121
|
+
- spec/calc_working_hours/time_recorder_spec.rb
|
94
122
|
- spec/calc_working_hours/working_hours_spec.rb
|
95
123
|
- spec/calc_working_hours_spec.rb
|
96
124
|
- spec/spec_helper.rb
|
97
|
-
has_rdoc:
|