Skip to content

Commit 035685a

Browse files
committed
Rename list-holidays and add some docs
1 parent a4ac697 commit 035685a

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* UNRELEASED
44
* API now throws if holi does not recognize a calendar name
55
* Fixed a bug in the calendar showcase
6-
* Added an API function to list the names of holidays in a particular date
6+
* Added the `holidays-in-date` API fn to list the names of holidays in a particular date
7+
* The `list-holidays` API fn is now called `holidays-in-year`
78

89
* 0.16.0 - 3Mar2023
910
* API now throws when holi has no record of holidays for given year
1011
* Improved performance of API fns even more, up to 100x faster!
1112

1213
* 0.15.0 - 2Mar2023
13-
* Improved performance of main api functions to be 5 to 10 times faster
14+
* Improved performance of main API functions to be 5 to 10 times faster
1415

1516
* 0.14.0 - 6Feb2023
1617
* Date lists are now about 55% smaller - great for js bundles. They also link dates and holiday names now

doc/02-TIPS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@ example: an invoice due date is every 10th of the month. If it's a weekend, then
2525
(holi/add 1 :months) ; 2022-07-06, Sat
2626
(holi/add 0 :business-days)) ; 2022-07-08, Mon
2727
```
28+
29+
## An example use case for holidays-in-date
30+
31+
Imagine you want to keep a list of people and their birthdays, so your program can
32+
run daily and congratulate whoever celebrates their birthday that day. You could:
33+
34+
1. Create a [custom calendar](04-CUSTOM.md) named, say, `BIRTHDAYS`, where each line represents one person, with their birthday in the `DDMMM` format
35+
2. Call `(holi/holidays-in-date current-date "BIRTHDAYS")` to get everyone that celebrates their birthday each day
36+
3. Use that info to congratulate them

resources/holi-template/resources/calendars.cljc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
(defn business-day? [date & calendars]
1717
(apply holi/business-day? date calendars))
1818

19-
(defn list-holidays [year calendar]
20-
(holi/list-holidays year calendar))
19+
(defn holidays-in-year [year calendar]
20+
(holi/holidays-in-year year calendar))
21+
22+
(defn holidays-in-date [date calendar]
23+
(holi/holidays-in-date date calendar))

src/luciolucio/holi.cljc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
[date & calendars]
109109
(not (apply non-business-day? date calendars)))
110110

111-
(defn list-holidays
111+
(defn holidays-in-year
112112
"Returns a collection of maps of the form `{:name \"Name\" :date LocalDate}`
113113
where every item of the collection represents a holiday in the given year according
114114
to the given holiday calendar
@@ -117,7 +117,7 @@
117117
[year calendar]
118118
(core/read-calendar (safe-calendar calendar) year))
119119

