This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-06-18
Channels
- # announcements (6)
- # babashka (16)
- # beginners (194)
- # calva (20)
- # cider (34)
- # clj-kondo (38)
- # clojure (89)
- # clojure-europe (10)
- # clojure-finland (15)
- # clojure-italy (2)
- # clojure-nl (15)
- # clojure-sg (7)
- # clojure-spec (15)
- # clojure-uk (86)
- # clojurebridge (1)
- # clojurescript (60)
- # community-development (11)
- # conjure (13)
- # core-async (48)
- # core-typed (3)
- # cursive (22)
- # datascript (8)
- # datomic (40)
- # duct (11)
- # emacs (3)
- # figwheel-main (22)
- # fulcro (45)
- # graphql (1)
- # helix (9)
- # hoplon (15)
- # hugsql (7)
- # jobs-discuss (47)
- # juxt (7)
- # kaocha (21)
- # luminus (1)
- # malli (13)
- # meander (2)
- # off-topic (52)
- # parinfer (19)
- # re-frame (66)
- # reagent (1)
- # reitit (3)
- # ring-swagger (1)
- # rum (2)
- # shadow-cljs (72)
- # spacemacs (5)
- # sql (4)
- # timbre (5)
- # tools-deps (15)
- # vim (5)
- # vrac (7)
I'm using this function with tick to return the 'last day of the month 3 months from now' - is there a more elegant way to do this?
(defn next-period-date [date]
(str
(t/- (apply t/new-date
(let [new-month (+ 1 (mod (+ 3 (t/int (t/month date))) 12))]
[(if (< new-month 5)
(inc (t/int (t/year date)))
(t/int (t/year date)))
new-month
1]))
(t/new-period 1 :days))))
I have first-of-month and last-of-month helpers - then i'd combine that with (t/new-period 3 :months)
(defn first-day-of-month
([] (first-day-of-month (t/today)))
([date] (-> (t/new-date (int-year date) (int-month date) 1)
(t/at (t/midnight)))))
(defn last-day-of-month
"date - tick/date or similar"
([] (last-day-of-month (t/today)))
([date]
(let [the-first (first-day-of-month date)]
(t/end (t/bounds the-first
(t/- (t/+ the-first (t/new-period 1 :months))
(t/new-period 1 :days)))))))
(last-day-of-month (t/+ (t/today) (t/new-period 3 :months)))
@allaboutthatmace1789 I think you want to be looking at t/year-month
like so:
(defn next-period-date [date]
(-> (t/+ date (t/new-period 3 :months))
t/year-month
t/end
(t/- (t/new-period 1 :days))
t/date))
it's a bit annoying that we need to subtract a day as the penultimate step, but then I guess the end
of a month is technically considered to be in the next month 🤷