Here you can find the source of restrictToDaytime(Instant instantToRestrict, Instant thresholdTime, ZoneId userZoneId)
public static Instant restrictToDaytime(Instant instantToRestrict, Instant thresholdTime, ZoneId userZoneId)
//package com.java2s; //License from project: Open Source License import java.time.*; public class Main { private static final int latestHourForAutomatedMessages = 20; private static final int earliestHourForAutomatedMessage = 8; private static final LocalTime latestHour = LocalTime.of(latestHourForAutomatedMessages, 0); private static final LocalTime earliestHour = LocalTime.of(earliestHourForAutomatedMessage, 0); public static Instant restrictToDaytime(Instant instantToRestrict, Instant thresholdTime, ZoneId userZoneId) { ZonedDateTime zonedDateTime = instantToRestrict.atZone(userZoneId); if (zonedDateTime.getHour() <= earliestHourForAutomatedMessage) { zonedDateTime = ZonedDateTime.of(zonedDateTime.toLocalDate(), earliestHour, userZoneId); return thresholdTime == null || zonedDateTime.toInstant().isBefore(thresholdTime) ? zonedDateTime.toInstant() : thresholdTime;/*from w w w . j a va 2 s . c o m*/ } else if (zonedDateTime.getHour() >= latestHourForAutomatedMessages) { zonedDateTime = ZonedDateTime.of(zonedDateTime.toLocalDate(), latestHour, userZoneId); return zonedDateTime.toInstant(); } else { return instantToRestrict; } } }