Example usage for java.time LocalDateTime atZone

List of usage examples for java.time LocalDateTime atZone

Introduction

In this page you can find the example usage for java.time LocalDateTime atZone.

Prototype

@Override
public ZonedDateTime atZone(ZoneId zone) 

Source Link

Document

Combines this date-time with a time-zone to create a ZonedDateTime .

Usage

From source file:org.apache.solr.client.solrj.io.stream.eval.TemporalEvaluatorsTest.java

@Test
public void testFunctionsLocalDateTime() throws Exception {

    LocalDateTime localDateTime = LocalDateTime.of(2017, 12, 5, 23, 59);
    Date aDate = Date.from(localDateTime.atZone(ZoneOffset.UTC).toInstant());
    testFunction("year(a)", localDateTime, 2017);
    testFunction("month(a)", localDateTime, 12);
    testFunction("day(a)", localDateTime, 5);
    testFunction("hour(a)", localDateTime, 23);
    testFunction("minute(a)", localDateTime, 59);
    testFunction("epoch(a)", localDateTime, aDate.getTime());
}

From source file:net.ljcomputing.ecsr.security.service.impl.JwtTokenServiceImpl.java

/**
 * Calculate the new refresh date./*from  www .j a va 2 s  . c  om*/
 *
 * @return the date
 */
@SuppressWarnings("unused")
private Date refreshDate() {
    final LocalDateTime refreshLdt = ldtNow.plusMinutes(refreshTokenExpTime); // NOPMD
    final ZonedDateTime zdt = refreshLdt.atZone(ZONE_ID); // NOPMD
    final Instant instant = zdt.toInstant(); // NOPMD
    return Date.from(instant); // NOPMD
}

From source file:com.orange.clara.cloud.servicedbdumper.task.job.JobFactoryTest.java

@Test
public void when_purge_finished_jobs_and_jobs_in_error_exist_it_should_delete_job_which_pass_expiration_and_have_null_database_target_and_source_and_service_instance() {
    Job jobNotExpired = new Job();
    jobNotExpired.setUpdatedAt(new Date());
    jobNotExpired.setDatabaseRefSrc(new DatabaseRef());

    Date date = new Date();
    LocalDateTime localDateTime = LocalDateTime.from(date.toInstant().atZone(ZoneId.systemDefault()))
            .minusMinutes(jobFinishedDeleteExpirationMinutes + 1);
    Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
    Job jobExpired = new Job();
    jobExpired.setUpdatedAt(Date.from(instant));

    when(jobRepo.findByJobEventOrderByUpdatedAtDesc(anyObject()))
            .thenReturn(Arrays.asList(jobNotExpired, jobExpired));
    jobFactory.purgeFinishedJob();/*from  w w w .java  2 s .  co  m*/
    verify(jobRepo, times(1)).delete((Job) notNull());
}

From source file:net.ljcomputing.ecsr.security.service.impl.JwtTokenServiceImpl.java

/**
 * Calculate the new expiration date from now.
 *
 * @return the date/* w w  w .  j a  v a  2 s.co  m*/
 */
private Date expirationDate() {
    final LocalDateTime expirationLdt = ldtNow.plusMinutes(tokenExpirationTime); // NOPMD
    final ZonedDateTime zdt = expirationLdt.atZone(ZONE_ID); // NOPMD
    final Instant instant = zdt.toInstant(); // NOPMD
    return Date.from(instant); // NOPMD

}

From source file:jef.tools.DateUtils.java

/**
 * Converts LocalDateTime to java.util.Date (null safety)
 * @param LocalDateTime//from w w  w. j  a v  a2 s  . c  om
 * @return java.util.Date
 */
public static Date fromLocalDateTime(LocalDateTime value) {
    return value == null ? null : Date.from(value.atZone(ZoneId.systemDefault()).toInstant());
}

From source file:org.onosproject.drivers.ciena.waveserver.rest.CienaRestDevice.java

private long parseAlarmTime(String time) {
    /*/* w  w  w. j a  v  a 2 s. c  o  m*/
     * expecting WaveServer time to be set to UTC.
     */
    try {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT);
        LocalDateTime localDateTime = LocalDateTime.parse(time, formatter);
        return localDateTime.atZone(ZoneId.of(UTC)).toInstant().toEpochMilli();
    } catch (DateTimeParseException e2) {
        log.error("unable to parse time {}, using system time", time);
        return System.currentTimeMillis();
    }
}

From source file:cn.afterturn.easypoi.excel.export.base.ExportCommonService.java

