Fork me on GitHub
#clojure-europe
<
2022-05-12
>
RAMart06:05:15

Morning ☀️ 😎

reefersleep07:05:00

Godmorgen 😎

pez07:05:10

Morning!

genRaiy08:05:21

Good morning, from the end of our street

2
practicalli-johnny08:05:16

With all these wonderful pictures I want to come and live on your village 😊

genRaiy09:05:17

please do 🙂

Ben Sless08:05:08

Morning!

😍 5
1
mccraigmccraig09:05:58

good måning, with bonus inversion

😍 1
simongray12:05:14

Maypole?

✔️ 1
lread12:05:19

Goo,ooo,ooo,ooo,ooo,ood morning!

genRaiy13:05:39

Today I used a brute force reduce to calculate the date that is N days before today (or another date) ... just skipped over weekends. I wanted to avoid a library for something seemingly simple. What do you folks think? Crazy - just use a lib or nah, better to code it up?

maleghast13:05:45

any chance you are prepared to share the implementation?

maleghast13:05:39

FWIW I would probably use tick as I like the way that it works / is designed:

(t/<< (t/now)
     (t/new-duration 10 :days))

seancorfield14:05:25

Ugh! Sorry, I'd look at that think WTF is <<?

😂 1
lread14:05:05

Sounds like you’d be ticked off! :drum_with_drumsticks:

facepalm 3
simple_smile 1
seancorfield14:05:10

That's just being clever for its own sake...

1
genRaiy14:05:10

give me a few minutes and I'll share a basic version of the implementation

genRaiy14:05:23

(defn from-date
  [{:keys [year month day]} n-working-days]
  (let [js-date (js/Date. year month day)]
    (reduce (fn [{:keys [working-days] :as from} dec-by]
              (if (>= working-days n-working-days)
                (reduced from)
                (let [_ (.setDate js-date (- (.getDate js-date) dec-by))
                      working-days' (condp = (.getDay js-date)
                                      0 working-days       ; Skip Sunday
                                      6 working-days       ; Skip Saturday
                                      (inc working-days))]
                  {:working-days working-days' 
                   :from-date js-date})))
            {:working-days 0
             :from-date    js-date} (repeat 1))))

genRaiy14:05:07

I should have said that it was working days not just days

😱 1
genRaiy15:05:22

why the scream @U054UD60U? Is the code really that bad?

genRaiy15:05:03

I am not handling holidays etc... so it's not an enterprise implementation 😆

ordnungswidrig15:05:06

Not at all. But that's quite a challenge to compute. Isn't it?

ordnungswidrig15:05:01

When not handling the you should get away with a winter days diff * 5/7 adjusted for the weekday of one edge of the interval.

pez15:05:33

If it's fine with not handling a lot of corner cases, I'd say it's fine to roll your own. But having worked with an app where time was of utter importance (a med reminder app), I know how hairy time stuff is and would use a library I trust if just some corner cases need be address.

maleghast16:05:19

@U04V70XH6 - it does make sense in the paradigm of time and date that Tick provides,

t/<<
is "rewind time" &
t/>>
is "fast-forward time"

maleghast16:05:01

it's admittedly only an obvious visual cue to the stereo / tape generation, but I figure you remember tape... 😉

metal 3
1
maleghast16:05:22

@U04V5V0V4 - If you need working days from Tick you just need to add the appropriate number of weekends to the number of days that you pipe into the subtract function above and there are loads of ways to peel that onion, including ones that could also potentially include national holidays, though you would probably have to implement another library that provides cultural localisation and make some helper functions to see if you needed to add any extra non-weekend non-working days into the Tick maths... 😉

🤕 1
genRaiy17:05:29

Getting the right number of weekends was giving me a headache hence the dumb implementation

genRaiy17:05:57

Also n is small

genRaiy17:05:23

But I agree with @U0ETXRFEW that a library would be better in complex cases.

genRaiy18:05:08

Incidentally it take 200ms to go back 10k days so yeah, quite slow but our case is max 45 which takes ~5ms so I'm not going to sweat

👍 1
lread12:05:10

@U04V5V0V4 not answering our question at all but it made me think. After decades in the industry I got into the habit of reaching for a library. I kind of became a library integrator. Clojure is teaching me many things, but I really like the realization that it is not that hard, and often much much simpler, to code up your own thing in Clojure instead of reaching for a library.

💯 2
dominicm17:05:49

Morning

👋 3
maleghast17:05:22

UTG..? I mean Morning 😉