Add work hours calc

This commit is contained in:
2019-11-03 12:23:17 +03:00
parent e236a1bdac
commit 3195a14bb3
3 changed files with 46 additions and 5 deletions

View File

@ -10,20 +10,44 @@ module Dayoff
)
end
class WorkRecord
JSON.mapping(
start: String,
finish: String,
)
end
class App
def initialize(pddates_path)
content = File.open(pddates_path) do |file|
def initialize(pdates_path, wdates_path)
content = File.open(pdates_path) do |file|
file.gets_to_end
end
@pdates = Array(PlannedDate).from_json(content)
content = File.open(wdates_path) do |file|
file.gets_to_end
end
@wrecords = Array(WorkRecord).from_json(content)
end
def get_work_hours
def get_planned_hours
sum = 0
@pdates.each do |wd|
sum += wd.hours
end
sum
end
def get_work_hours
sum = 0
location = Time::Location.load("Europe/Moscow")
@wrecords.each do |wr|
s = Time.parse(wr.start, "%Y-%m-%d %H:%M:%S", location)
f = Time.parse(wr.finish, "%Y-%m-%d %H:%M:%S", location)
diff = f - s
sum += diff.total_hours.to_i32
end
return sum
end
end
end