Hi Steve,
thanks a lot for your answer.
Took me a while to verify it, but this now works and give me way to propose
a method that allows identical replacement:
public void DateMidnightTest() {
Calendar cal = Calendar.getInstance();
cal.setTime(DateUtil.stringToDate("01/01/2009"));
// On definit l'horaire a 23h59hmin59
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
assertTrue(cal.getTime().equals(new
DateMidnight(2009,1,2).toDateTime().minusSeconds(1).toDate()));
}
Seems like toDateTime() was the missing part.
It's important that I can provide first a method that is equivalent to the
existing.
Then I should be able to move to something more simple where Time is not
taken into account.
cheers,
-jean
Stephen Cresswell-2 wrote:
>
> The other thing you could try is to use new LocalDate() and so remove the
> time aspect completely.
>
> 2009/12/3 Stephen Cresswell <[email protected]>
>
>> I haven't tried this but my guess is that because
>> DateMidnight.minus(long)
>> returns a DateMidnight, you'll always get "midnight". Maybe try...
>>
>> new DateMidnight().toDateTime().minusSeconds(1)
>>
>> Steve
>>
>> 2009/12/3 Jean Seurin <[email protected]>
>>
>>
>>> Hi,
>>>
>>> I'm new to Joda and try to get it adopted in our application.
>>> Legacy code use to set the Date with time being at the last second of a
>>> day,
>>> to ensure a consistant behavior when comparing "date only" time with
>>> this
>>> date.
>>>
>>> To make things clearer, legacy code is crippled with things like that:
>>>
>>> Calendar cal = Calendar.getInstance();
>>> SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
>>> cal.setTime(sdf.parse("01/01/2009"));
>>> cal.set(Calendar.HOUR_OF_DAY, 23);
>>> cal.set(Calendar.MINUTE, 59);
>>> cal.set(Calendar.SECOND, 59);
>>>
>>> i'd like to offer a unique function to replace that, using Joda.
>>>
>>> I've tried to use the minus(..) methods but to no avail.
>>> Here's what I've tried:
>>>
>>> new DateMidnight(2009,1,2).minus(1000);
>>>
>>> Looking at the Java doc, I understand it should be exactly equal to
>>> cal.getTime().
>>> However the getDate() methods return January 1st, at Midnight.
>>>
>>> Minus doesn't seem to do what it is supposed to.
>>>
>>> Obviously I misused it.
>>>
>>> Can any one explain me how to work it, and more generally maybe, the
>>> fastest
>>> way to get the last second before midnight DateTime of a given day?
>>>
>>> rgds,
>>> Jean
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/Getting-the-last-second-of-a-day-with-Joda-tp4104106p4104106.html
>>> Sent from the Joda-Interest mailing list archive at Nabble.com.
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Join us December 9, 2009 for the Red Hat Virtual Experience,
>>> a free event focused on virtualization and cloud computing.
>>> Attend in-depth sessions from your desk. Your couch. Anywhere.
>>> http://p.sf.net/sfu/redhat-sfdev2dev
>>> _______________________________________________
>>> Joda-interest mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>
>>
>>
>
> ------------------------------------------------------------------------------
> Join us December 9, 2009 for the Red Hat Virtual Experience,
> a free event focused on virtualization and cloud computing.
> Attend in-depth sessions from your desk. Your couch. Anywhere.
> http://p.sf.net/sfu/redhat-sfdev2dev
> _______________________________________________
> Joda-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>
--
View this message in context:
http://n2.nabble.com/Getting-the-last-second-of-a-day-with-Joda-tp4104106p4162671.html
Sent from the Joda-Interest mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest