Skip to content

Commit

Permalink
Merge pull request #13 from clanhr/consider-4-hours-for-half-day
Browse files Browse the repository at this point in the history
Consider hours for a half-day absence
  • Loading branch information
paulosilva86 committed Mar 27, 2019
2 parents a62a1bc + d5fafc4 commit 3d7ffb2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject clanhr/work-days "0.10.0"
(defproject clanhr/work-days "0.10.1"
:description "Work days calculation"
:url "https://github.com/clanhr/work-days"
:dependencies [[org.clojure/clojure "1.8.0"]
Expand Down
13 changes: 10 additions & 3 deletions src/clanhr/work_days/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
[settings]
(or (:hours-per-day settings) 8))

(defn hours-in-half-day
"Gets the number of hours for a half working day"
[settings]
(/ (hours-per-day settings) 2))

(defn days-interval
"Gets the number of days between start-date and end-date"
[settings absence]
Expand Down Expand Up @@ -140,7 +145,7 @@
(* (hours-per-day settings) (days-interval-remove-dayoff settings absence))
(* (hours-per-day settings) (days-interval settings absence)))
(if (= "partial-day" (:duration-type absence))
(:partial-day absence)
(hours-in-half-day settings)
(:hours absence)))
0)))

Expand All @@ -157,7 +162,9 @@
(days-interval settings absence))

(= (:duration-type absence) "partial-day")
(:partial-day absence)

(if (= "vacations" (absence-type absence))
(:partial-day absence)
(hours-in-half-day settings))

:else
(:hours absence)))))
4 changes: 2 additions & 2 deletions test/clanhr/work_days/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@
:partial-day 0.5}]

(testing "should consider half days"
(is (= 0.5 (work-days/calculate {} absence)))
(is (= 0.5 (work-days/total-absence-hours {} absence))))))
(is (= 4 (work-days/calculate {} absence)))
(is (= 4 (work-days/total-absence-hours {} absence))))))

(deftest several-format-dates
(let [absence {:start-date "09-11-2015"
Expand Down

0 comments on commit 3d7ffb2

Please sign in to comment.