tags:

views:

128

answers:

3

I'd like to know if there is a "standard" Java implementation of a DateBuilder before I build one myself. I have looked in the java API and Apache Commons and can't seem to find reference to one.

I am looking for something simple that would implement an interface like:

Date date = new DateBuilder().month(2).year(1).build();

where date would be July 12, 2010 (assuming today is May 12).

Also, please no references to Joda Time.

+3  A: 

No, but you can accomplish the same (just not in a single line / chained method calls) with the Calendar object:

//assuming your use case is "add 1 year and 2 months to the current date/time"
Calendar cal = Calendar.getInstance()
cal.clear();
cal.add(Calendar.MONTH, 2);
cal.add(Calendar.YEAR, 1);

It should be trivial to wrap Calendar.add() and Calendar.set() yourself in the Builder pattern.

matt b
I presume that's exactly what the OP was planning to do, if there are no standard libraries that provide equivalent functionality. (In other words, this is a non-answer, IMO.)
Chris Jester-Young
Yeah well I felt like "Nope" was too short :)
matt b
A: 

Google codesearch turns up this

Any use?

Paul
Jitterbit isn't exactly a standard library, is it? Nice try though.
Chris Jester-Young
Agreed, but then the answer is "no", I think. But at least now the OP has a way of getting an implementation :)
Paul
A: 

You could wait for JSR-310. That will be the standard in the future when it is implemented!

Karl the Pagan