diff --git a/src/oph/heratepalvelu/common.clj b/src/oph/heratepalvelu/common.clj index 3dfb0976..fb7b842d 100644 --- a/src/oph/heratepalvelu/common.clj +++ b/src/oph/heratepalvelu/common.clj @@ -292,10 +292,18 @@ :tyyppi_kausi [:s (str tyyppi "/" laskentakausi)]})))) (defn valid-herate-date? - "onko herätteen päivämäärä aikaisintaan 1.7.2022?" + "onko herätteen päivämäärä aikaisintaan kuluvan rahoituskauden alkupvm + (1.7.)?" [heratepvm] (try - (not (.isAfter (LocalDate/of 2022 7 1) (LocalDate/parse (or heratepvm "")))) + (let [current-year (.getYear (local-date-now)) + rahoituskausi-alkuvuosi (if (< (.getMonthValue (local-date-now)) 7) + (dec current-year) + current-year) + rahoituskausi-alkupvm (LocalDate/of + ^long rahoituskausi-alkuvuosi 7 1)] + (not (.isAfter rahoituskausi-alkupvm + (LocalDate/parse (or heratepvm ""))))) (catch DateTimeParseException e (log/warn "Bad date" heratepvm) false))) diff --git a/test/oph/heratepalvelu/common_test.clj b/test/oph/heratepalvelu/common_test.clj index 4c3395cf..f2196be3 100644 --- a/test/oph/heratepalvelu/common_test.clj +++ b/test/oph/heratepalvelu/common_test.clj @@ -1,6 +1,6 @@ (ns oph.heratepalvelu.common-test (:require [clojure.test :refer :all] - [oph.heratepalvelu.common :refer :all] + [oph.heratepalvelu.common :refer :all :as c] [oph.heratepalvelu.test-util :refer :all] [clj-time.core :as t] [clojure.string :as str]) @@ -199,13 +199,18 @@ "arvizturo_tukorfurogep")))) (deftest test-valid-herate-date? - (testing "True if heratepvm is >= 2022-07-01" - (is (true? (valid-herate-date? "2022-07-02"))) - (is (true? (valid-herate-date? "2022-07-01"))) - (is (not (true? (valid-herate-date? "2022-06-01")))) - (is (not (true? (valid-herate-date? "2022-07-01xxxx")))) - (is (not (true? (valid-herate-date? "")))) - (is (not (true? (valid-herate-date? nil)))))) + (testing "True if heratepvm is >= [rahoituskausi start year]-07-01" + (with-redefs [c/local-date-now (constantly (LocalDate/of 2023 6 22))] + (is (true? (valid-herate-date? "2022-07-02"))) + (is (true? (valid-herate-date? "2022-07-01"))) + (is (not (true? (valid-herate-date? "2022-06-01")))) + (is (not (true? (valid-herate-date? "2022-07-01xxxx")))) + (is (not (true? (valid-herate-date? "")))) + (is (not (true? (valid-herate-date? nil)))))) + (testing "Not true if heratepvm is < [rahoituskausi start year]-07-01" + (with-redefs [c/local-date-now (constantly (LocalDate/of 2023 7 22))] + (is (not (true? (valid-herate-date? "2022-07-02")))) + (is (not (true? (valid-herate-date? "2022-07-01"))))))) (deftest test-sisaltyy-toiseen-opiskeluoikeuteen (testing "Sisältyy toiseen opiskeluoikeuteen"