Example usage for java.time ZonedDateTime toInstant

List of usage examples for java.time ZonedDateTime toInstant

Introduction

In this page you can find the example usage for java.time ZonedDateTime toInstant.

Prototype

default Instant toInstant() 

Source Link

Document

Converts this date-time to an Instant .

Usage

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

/**
 * Calculate the new refresh date./*from  w w w .j  a  v  a  2s . c o m*/
 *
 * @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:net.ljcomputing.ecsr.security.service.impl.JwtTokenServiceImpl.java

/**
 * Calculate the new expiration date from now.
 *
 * @return the date/*from   www .j a  v a2  s .  c  om*/
 */
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:io.stallion.jobs.JobCoordinator.java

@Override
public void run() {

    if (Settings.instance().getLocalMode()
            && ("prod".equals(Settings.instance().getEnv()) || "qa".equals(Settings.instance().getEnv()))) {
        Log.info(/*from w w w .  j a va 2  s. c o m*/
                "Running localMode, environment is QA or PROD, thus not running jobs. Do not want to run production jobs locally!");
        return;
    }

    while (!shouldShutDown) {
        try {
            executeJobsForCurrentTime(utcNow());
        } catch (Exception e) {
            Log.exception(e, "Error executing jobs in the main job coordinator loop!!!");
        }

        // Find the seconds until the next minute, sleep until 10 seconds into the next minute
        ZonedDateTime now = utcNow();
        ZonedDateTime nextMinute = now.withSecond(0).plusMinutes(1);
        Long waitSeconds = (nextMinute.toInstant().getEpochSecond() - now.toInstant().getEpochSecond()) + 10;
        try {
            Thread.sleep(waitSeconds * 1000);
        } catch (InterruptedException e) {
            break;
        }

    }

    // Shut down the thread pool
    // Wait for everything to exit

}

From source file:com.github.ithildir.airbot.service.impl.AirNowMeasurementServiceImpl.java

private long _parseTime(String dateString, String timeString, String timeZoneString) {

    int year = Integer.parseInt(dateString.substring(6)) + 2000;
    int month = Integer.parseInt(dateString.substring(0, 2));
    int dayOfMonth = Integer.parseInt(dateString.substring(3, 5));
    int hour = Integer.parseInt(timeString.substring(0, timeString.length() - 3));
    int minute = Integer.parseInt(timeString.substring(timeString.length() - 2));

    ZoneId zoneId = ZoneId.of(timeZoneString, _shortZoneIds);

    ZonedDateTime zonedDateTime = ZonedDateTime.of(year, month, dayOfMonth, hour, minute, 0, 0, zoneId);

    Instant instant = zonedDateTime.toInstant();

    return instant.toEpochMilli();
}

From source file:it.tidalwave.northernwind.frontend.ui.component.rssfeed.DefaultRssFeedViewController.java

@Override
protected void addFullPost(final @Nonnull it.tidalwave.northernwind.core.model.Content post)
        throws IOException, NotFoundException {
    final ZonedDateTime blogDateTime = post.getProperties().getDateTimeProperty(DATE_KEYS, TIME0);
    // FIXME: compute the latest date, which is not necessarily the first
    if (feed.getLastBuildDate() == null) {
        feed.setLastBuildDate(Date.from(blogDateTime.toInstant()));
    }/*from   w  ww .  j ava 2 s. c om*/

    final ResourceProperties postProperties = post.getProperties();
    final Item item = new Item();
    final Content content = new Content();
    // FIXME: text/xhtml?
    content.setType("text/html"); // FIXME: should use post.getResourceFile().getMimeType()?
    content.setValue(postProperties.getProperty(PROPERTY_FULL_TEXT));
    item.setTitle(postProperties.getProperty(PROPERTY_TITLE, ""));
    //        item.setAuthor("author " + i); TODO
    item.setPubDate(Date.from(blogDateTime.toInstant()));
    item.setContent(content);

    try {
        // FIXME: manipulate through site.createLink()
        final String link = linkBase.replaceAll("/$", "") + post.getExposedUri().asString() + "/";
        final Guid guid = new Guid();
        guid.setPermaLink(true);
        guid.setValue(link);
        item.setGuid(guid);
        item.setLink(link);
    } catch (NotFoundException e) {
        // ok. no link
    }

    items.add(item);
}

From source file:com.cohesionforce.dis.ConvertCSV.java