private Object dateFormatValue(Object value, ExcelExportEntity entity) throws Exception {
    Date temp = null;//ww  w. j a v a2  s  .  co  m
    if (value instanceof String && StringUtils.isNoneEmpty(value.toString())) {
        SimpleDateFormat format = new SimpleDateFormat(entity.getDatabaseFormat());
        temp = format.parse(value.toString());
    } else if (value instanceof Date) {
        temp = (Date) value;
    } else if (value instanceof Instant) {
        Instant instant = (Instant) value;
        temp = Date.from(instant);
    } else if (value instanceof LocalDate) {
        LocalDate localDate = (LocalDate) value;
        temp = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
    } else if (value instanceof LocalDateTime) {
        LocalDateTime localDateTime = (LocalDateTime) value;
        temp = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
    } else if (value instanceof java.sql.Date) {
        temp = new Date(((java.sql.Date) value).getTime());
    } else if (value instanceof java.sql.Time) {
        temp = new Date(((java.sql.Time) value).getTime());
    } else if (value instanceof java.sql.Timestamp) {
        temp = new Date(((java.sql.Timestamp) value).getTime());
    }
    if (temp != null) {
        SimpleDateFormat format = new SimpleDateFormat(entity.getFormat());
        if (StringUtils.isNotEmpty(entity.getTimezone())) {
            format.setTimeZone(TimeZone.getTimeZone(entity.getTimezone()));
        }
        value = format.format(temp);
    }
    return value;
}

From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java

public void mouseMoved(MouseEvent e, Vector3d point) {
    HEKEvent lastHEKEvent = mouseOverHEKEvent;

    LocalDateTime in = Plugins.SINGLETON.getCurrentDateTime();
    if (in != null) {
        Date currentDate = Date.from(in.atZone(ZoneId.systemDefault()).toInstant());

        mouseOverHEKEvent = null;/*from  www . j  a  v a  2 s. c o  m*/
        mouseOverPosition = null;

        List<HEKEvent> toDraw = HEKCache.getSingletonInstance().getModel().getActiveEvents(currentDate);
        if (toDraw.size() > 0) {
            for (HEKEvent evt : toDraw) {
                SphericalCoord stony = evt.getStony(currentDate);
                Vector3d coords = HEKEvent.convertToSceneCoordinates(stony, currentDate);

                double deltaX = Math.abs(point.x - coords.x);
                double deltaY = Math.abs(-point.y - coords.y);
                double deltaZ = Math.abs(point.z - coords.z);
                if (deltaX < 10000000 && deltaZ < 10000000 && deltaY < 10000000) {
                    mouseOverHEKEvent = evt;
                    mouseOverPosition = new Point(e.getX(), e.getY());
                }

            }

            if (lastHEKEvent == null && mouseOverHEKEvent != null) {
                lastCursor = Plugins.getCursor();
                Plugins.setCursor(CURSOR_HELP);
            } else if (lastHEKEvent != null && mouseOverHEKEvent == null) {
                Plugins.setCursor(lastCursor);
            }
        }
    }

}

From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java

@Override
public void render(GL2 gl, PluginLayer _imageParams) {
    if (isVisible()) {
        LocalDateTime in = Plugins.SINGLETON.getCurrentDateTime();
        if (in != null) {
            Date currentDate = Date.from(in.atZone(ZoneId.systemDefault()).toInstant());
            List<HEKEvent> toDraw = HEKCache.getSingletonInstance().getModel().getActiveEvents(currentDate);
            if (toDraw != null && toDraw.size() > 0) {
                gl.glDisable(GL2.GL_TEXTURE_2D);
                gl.glEnable(GL2.GL_CULL_FACE);
                gl.glEnable(GL2.GL_LINE_SMOOTH);
                gl.glEnable(GL2.GL_BLEND);

                for (HEKEvent evt : toDraw)
                    drawPolygon(gl, evt, currentDate);

                gl.glDisable(GL2.GL_LINE_SMOOTH);

                gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
                gl.glDisable(GL2.GL_DEPTH_TEST);
                gl.glEnable(GL2.GL_TEXTURE_2D);
                gl.glColor4f(1.0f, 1.0f, 1.0f, 1);

                for (HEKEvent evt : toDraw)
                    drawIcon(gl, evt, currentDate);

                gl.glDisable(GL2.GL_TEXTURE_2D);
                gl.glDisable(GL2.GL_BLEND);
                gl.glEnable(GL2.GL_DEPTH_TEST);
                gl.glDisable(GL2.GL_CULL_FACE);
            }//from  www  .  ja v  a2 s. c  om
        }
    }
}

From source file:onl.area51.httpd.action.Request.java

default Request addHeader(String n, LocalDateTime dt) {
    return addHeader(n, dt.atZone(LONDON));
}