I'm considering using Joda-Time.
I'm wondering if I should pay attention of what type of object my Interfaces are returning.
Returning Joda-Time objects from my interface signature on the service layer means that every module that use it will have be dependent on Joda-Time instead of the common java.util.Date API.
Are you passing Joda objects around your App modules or do you write wrappers in specific part of your app?
An interval in Joda-Time represents an interval of time from one instant to another instant. Both instants are fully specified instants in the datetime continuum, complete with time zone.
Joda-Time provides a quality replacement for the Java date and time classes. Joda-Time is the de facto standard date and time library for Java prior to Java SE 8. Users are now asked to migrate to java. time (JSR-310). Joda-Time is licensed under the business-friendly Apache 2.0 licence.
Joda-Time provides a comprehensive formatting system. There are two layers: High level - pre-packaged constant formatters. Mid level - pattern-based, like SimpleDateFormat. Low level - builder.
Joda-Time provides support for multiple calendar systems and the full range of time-zones. The Chronology and DateTimeZone classes provide this support. Joda-Time defaults to using the ISO calendar system, which is the de facto civil calendar used by the world.
In the beginning, only return the most suitable type (Joda Objects in this case).
If you learn that someone has a problem with that (which probably won't happen too often), either add a converter method to the interface (so you have, say, getTime()
and now getJavaTime()
or getTimeInMillis()
).
Or add a general purpose helper method which takes an Object (you can treat an unknown instance as Object
anywhere in the code without having to import the actual Joda classes) and returns a plain Java object (java.util.Date
).
What is the alternative ? Transforming jodaTime objects into infamous Calendar/Date objects ?
You chose to get rid of these objects and that's a good decision. Now, if you let other layers use the java date API, they'll go into the kind of bugs and non-sensical behaviours you got rid of by using jodaTime.
I think you should do your users a favor and let them use jodaTime.
Of course it's a design decision that'll add in their code a dependency to jodaTime, but I don't find it questionnable, as you chose jodaTime to write less and better code, and so should they.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With