.
, , . .
, :
, (, ) , ( "-" ), (), () . , .
Joda
, Joda-Time 2.7. :
, Joda-Time MonthDay
, .
MonthDay mdStart = new MonthDay ( DateTimeConstants.NOVEMBER, 1 );
MonthDay mdStop = new MonthDay ( DateTimeConstants.JUNE, 1 );
, , . , " ". , 3-4 .
DateTime target = DateTime.now ( DateTimeZone.forID ( "Africa/Casablanca" ) );
toDateTime
MonthDay
( ) DateTime
, DateTime
. Joda-Time , , .
:
- MonthDay - , DateTime. ( )
- MonthDay - , DateTime. ( )
-, .
DateTime earlierStart = mdStart.toDateTime ( target );
DateTime earlierStop = mdStop.toDateTime ( target );
if ( earlierStart.isAfter ( earlierStop ) ) {
earlierStart = earlierStart.minusYears ( 1 );
}
Joda-Time Interval
.
Interval earlierInterval = new Interval ( earlierStart, earlierStop );
DateTime laterStart = mdStart.toDateTime ( target );
DateTime laterStop = mdStop.toDateTime ( target );
if ( laterStart.isAfter ( laterStop ) ) {
laterStop = laterStop.plusYears ( 1 );
}
Interval laterInterval = new Interval ( laterStart, laterStop );
, DateTime
Interval
. , Joda-Time Half-Open , , . , 1 . , 1 , , 1 , .
Boolean earlierHasTarget = earlierInterval.contains ( target );
Boolean laterHasTarget = laterInterval.contains ( target );
Boolean targetContained = ( earlierHasTarget || laterHasTarget );
java.time
Java 8 java.time, , Joda-Time. Joda-Time, . . , java.time Interval
.