Hacker News new | ask | show | jobs
by fougerejo 4075 days ago
One month ago I tried to find a nice datepicker directive for angular. "tried". Couldn't find one that wasn't broken somewhere. Ended up using the angular-ui one, and spent hours and hours patching the brokeness (options not being taken into account, dates needed to be formatted for the initialisation, etc).

That's where I realised that even an active ecosystem as the angular one is not enough to produce quality libraries/modules for basic stuff as a datepicker..

6 comments

I'm actually relieved to find out it isn't just me and that others have been frustrated by this too.

My boss thinks I'm an idiot because I struggled with ui-datepicker in angular (being used in a search field). I had to over-explain that it is broken and still noone believes me when I tell them that the Jenkins build gives a different result from the same build but on localhost.

The second time around went better as I was forewarned, but then I had to have 2 datepickers (from and to dates) and that broke it scope-wise.

It should be mentioned, the UI Bootstrap one has a lot of fixes in master currently that addresses the issues - we are close to the 0.13.0 release (after work by a new core team that was assembled a month and a half ago), which should address the problems with Angular 1.3 present in 0.12. Angular 1.4 compatibility should be quick from there, along with massive performance improvements in 0.13.1.
It's not a particularly great wrapper (I've had to handle a couple minor issues in a further wrapper directive), but for the two-pickers situation where you want a range, I've recently used https://github.com/fragaria/angular-daterangepicker

Which is itself just a directive wrapper around Dan Grossman's DateRange Picker for Bootstrap https://github.com/dangrossman/bootstrap-daterangepicker

Of course, those have a lot of dependencies, so if the app isn't using bootstrap/moment/etc. it isn't as useful.

Same experience here. Caught me by surprise, thought I'd just inject one of many solid ones... Ended up building something custom myself (which is a bit of a pain as dates in JS isn't the most straightforward thing in the world).
Oh yes, I had to use it as a range as well, and of course it's not supported, so you need to do everything by hand on the controller..
AngularStrap has one which works rather well - https://mgcrea.github.io/angular-strap/#/datepickers
To second this with my own experience: Very many issues in angular-ui can be resolved by using angular-strap instead.
I used the angularstrap one, it's pretty good!
Dates are far more complex to manage than most people think. Even though a datepicker is something basic needed on most websites, it seems it needs a lot of effort to create a good one which works everywhere.
> Even though a datepicker is something basic needed on most websites

This is why I don't understand the incredibly bad support for the HTML date/time inputs (http://caniuse.com/#feat=input-datetime)

In theory they allow using the platform convention (i.e. on iOS the native datepicker is usually much nicer than whatever you can do in HTML).

Luckily Spartan (new Internet Explorer) will support it. Unfortunately given the recent track record of Safari development, I don't think we'll see support across all browsers anytime soon.

Indeed, I did my best to keep the dependencies minimal in this one. Although it's angular reliant it only has one dependency to momentJS
It's a bit weird, really. Almost all systems have some dependency on modifying dates and times, yet many big frameworks and languages have completely broken support for it.

Both Java and Javascript, which is the languages I know best, have had big issues in the past. One had to use other libraries (Joda and Moment comes to mind), but that again is a problem when other libraries again doesn't use the same libraries for handling dates. Java 8 fixes some of this, and browser support has fixed some of the major ones in JS, but it will take a long time until one can be completely free of the hassle.

At my work, even in production we still have to use Joda Time to support proper datetime stamps. Momentjs is pretty much the same for JS at this point. I think my datepicker works pretty well, I just added a demo if you visit the github page at http://mobinni.github.io/material-date-picker/ you can test it.
Technically you are right, but I find that as a developer when management decides on a certain path of technology you have to work around it's flaws and try to make something that has the look and feel of something made with quality, even if the code will turn out ugly 99% of the time
We use angular-ui-date https://github.com/angular-ui/ui-date, which works pretty well for us.