Skip to content

Commit bc29fe7

Browse files
authored
Merge pull request #21 from mrwizard82d1/master
Implement the `As` protocol for two field entities
2 parents bf0f76a + 21c4976 commit bc29fe7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/java_time/single_field.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@
163163
(single-after? [d# o#]
164164
(.isAfter d# o#))
165165
(single-before? [d# o#]
166-
(.isBefore d# o#))))))
166+
(.isBefore d# o#))
167+
jt.c/As
168+
(as* [o# k#]
169+
(jt.c/value (jt.c/property o# k#)))))))
167170

168171
(enumerated-entity DayOfWeek
169172
"Returns the `DayOfWeek` for the given day keyword name (e.g. `:monday`),

test/java_time_test.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,16 @@
644644
(is (= 1 (j/as (j/local-date 2015 1 1) :day-of-month)))
645645
(is (= 2015 (j/as (j/local-date 2015 1 1) :year))))
646646

647+
(testing "temporal-accessor"
648+
(let [month-day-under-test (j/month-day 3 31)]
649+
(is (= 3 (j/as month-day-under-test :month-of-year)))
650+
(is (= 31 (j/as month-day-under-test :day-of-month)))
651+
(is (thrown? Exception (j/as month-day-under-test :year))))
652+
(let [year-month-under-test (j/year-month 2018 3)]
653+
(is (= 2018 (j/as year-month-under-test :year)))
654+
(is (= 3 (j/as year-month-under-test :month-of-year)))
655+
(is (thrown? Exception (j/as year-month-under-test :day-of-month)))))
656+
647657
(testing "multiple"
648658
(is (= [2015 1 1] (j/as (j/local-date 2015 1 1) :year :month-of-year :day-of-month))))
649659

0 commit comments

Comments
 (0)