protected static Temporal makeResult ( Map < Component , Integer > values , LocalDate now , ZoneId timezone ) { LocalDate date = null ; LocalTime time = null ; if ( values . containsKey ( Component . MONTH ) ) { int year = yearFrom2Digits ( ExpressionUtils . getOrDefault ( values , Component . YEAR , now . getYear ( ) ) , now . getYear ( ) ) ; int month = values . get ( Component . MONTH ) ; int day = ExpressionUtils . getOrDefault ( values , Component . DAY , 1 ) ; try { date = LocalDate . of ( year , month , day ) ; } catch ( DateTimeException ex ) { return null ; // not a valid date } } if ( ( values . containsKey ( Component . HOUR ) && values . containsKey ( Component . MINUTE ) ) || values . containsKey ( Component . HOUR_AND_MINUTE ) ) { int hour , minute , second , nano ; if ( values . containsKey ( Component . HOUR_AND_MINUTE ) ) { int combined = values . get ( Component . HOUR_AND_MINUTE ) ; hour = combined / 100 ; minute = combined - ( hour * 100 ) ; second = 0 ; nano = 0 ; } else { hour = values . get ( Component . HOUR ) ; minute = values . get ( Component . MINUTE ) ; second = ExpressionUtils . getOrDefault ( values , Component . SECOND , 0 ) ; nano = ExpressionUtils . getOrDefault ( values , Component . NANO , 0 ) ; if ( hour < 12 && ExpressionUtils . getOrDefault ( values , Component . AM_PM , AM ) == PM ) { hour += 12 ; } else if ( hour == 12 && ExpressionUtils . getOrDefault ( values , Component . AM_PM , PM ) == AM ) { hour -= 12 ; } } try { time = LocalTime . of ( hour , minute , second , nano ) ; } catch ( DateTimeException ex ) { return null ; // not a valid time } } if ( values . containsKey ( Component . OFFSET ) ) { timezone = ZoneOffset . ofTotalSeconds ( values . get ( Component . OFFSET ) ) ; } if ( date != null && time != null ) { return ZonedDateTime . of ( date , time , timezone ) ; } else if ( date != null ) { return date ; } else if ( time != null ) { return ZonedDateTime . of ( now , time , timezone ) . toOffsetDateTime ( ) . toOffsetTime ( ) ; } else { return null ; } }
Makes a date or datetime or time object from a map of component values