Joda Time: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Jochen (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „__TOC__ == How to detect an ambiguous DST overlap in Joda Time? == Take advantage of <code>withEarlierOffsetAtOverlap()</code> <syntaxhighlight lang="java"…“) |
Jochen (Diskussion | Beiträge) |
||
| (2 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 4: | Zeile 4: | ||
== How to detect an ambiguous DST overlap in Joda Time? == | == How to detect an ambiguous DST overlap in Joda Time? == | ||
Take advantage of <code>withEarlierOffsetAtOverlap()</code> | Take advantage of <code>withEarlierOffsetAtOverlap()</code>. | ||
<syntaxhighlight lang="java"> | <syntaxhighlight lang="java"> | ||
Aktuelle Version vom 28. September 2016, 21:59 Uhr
How to detect an ambiguous DST overlap in Joda Time?
Take advantage of withEarlierOffsetAtOverlap().
public static boolean isInOverlap(LocalDateTime ldt, DateTimeZone dtz)
{
DateTime dt1 = ldt.toDateTime(dtz).withEarlierOffsetAtOverlap();
DateTime dt2 = dt1.withLaterOffsetAtOverlap();
return dt1.getMillis() != dt2.getMillis();
}
public static void test()
{
// CET DST rolls back at 2011-10-30 2:59:59 (+02) to 2011-10-30 2:00:00 (+01)
final DateTimeZone dtz = DateTimeZone.forID("CET");
LocalDateTime ldt1 = new LocalDateTime(2011,10,30,1,50,0,0); // not in overlap
LocalDateTime ldt2 = new LocalDateTime(2011,10,30,2,50,0,0); // in overlap
System.out.println(ldt1 + " is in overlap? " + isInOverlap(ldt1, dtz));
System.out.println(ldt2 + " is in overlap? " + isInOverlap(ldt2, dtz));
}