List of usage examples for java.time Instant minusSeconds
public Instant minusSeconds(long secondsToSubtract)
From source file:Main.java
public static void main(String[] args) { Instant instant = Instant.parse("2014-12-03T10:15:30.00Z"); instant = instant.minusSeconds(10000); System.out.println(instant);/*from w ww . ja v a 2 s. c om*/ }
From source file:edu.usu.sdl.openstorefront.service.message.SystemErrorAlertMessageGenerator.java
@Override protected String generateMessageInternal(Email email) { StringBuilder message = new StringBuilder(); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss z"); ErrorTicket errorTicketExample = new ErrorTicket(); errorTicketExample.setActiveStatus(ErrorTicket.ACTIVE_STATUS); //We need to back up a bit to capture the error that triggered the message. It's possible it will pick old ones if they'are are close. ErrorTicket errorTicketStartExample = new ErrorTicket(); Instant instant = Instant.ofEpochMilli(messageContext.getUserMessage().getCreateDts().getTime()); instant = instant.minusSeconds(1); errorTicketStartExample.setCreateDts(new Date(instant.toEpochMilli())); QueryByExample queryByExample = new QueryByExample(errorTicketExample); SpecialOperatorModel specialOperatorModel = new SpecialOperatorModel(); specialOperatorModel.getGenerateStatementOption() .setOperation(GenerateStatementOption.OPERATION_GREATER_THAN_EQUAL); specialOperatorModel.setExample(errorTicketStartExample); queryByExample.getExtraWhereCauses().add(specialOperatorModel); List<ErrorTicket> tickets = serviceProxy.getPersistenceService().queryByExample(ErrorTicket.class, queryByExample);/*from w ww.j a v a2 s .co m*/ if (!tickets.isEmpty()) { message.append("System errors have occured. ").append(tickets.size()).append(" error(s) since: ") .append(sdf.format(messageContext.getUserMessage().getCreateDts())).append("<hr>"); message.append("<ul>"); for (ErrorTicket ticket : tickets) { message.append(" <li> ") .append(TranslateUtil.translate(ErrorTypeCode.class, ticket.getErrorTypeCode())) .append(" - ").append(ticket.getMessage()).append(" - ").append(ticket.getErrorTicketId()) .append("</li><br>"); } message.append("</ul>"); message.append("See attached for details.<br>"); int max = tickets.size(); if (tickets.size() > MAX_TICKETS_TO_ATTACH) { message.append("(Only ").append(MAX_TICKETS_TO_ATTACH) .append(" are attached login to view more.<br>"); max = MAX_TICKETS_TO_ATTACH; } for (int i = 0; i < max; i++) { ErrorTicket ticket = tickets.get(i); String ticketData = serviceProxy.getSystemService().errorTicketInfo(ticket.getErrorTicketId()); if (StringUtils.isNotBlank(ticketData)) { email.addAttachment("error-" + ticket.getErrorTicketId() + ".txt", ticketData.getBytes(Charset.defaultCharset()), "text/plain"); } } } else { log.log(Level.WARNING, MessageFormat.format( "System Error Message was queue...however no error tickets found within window. " + " Likely, the error occur before message time window. " + "Use the System tool to find error. Message Time: {0}", sdf.format(messageContext.getUserMessage().getCreateDts()))); } return message.toString(); }
From source file:eu.fthevenet.binjr.sources.jrds.adapters.JrdsDataAdapter.java
private Graphdesc getGraphDescriptorLegacy(String id) throws DataAdapterException { Instant now = ZonedDateTime.now().toInstant(); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { try (InputStream in = fetchRawData(id, now.minusSeconds(300), now, false)) { List<String> headers = getDecoder().getDataColumnHeaders(in); Graphdesc desc = new Graphdesc(); desc.seriesDescList = new ArrayList<>(); for (String header : headers) { Graphdesc.SeriesDesc d = new Graphdesc.SeriesDesc(); d.name = header;// w ww. j a v a 2 s.co m desc.seriesDescList.add(d); } return desc; } } catch (IOException e) { throw new FetchingDataFromAdapterException(e); } }