Sadly, there is no such simple method in Joda-Time.

One solution is to catch the exception and use
DateTimeZone.nextTransition() to find the end of the gap. The code
looks something like:

try {
 date = new LocalDateTime(2009, 2, 29, 2, 30).toDateTime().toDate()
} catch (Exception ex) {
 DateTime dt = new LocalDateTime(2009, 2, 29, 2, 30).minusHours(2).toDateTime();
 dt = new DateTime(timeZone.nextTransition(dt.getMillis()));
 date = dt.toDate();
}

Stephen


2009/4/22 Den Orlov <den.or...@gmail.com>:
> I have LocalDateTime that should be used in external code and so
> converted to Date. If LocalDateTime represents point in time that are
> in DST gap (for example 28 March, 2:30, MSK) then
>
> new LocalDateTime(2009, 2, 29, 2, 30).toDateTime().toDate()
>
> raises Exception when default time zone are set to MSK.
>
> Is there some simple way to do that conversion to DateTime so that
> time point will be rolled to most suitable one? In fact I am trying to
> find some analog of LocalDate.toDateTimeAtStartOfDay()
>
> Den
>
> ------------------------------------------------------------------------------
> Stay on top of everything new and different, both inside and
> around Java (TM) technology - register by April 22, and save
> $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
> 300 plus technical and hands-on sessions. Register today.
> Use priority code J9JMT32. http://p.sf.net/sfu/p
> _______________________________________________
> Joda-interest mailing list
> Joda-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to