Example usage for org.joda.time DateTime plusMinutes

List of usage examples for org.joda.time DateTime plusMinutes

Introduction

In this page you can find the example usage for org.joda.time DateTime plusMinutes.

Prototype

public DateTime plusMinutes(int minutes) 

Source Link

Document

Returns a copy of this datetime plus the specified number of minutes.

Usage

From source file:ru.caramel.juniperbot.core.moderation.service.MuteServiceImpl.java

License:Open Source License

private void storeState(ModerationActionRequest request) {
    MuteState state = new MuteState();
    state.setGlobal(request.isGlobal());
    state.setUserId(request.getViolator().getUser().getId());
    state.setGuildId(request.getViolator().getGuild().getIdLong());
    DateTime dateTime = DateTime.now();
    if (request.getDuration() != null) {
        dateTime = dateTime.plusMinutes(request.getDuration());
    } else {/*from w  w  w  .j  ava2 s . c  om*/
        dateTime = dateTime.plusYears(100);
    }
    state.setExpire(dateTime.toDate());
    state.setReason(request.getReason());
    if (request.getChannel() != null) {
        state.setChannelId(request.getChannel().getId());
    }
    muteStateRepository.save(state);
}

From source file:ru.caramel.juniperbot.module.reminder.commands.RemindCommand.java

License:Open Source License

@Override
public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String content) {
    try {/*from  w w w .  j  a  va2  s .c  o m*/
        DateTime date = null;
        String reminder = null;
        Matcher m = PATTERN.matcher(content);
        if (m.find()) {
            date = getFormatter(context).parseDateTime(String.format("%s %s", m.group(1), m.group(2)));
            reminder = m.group(3);
            if (DateTime.now().isAfter(date)) {
                messageService.onError(message.getChannel(), "discord.command.remind.error.future");
                return fail(message);
            }
        }

        String keyWord = messageService.getMessage("discord.command.remind.keyWord");
        m = Pattern.compile(String.format(RELATIVE_PATTERN_FORMAT, keyWord)).matcher(content);
        if (m.find()) {
            Long millis = SEQUENCE_PARSER.parse(m.group(1));
            reminder = m.group(2);
            if (millis != null && StringUtils.isNotEmpty(reminder)) {
                date = DateTime.now().plus(millis);
            }
        }

        if (date != null && reminder != null) {
            createReminder(message.getChannel(), message.getMember(), reminder, date.toDate());
            return ok(message, "discord.command.remind.done");
        }
    } catch (IllegalArgumentException e) {
        // fall down
    }

    String prefix = context.getConfig() != null ? context.getConfig().getPrefix()
            : configService.getDefaultPrefix();

    String remindCommand = messageService.getMessageByLocale("discord.command.remind.key",
            context.getCommandLocale());

    DateTime current = DateTime.now();
    current = current.plusMinutes(1);
    EmbedBuilder builder = messageService.getBaseEmbed();
    builder.setTitle(messageService.getMessage("discord.command.remind.help.title"));
    builder.addField(
            messageService.getMessage("discord.command.remind.help.field1.title",
                    CommonUtils.getUTCOffset(context.getTimeZone())),
            messageService.getMessage("discord.command.remind.help.field1.value", prefix, remindCommand,
                    getFormatter(context).print(current)),
            false);
    builder.addField(messageService.getMessage("discord.command.remind.help.field2.title"),
            messageService.getMessage("discord.command.remind.help.field2.value", prefix, remindCommand),
            false);
    messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build());
    return false;
}

From source file:securesocial.core.java.SecureSocial.java

License:Apache License

/**
 * Checks if the session has expired/*from ww  w . j  a v a2 s . c om*/
 *
 * @param lastAccess the last access date that came in the session
 * @return  true if the session has expired, false otherwise.
 */
private static boolean isSessionExpired(DateTime lastAccess) {
    return DateTime.now().isAfter(lastAccess.plusMinutes(SESSION_TIMEOUT));
}

