Skip to content

Commit

Permalink
Merge pull request #12 from clanhr/half-day-absences
Browse files Browse the repository at this point in the history
Consider half-days on an absence
  • Loading branch information
paulosilva86 committed Mar 27, 2019
2 parents c14a1f1 + 3824a72 commit a62a1bc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 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.9.0"
(defproject clanhr/work-days "0.10.0"
:description "Work days calculation"
:url "https://github.com/clanhr/work-days"
:dependencies [[org.clojure/clojure "1.8.0"]
Expand Down
6 changes: 4 additions & 2 deletions src/clanhr/work_days/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,17 @@
0)))

(defn total-absence-hours
"Gets the total vacation days on this absence"
"Gets the total absence days/hours/partial-day on this absence"
[settings absence]
(let [absence (build absence)]
(if (not= "vacations" (absence-type absence))
(if (= "days" (:duration-type absence))
(if (remove-days-off? settings absence)
(* (hours-per-day settings) (days-interval-remove-dayoff settings absence))
(* (hours-per-day settings) (days-interval settings absence)))
(:hours absence))
(if (= "partial-day" (:duration-type absence))
(:partial-day absence)
(:hours absence)))
0)))

(defn calculate
Expand Down
11 changes: 11 additions & 0 deletions test/clanhr/work_days/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@
(is (= 0.5 (work-days/calculate {} absence)))
(is (= 0.5 (work-days/total-vacation-days {} absence))))))

(deftest half-absence-days
(let [absence {:start-date "2015-11-09"
:end-date "2015-11-09"
:absence-type "medical"
:duration-type "partial-day"
: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))))))

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

0 comments on commit a62a1bc

Please sign in to comment.