tags:

views:

903

answers:

6

I want to convince the architecture manager to include the joda time jar in our product.

Do you know any disadvantages in using it?

I think joda time needs to be constantly updated because of the files that it includes. And that is a disadvantage. Maybe I am wrong.

Could you provide some clarity on the subject?

Thanks

+1  A: 

I haven't used Joda Time personally, but I have heard that Java 7 is going to have a new date/time API by the author of Joda Time.

R. Bemrose
+1  A: 

In the past, I've encountered companies that didn't want to incorporate third party open source software, or at least required the company lawyer to certify that the license wasn't going to expose them to any sort of liability or have a viral effect on their product.

As with any third party libraries, you should probably put it into source control so you can find the version that you shipped with particular releases of your code in case something goes wrong.

Paul Tomblin
+5  A: 

The biggest issue that we had when using Joda Time was with integration with Spring and Tapestry, as they both wanted to use the built-in Date and Time. We were constantly writing wrappers in getters/setters for date and time: either we would store it as Joda Time and one set of getters/setters passed it through and the other would convert on the fly, and some classes stored it internally as a Java Date/Time, and the Joda getter/setter had to switch it on the fly.

Basically, it was a headache because the classes are similarly named, and unless you can get your entire architecture (including other libraries you're integrating) to switch to Joda Time, you are going to write more wrapper code than you are likely to save by using the Joda libraries.

Matt Poush
I don't know about Tapestry, but in Spring it's pretty easy to write your own converters, so certainly the Spring *config* file could easily handle Joda Time. Some of its own libraries might be more of a pain, admittedly.
Jon Skeet
+8  A: 

I've had almost entirely positive experiences with Joda Time. My one problem was when trying to construct my own time zone (for legitimate reasons, I assure you :) I got some very weird exceptions, and the documentation wasn't very good for that particular use case.

However, for the most part it's been a joy to use - immutability makes code a lot easier to reason about, and thread-safety for formatters is hugely useful.

Yes, there are files to keep up to date - but at least you can keep them up to date. It's not like they contain things which were unnecessary with Java's built-in stuff, it's just that with Java's mechanism you just couldn't keep information like timezones up to date without significant hackery!

Basically, +1 for using Joda Time. The Java date/time API is one of the worst bits of the Java platform, IMO.

Jon Skeet
Can someone provide details on Joda Time updates? Specifically, I want to know if Joda Time forces you to keep the files up to date. The business I work at is ultra-conservative on updating its libraries (it's like pulling teeth to get them to update, let alone request a new one) and I'd like to know how this works before I make the request. For instance, if Joda Time just stops working if it doesn't find updated files, then it's too risky.
InverseFalcon
@InverseFalcon see http://joda-time.sourceforge.net/tz_update.html
matt b
A: 

Parleys hosts a presentation by Stephen Colebourne about JSR-310, mr. Colbourne the author of Joda-Time and JSR-310. He starts out by explaining the weaknesses of the standard date/time support in Java and why you'd want to use an alternative. It may be helpful to show this presentation to your architecture manager. I can't seem to deep-link

The reason Joda-Time updates its timezone file fairly often is because timezone data changes all the time, often on short notice (today on slashdot: leap second added on 2008-12-31) and not always scientifically motivated (e.g. I recall some pacific island state changed its time zone to be the first country to enter the year 2000).

Barend
+3  A: 

In my opinion, the most important drawback in Joda Time is about precision: many databases store timestamps with microsecond (or even nanosecond) precision. Joda-time goes only to milliseconds. This is not acceptable to me: all "data model" classes that I use need to reflect the full precision of the data in my database. Approximations or truncations of my data by a library just don't cut it.

Here is the reasoning behind the choice of millisecond precision, taken from the JSR-310 mailing list:

"Joda-Time chose to use milliseconds as it made conversions to Date and Calendar easier." - S. Colebourne

Easier for whom? The author of the library, one would assume... Incorrect design decision, in my opinion, when almost all databases store times to microsecond/nanosecond precision. The disregard for database values is worrying.

John O
I can see microsecond or nanosecond precision being important if you are problem domain deals with sub-atomic particles. And I can also understand that if your DB has micro/nano values, you don't want those truncated. But for 99% of the use cases out there, millisecond accuracy is quite sufficient.
Tauren
Oracle, DB2, and PostgreSQL can all store timestamp values to microsecond or greater precision. Those are hardly obscure databases, now are they?
John O
John O - I said nothing of the database being obscure. My point is that for most use cases, that kind of precision doesn't matter. Just because your database CAN store that precision doesn't mean that you must. Joda time is a good tool and not worth eliminating unless your use case requires higher precision dates. For these situations, simply store dates with only millisecond precision if you don't want approximations or truncations to occur. Of course, if your application requires micro or nano precision, then Joda time might not be the best tool for the job.
Tauren