From source file:sk.linhard.openair.displaymodel.OverviewDisplay.java

License:Open Source License

private void setLocationOverviewDateNotice(DateTime minday, OverviewData aData, DayProgram[] dayPrograms,
        int nextDayProgramNoticePeriod) {
    DateTime endOfPreviousDay = getEndOfPreviousDayMax(minday, dayPrograms);
    DateTime dateNoticeSwitchOff = endOfPreviousDay == null ? null
            : endOfPreviousDay.plusMinutes(nextDayProgramNoticePeriod);
    boolean dayNotStarted = aData.getTime().isBefore(minday);
    // if the day program hasn't started yet, we have to
    // display date notice, to let viewers know that program displayed
    // isn't for today
    boolean previousProgramJustEnded = (dateNoticeSwitchOff != null)
            && (dateNoticeSwitchOff.isAfter(aData.getTime()));
    // 60 minutes (nextDayProgramNoticePeriod) hasn't passed from the end of
    // last day's program, viewers need time to realise that the program
    // being displayed
    // is already for the next (declared) day

    if (dayNotStarted || previousProgramJustEnded) {
        aData.setDateNotice(minday);//  www. j  a  v a 2 s .c o  m
        if (previousProgramJustEnded) {
            if (dateNoticeSwitchOff.isBefore(minday)) {
                dateNoticeSwitchOff = minday;
            }
            if (aData.getNextDisplayChange().isAfter(dateNoticeSwitchOff)) {
                aData.setNextDisplayChange(dateNoticeSwitchOff);
            }
        }
    }
}

From source file:test.integ.be.fedict.performance.CAConfiguration.java

License:Open Source License

private void generateCrl() throws Exception {

    DateTime now = new DateTime();
    if (this.crlRefresh > 0) {
        crllGenerateNext = now.plusMinutes(this.crlRefresh);
    } else {/*w  ww.j a va 2 s . c  om*/
        crllGenerateNext = now.plusHours(3);
    }
    crlNextUpdate = now.plusDays(7);

    List<BigInteger> revokedSerialNumbers = new LinkedList<BigInteger>();
    for (long i = 0; i < this.crlRecords; i++) {
        revokedSerialNumbers.add(new BigInteger(Long.toString(i)));
    }

    X509CRL crl = TestUtils.generateCrl(crlNumber, this.keyPair.getPrivate(), certificate, now, crlNextUpdate,
            revokedSerialNumbers);

    this.crlFile = File.createTempFile("crl_" + name + "_", ".crl");
    this.crlFile.deleteOnExit();

    FileOutputStream fos = new FileOutputStream(this.crlFile);
    fos.write(crl.getEncoded());
    fos.close();
}

From source file:test.unit.be.e_contract.dssp.client.SignResponseFactory.java

License:Open Source License

