The datepicker saga

Part one

So I begin work on a page where user add their details, project is late, taking ages on this page

Nearly done, just need a component to allow users to put in some date of births. Look for react components.

Avoiding that one because fuck Bootstrap.

Ah-ha, that looks good, let's give it a go.

CSS doesn't exist, oh need copy it over from npm dist. Great it applied but...

... WTF it's tiny. Thought it was a problem with my zoom. Nope found the issue in github.com and it's something to do with using REM rather than EM or something, okay someone provided a solution, rather I saw a couple of solutions, after some hacking around I got it working and pasted it in the right location and yes, it's a reasonable size now.

Only it's a bit crap because it only allows scrolling 1 month at a time. No good. Hunting through the docs reveals several options to add year and month drop downs and allow them to be scrolled. Still a bit shit as it only shows certain years, figure I'd set the start date position somewhere at the average.

Wait. The up button on the scroll doesn't even show, it's just a blank 5px button. Mouse scroll doesn't work


... Bailing on that.

Part 2

Okay sod it I'll just make my own three drop down select boxes, day, month and year. Easy.

At this point I take full responsibility and cannot blame any third party. And kids, take this as a lesson to plan out your code fully and make no assumptions on the simplicity of the problem.

For some reason (of which I regretted much) I decided to abstract things so much I made an array of three objects for each drop down. Containing the information to pretty much abstract away the field it was dealing with. This sort of meta programming really screwed with my head, I have lines like the following:

[...].map(optionGroup =>
, 10)

But I was in too deep and had to weave my way through this kind of abstract process like an intrepid explorer chopping through a rain forest with a butter knife.

So I am using React and Redux, decided it was overkill to use Redux to control each field. Only trouble is of course when the user clicks one of the fields, it doesn't make sense in redux to have one of the three fields selected. And I wanted to show the field title as the first option. So I went against good practice and used state to keep track of the fields before they are handed off to the parent/redux. What a nightmare that was.

Possibly the most challenging part was matching my indices with moment.js to get the UI working right, it was such a meta mess when it just shouldn't have taken so stupidly long.

But, I begin to see the light at the end of this tunnel, it's slowly coming together. And when it all clicks into place I sit back and actually quite enjoy my abysmal attempt at clean and easy to read code.

Part 3

Ran the generated timestamp through a converter and I get the day before, oh yeah that's great

Seems like it's dependant on the timezone??!

Nope. Deploying. Bye. I no longer care if daylight savings makes you a day younger.

  • 2
    I feel with you.

    Built a picker once long ago to solve a problem with users from different countries entering dates in different ways.

    It did work but was not very stylish but good enough for 2000.

    Recently found out a colleague still use it in one of our applications :/.

    It was built when ie6 was the new hot browser, it should have been buried by now :(
Add Comment