120-
(defn holidays
120+
(defn holidays-in-date
121121
"Returns a collection containing names of holidays in the given date, for example: `[\"New Year's Day\" \"Independence Day\"]`
122122
123123
If there are none, it will return an empty collection.
@@ -131,7 +131,7 @@
131131
[date calendar]
132132
(if (holiday? date calendar)
133133
(->> calendar
134-
(list-holidays (-> date t/date t/year))
134+
(holidays-in-year (-> date t/date t/year))
135135
(filter #(= (t/date date) (:date %)))
136136
(map :name))
137137
[]))
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns luciolucio.holi.holidays-test
1+
(ns luciolucio.holi.holidays-in-date-test
22
(:require [clojure.test :as ct]
33
[luciolucio.holi :as holi]
44
[luciolucio.holi.test-setup :as setup]
@@ -8,17 +8,17 @@
88

99
(ct/use-fixtures :each setup/test-datelist-fixture)
1010

11-
(ct/deftest should-return-holidays-when-holidays-with-date
11+
(ct/deftest should-return-holidays-when-holidays-in-date-with-date
1212
(ct/are [date calendar expected]
13-
(= expected (holi/holidays (t/date date) calendar))
13+
(= expected (holi/holidays-in-date (t/date date) calendar))
1414
"2020-08-01" "DAY-TWENTY-NINE" []
1515
"2020-07-29" "DAY-TWENTY-NINE" ["Twenty Ninth Day"]
1616
"2020-07-30" "DAY-THREE" []
1717
"2020-08-03" "DAY-THREE" ["Third Day"]))
1818

19-
(ct/deftest should-return-holidays-when-holidays-with-date-time
19+
(ct/deftest should-return-holidays-when-holidays-in-date-with-date-time
2020
(ct/are [date calendar expected]
21-
(= expected (holi/holidays (t/date-time date) calendar))
21+
(= expected (holi/holidays-in-date (t/date-time date) calendar))
2222
"2020-08-01T00:00:00" "DAY-TWENTY-NINE" []
2323
"2020-07-29T11:11:22" "DAY-TWENTY-NINE" ["Twenty Ninth Day"]
2424
"2020-07-30T22:22:22" "DAY-THREE" []
@@ -27,21 +27,21 @@
2727
(ct/deftest
2828
^{:doc "This test relies on TEST-WEEKEND and DAY-THREE, which only list dates in 2020.
2929
Any argument outside 2020 should raise an exception"}
30-
should-throw-when-holidays-with-date-beyond-limit-year
30+
should-throw-when-holidays-in-date-with-date-beyond-limit-year
3131
(ct/are [date calendar]
32-
(thrown-with-msg? ExceptionInfo #"Date is out of bounds" (holi/holidays (t/date date) calendar))
32+
(thrown-with-msg? ExceptionInfo #"Date is out of bounds" (holi/holidays-in-date (t/date date) calendar))
3333
"2021-08-03" "DAY-THREE"
3434
"2019-08-03" "DAY-THREE"))
3535

3636
(ct/deftest
3737
^{:doc "This test relies on TEST-WEEKEND and DAY-THREE, which only list dates in 2020.
3838
Any argument outside 2020 should raise an exception"}
39-
should-throw-when-holidays-with-date-time-beyond-limit-year
39+
should-throw-when-holidays-in-date-with-date-time-beyond-limit-year
4040
(ct/are [date calendar]
41-
(thrown-with-msg? ExceptionInfo #"Date is out of bounds" (holi/holidays (t/date-time date) calendar))
41+
(thrown-with-msg? ExceptionInfo #"Date is out of bounds" (holi/holidays-in-date (t/date-time date) calendar))
4242
"2021-08-03T10:10:10" "DAY-THREE"
4343
"2019-08-03T23:59:59" "DAY-THREE"))
4444

45-
(ct/deftest should-throw-when-holidays-with-inexistent-calendar-or-WEEKEND
46-
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendars: HOL" (holi/holidays (t/date "2020-10-10") "HOL")))
47-
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendar: WEEKEND" (holi/holidays (t/date "2020-10-10") "WEEKEND"))))
45+
(ct/deftest should-throw-when-holidays-in-date-with-inexistent-calendar-or-WEEKEND
46+
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendars: HOL" (holi/holidays-in-date (t/date "2020-10-10") "HOL")))
47+
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendar: WEEKEND" (holi/holidays-in-date (t/date "2020-10-10") "WEEKEND"))))

test/luciolucio/holi/list_test.cljc renamed to test/luciolucio/holi/holidays_in_year_test.cljc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns luciolucio.holi.list-test
1+
(ns luciolucio.holi.holidays-in-year-test
22
(:require [clojure.test :as ct]
33
[luciolucio.holi :as holi]
44
[luciolucio.holi.test-setup :as setup]
@@ -8,9 +8,9 @@
88

99
(ct/use-fixtures :each setup/test-datelist-fixture)
1010

11-
(ct/deftest should-list-the-correct-holidays-for-calendar-and-year-when-list-holidays
11+
(ct/deftest should-list-the-correct-holidays-for-calendar-and-year-when-holidays-in-year
1212
(ct/are [year expected]
13-
(= expected (holi/list-holidays year "TEST-US"))
13+
(= expected (holi/holidays-in-year year "TEST-US"))
1414
2021 [{:date (t/date "2021-01-01") :name "New Year's Day"}
1515
{:date (t/date "2021-01-18") :name "Martin Luther King Jr. Day"}
1616
{:date (t/date "2021-02-15") :name "President's Day"}
@@ -59,14 +59,14 @@
5959
{:date (t/date "2024-11-28") :name "Thanksgiving"}
6060
{:date (t/date "2024-12-25") :name "Christmas"}]))
6161

62-
(ct/deftest should-throw-when-list-holidays-with-year-beyond-limits
63-
(ct/is (thrown-with-msg? ExceptionInfo #"Year is out of bounds" (holi/list-holidays 1942 "TEST-US")))
64-
(ct/is (thrown-with-msg? ExceptionInfo #"Year is out of bounds" (holi/list-holidays 2104 "TEST-US"))))
62+
(ct/deftest should-throw-when-holidays-in-year-with-year-beyond-limits
63+
(ct/is (thrown-with-msg? ExceptionInfo #"Year is out of bounds" (holi/holidays-in-year 1942 "TEST-US")))
64+
(ct/is (thrown-with-msg? ExceptionInfo #"Year is out of bounds" (holi/holidays-in-year 2104 "TEST-US"))))
6565

6666
(ct/deftest
6767
^{:doc "These should say 'No such calendars' before
6868
checking that the year is out of bounds"}
69-
should-throw-when-list-holidays-with-inexistent-calendar-or-WEEKEND
70-
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendars: OMG" (holi/list-holidays 1930 "OMG")))
71-
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendars: WATIZIT" (holi/list-holidays 2200 "WATIZIT")))
72-
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendar: WEEKEND" (holi/list-holidays 2200 "WEEKEND"))))
69+
should-throw-when-holidays-in-year-with-inexistent-calendar-or-WEEKEND
70+
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendars: OMG" (holi/holidays-in-year 1930 "OMG")))
71+
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendars: WATIZIT" (holi/holidays-in-year 2200 "WATIZIT")))
72+
(ct/is (thrown-with-msg? ExceptionInfo #"No such calendar: WEEKEND" (holi/holidays-in-year 2200 "WEEKEND"))))

0 commit comments

Comments
 (0)