public void run() {

    int count = 0;

    System.out.println("Opening file to convert: " + inputFile);
    BufferedReader br;/*from w  ww .jav  a2 s. co  m*/
    try {
        br = new BufferedReader(new FileReader(inputFile));
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
        return;
    }

    startWriters();
    marking.setCharacterSet(0);

    dr.setDeadReckoningAlgorithm(2);
    dr.setEntityLinearAcceleration(zeroVector);
    dr.setEntityAngularVelocity(zeroVector);

    System.out.println("Starting to convert PDUs");

    while (done == false) {
        String line = null;
        try {
            line = br.readLine(); // throw away header

            // medallion, hack_license, vendor_id, rate_code,
            // store_and_fwd_flag,pickup_datetime,dropoff_datetime,passenger_count,
            // trip_time_in_secs,trip_distance,pickup_longitude,pickup_latitude,
            // dropoff_longitude,dropoff_latitude
            while ((line = br.readLine()) != null) {
                String[] pieces = line.split(cvsSplitBy);

                String medallion = pieces[0];

                LocalDateTime localTime = LocalDateTime.from(formatter.parse(pieces[5]));
                ZonedDateTime zoneTime = localTime.atZone(ZoneId.of("America/New_York"));
                long ts = zoneTime.toInstant().toEpochMilli();

                EntityStatePdu output = getNewEntityState(medallion);
                output.setTimestamp(ts);

                // Create EntityLocation from string
                double plon = Double.parseDouble(pieces[10]);
                double plat = Double.parseDouble(pieces[11]);
                Vector3Double loc = getLocation(plon, plat);
                output.setEntityLocation(loc);

                logPdu(output, 1);

                if (++count % 100000 == 0) {
                    System.out.println("Converted " + count + " PDUs");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        done = true;
    } // end
    try {
        br.close();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    System.out.print("Waiting on writers to clear their queues");

    boolean emptyQueue = false;
    while (!emptyQueue)

    {
        emptyQueue = true;
        for (LogWriter<?> writer : writers) {
            // If any queue is not empty, sleep and check again
            if (!writer.getQueue().isEmpty()) {
                try {
                    emptyQueue = false;
                    System.out.print(".");
                    Thread.sleep(1000);
                    break;
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    System.out.println("");
    System.out.println("PDUs converted: " + count);
    System.out.println("Shutting down logging threads");
    threadGroup.interrupt();

    int tries = 0;
    while (threadGroup.activeCount() > 0 && tries < 10)

    {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }
        ++tries;
    }
    System.out.println("Completed logging threads shutdown");

}

From source file:com.github.aptd.simulation.elements.IBaseElement.java

@IAgentActionFilter
@IAgentActionName(name = "nextactivation/set")
private void setNextActivation(@Nullable final ZonedDateTime p_datetime) throws Exception {
    if (p_datetime == null)
        throw new IllegalArgumentException("next activation time must not be null");

    final Instant l_instant = p_datetime.toInstant();
    if (l_instant.compareTo(m_time.current()) <= 0)
        throw new IllegalArgumentException("next activation time must be in the future");

    m_nextactivation = l_instant;//from   w ww . jav  a 2 s  .co  m
}

From source file:it.tidalwave.northernwind.frontend.ui.component.blog.htmltemplate.HtmlTemplateBlogViewController.java

/*******************************************************************************************************************
 *
 * {@inheritDoc}/* w w  w  .  j a  v  a 2s .  c om*/
 *
 ******************************************************************************************************************/
private void addPost(final @Nonnull Content post, final boolean addBody) throws IOException, NotFoundException {
    log.debug("addPost({}, {})", post, addBody);
    final ResourceProperties properties = post.getProperties();
    final StringBuilder htmlBuilder = new StringBuilder();

    final ZonedDateTime blogDateTime = properties.getDateTimeProperty(DefaultBlogViewController.DATE_KEYS,
            DefaultBlogViewController.TIME0);
    final String idPrefix = "nw-" + view.getId() + "-blogpost-" + blogDateTime.toInstant().toEpochMilli();
    htmlBuilder.append(String.format("<div id='%s' class='nw-blog-post'>%n", idPrefix));
    htmlBuilder.append(String.format("<h3>%s</h3>%n", properties.getProperty(PROPERTY_TITLE)));

    htmlBuilder.append("<div class='nw-blog-post-meta'>");
    renderDate(htmlBuilder, blogDateTime);
    renderCategory(htmlBuilder, post);
    renderTags(htmlBuilder, post);
    renderPermalink(htmlBuilder, post);
    htmlBuilder.append("</div>");

    if (addBody) {
        htmlBuilder.append(String.format("<div class='nw-blog-post-content'>%s</div>%n",
                properties.getProperty(PROPERTY_FULL_TEXT)));

        try {
            requestContext.setDynamicNodeProperty(PROP_ADD_ID, properties.getProperty(PROPERTY_ID));
        } catch (NotFoundException | IOException e) {
            log.debug("Can't set dynamic property " + PROP_ADD_ID, e); // ok, no id
        }

        requestContext.setDynamicNodeProperty(PROP_ADD_TITLE, computeTitle(post));
    }

    htmlBuilder.append(String.format("</div>%n"));
    htmlParts.add(htmlBuilder.toString());
}

From source file:org.apache.james.jmap.methods.integration.cucumber.GetMessagesMethodStepdefs.java

private void appendMessage(String emlFileName) throws Exception {
    ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
    mainStepdefs.jmapServer.serverProbe().appendMessage(userStepdefs.lastConnectedUser,
            new MailboxPath(MailboxConstants.USER_NAMESPACE, userStepdefs.lastConnectedUser, "inbox"),
            ClassLoader.getSystemResourceAsStream(emlFileName), Date.from(dateTime.toInstant()), false,
            new Flags());
}

From source file:co.com.soinsoftware.hotelero.view.JFRoomPayment.java

private Date getFinalDate(final Date initialDate, final int hour) {
    final LocalDate today = LocalDate.now();
    LocalDateTime finalDateTime = null;
    if (DateUtils.isSameDay(initialDate, new Date())) {
        finalDateTime = today.plusDays(1).atTime(LocalTime.of(hour, 0));
    } else {//from  w w w. ja v  a  2  s .c  o m
        finalDateTime = today.atTime(LocalTime.of(hour, 0));
    }
    final ZonedDateTime zdt = finalDateTime.atZone(ZoneId.systemDefault());
    return Date.from(zdt.toInstant());
}