public static String createSignResponse(String responseId, String destination, String inResponseTo,
        String tokenId, byte[] tokenKey, String resultMajor, String resultMinor, String signerIdentity) {
    ObjectFactory dssObjectFactory = new ObjectFactory();
    be.e_contract.dssp.ws.jaxb.dss.async.ObjectFactory asyncObjectFactory = new be.e_contract.dssp.ws.jaxb.dss.async.ObjectFactory();
    be.e_contract.dssp.ws.jaxb.wsa.ObjectFactory wsaObjectFactory = new be.e_contract.dssp.ws.jaxb.wsa.ObjectFactory();
    be.e_contract.dssp.ws.jaxb.wsu.ObjectFactory wsuObjectFactory = new be.e_contract.dssp.ws.jaxb.wsu.ObjectFactory();
    be.e_contract.dssp.ws.jaxb.saml.protocol.ObjectFactory samlObjectFactory = new be.e_contract.dssp.ws.jaxb.saml.protocol.ObjectFactory();

    SignResponse signResponse = dssObjectFactory.createSignResponse();
    signResponse.setProfile(DigitalSignatureServiceConstants.PROFILE);
    Result result = dssObjectFactory.createResult();
    signResponse.setResult(result);/*  w  w  w.j a v a2 s.  co  m*/
    result.setResultMajor(resultMajor);
    if (null != resultMinor) {
        result.setResultMinor(resultMinor);
    }

    AnyType optionalOutputs = dssObjectFactory.createAnyType();
    signResponse.setOptionalOutputs(optionalOutputs);

    optionalOutputs.getAny().add(asyncObjectFactory.createResponseID(responseId));

    RelatesToType relatesTo = wsaObjectFactory.createRelatesToType();
    optionalOutputs.getAny().add(wsaObjectFactory.createRelatesTo(relatesTo));
    relatesTo.setValue(inResponseTo);

    TimestampType timestamp = wsuObjectFactory.createTimestampType();
    optionalOutputs.getAny().add(wsuObjectFactory.createTimestamp(timestamp));
    AttributedDateTime created = wsuObjectFactory.createAttributedDateTime();
    timestamp.setCreated(created);
    DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime()
            .withChronology(ISOChronology.getInstanceUTC());
    DateTime createdDateTime = new DateTime();
    created.setValue(dateTimeFormatter.print(createdDateTime));
    AttributedDateTime expires = wsuObjectFactory.createAttributedDateTime();
    timestamp.setExpires(expires);
    DateTime expiresDateTime = createdDateTime.plusMinutes(5);
    expires.setValue(dateTimeFormatter.print(expiresDateTime));

    AttributedURIType to = wsaObjectFactory.createAttributedURIType();
    optionalOutputs.getAny().add(wsaObjectFactory.createTo(to));
    to.setValue(destination);

    if (null != signerIdentity) {
        NameIdentifierType nameIdentifier = samlObjectFactory.createNameIdentifierType();
        nameIdentifier.setValue(signerIdentity);
        nameIdentifier.setFormat("urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName");
        optionalOutputs.getAny().add(dssObjectFactory.createSignerIdentity(nameIdentifier));
    }

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder;
    try {
        documentBuilder = documentBuilderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException("DOM error: " + e.getMessage(), e);
    }
    Document document = documentBuilder.newDocument();

    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class,
                be.e_contract.dssp.ws.jaxb.wsa.ObjectFactory.class,
                be.e_contract.dssp.ws.jaxb.wsu.ObjectFactory.class);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.marshal(signResponse, document);
    } catch (JAXBException ex) {
        throw new RuntimeException(ex);
    }
    try {
        sign(document, tokenId, tokenKey);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }

    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer;
    try {
        transformer = transformerFactory.newTransformer();
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("JAXP config error: " + e.getMessage(), e);
    }
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        transformer.transform(new DOMSource(document), new StreamResult(byteArrayOutputStream));
    } catch (TransformerException e) {
        throw new RuntimeException("JAXP error: " + e.getMessage(), e);
    }

    return Base64.encode(byteArrayOutputStream.toByteArray());
}

From source file:uk.ac.ebi.intact.editor.controller.curate.complex.ComplexController.java

License:Apache License

private boolean isButtonRendered(LifeCycleEventType eventType) {
    LifeCycleEvent event = ReleasableUtils.getLastEventOfType(complex, eventType);

    if (event == null) {
        return false;
    }/*w w w.  j a v a2s  .c om*/

    DateTime eventTime = new DateTime(event.getWhen());

    return new DateTime().isBefore(eventTime.plusMinutes(getEditorConfig().getRevertDecisionTime()));
}

From source file:uk.ac.ebi.intact.editor.controller.curate.publication.PublicationController.java

License:Apache License

private boolean isButtonRendered(LifeCycleEventType eventType) {
    LifeCycleEvent event = ReleasableUtils.getLastEventOfType(publication, eventType);

    if (event == null) {
        return false;
    }/* w ww . j  ava  2 s  .c  o  m*/

    DateTime eventTime = new DateTime(event.getWhen());

    return new DateTime().isBefore(eventTime.plusMinutes(getEditorConfig().getRevertDecisionTime()));
}