Groovy web console

subscribe to the feed Subscribe
to this


Published 2 months ago by Marcello de Sales with tags LocalDateTime
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
import java.time.*;
import java.util.Arrays;
import java.util.TimeZone;

def getMillis(LocalDateTime dateTime) {
    return dateTime.atZone(ZoneId.of("America/Sao_Paulo")).toInstant().toEpochMilli();

def LocalDateTime getLocalDateTime(long milliseconds) {    
LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(milliseconds), TimeZone.getDefault().toZoneId());
    return dateTime.atZone(ZoneId.of("UTC"))

 * @param dateTime
 * @return The start and end hour of the day for searches
def void getDateZeroHoraMidnightInterval(LocalDateTime dateTime) {
    LocalDateTime earlyMorning = dateTime.toLocalDate().atStartOfDay();
    LocalDateTime lateNight = earlyMorning.plusHours(23).plusMinutes(59);
    println ("Time is ${dateTime} and grace period is ${dateTime.plusMinutes(20)}")
    println ("Morning ${earlyMorning} and night ${lateNight}")