Java Code Examples for java.time.Instant.plusSeconds()

The following are Jave code examples for showing how to use plusSeconds() of the java.time.Instant class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: kafka-connect-github-source   File: DateUtilsTest.java   Source Code and License Vote up 5 votes
@Test
public void maxInstant() {
    Instant i1 = ZonedDateTime.now().toInstant();
    Instant i2 = i1.plusSeconds(1);
    assertEquals(DateUtils.MaxInstant(i1, i2), i2);
    assertEquals(DateUtils.MaxInstant(i2, i1), i2);
}
 
Example 2
Project: GiveawayBot   File: Bot.java   Source Code and License Vote up 5 votes
public boolean startGiveaway(TextChannel channel, Instant now, int seconds, int winners, String prize)
{
    if(!Constants.canSendGiveaway(channel))
        return false;
    database.settings.updateColor(channel.getGuild());
    Instant end = now.plusSeconds(seconds);
    Message msg = new Giveaway(0, channel.getIdLong(), channel.getGuild().getIdLong(), end, winners, prize).render(channel.getGuild().getSelfMember().getColor(), now);
    channel.sendMessage(msg).queue(m -> {
        m.addReaction(Constants.TADA).queue();
        database.giveaways.createGiveaway(m, end, winners, prize);
    }, v -> LOG.warn("Unable to start giveaway: "+v));
    return true;
}
 
Example 3
Project: trellis-rosid-file   File: RDFPatchTest.java   Source Code and License Vote up 5 votes
@Test
public void testPatchWriter() throws IOException {
    final File file = new File(resDir1, RESOURCE_JOURNAL);
    final Instant time = now();
    final List<Quad> delete = new ArrayList<>();
    final List<Quad> add = new ArrayList<>();
    final Quad title = rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title, rdf.createLiteral("Title"));
    add.add(title);
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.description,
                rdf.createLiteral("A longer description")));
    add.add(rdf.createQuad(Trellis.PreferServerManaged, identifier, type, LDP.RDFSource));
    RDFPatch.write(file, delete.stream(), add.stream(), time);
    final List<Quad> data1 = RDFPatch.asStream(rdf, file, identifier, time).collect(toList());
    assertEquals(add.size() + 1, data1.size());
    add.forEach(q -> assertTrue(data1.contains(q)));

    final Instant later = time.plusSeconds(10L);
    add.clear();
    delete.add(title);
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title, rdf.createLiteral("Other Title")));
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, RDFS.label, rdf.createLiteral("Label")));
    RDFPatch.write(file, delete.stream(), add.stream(), later);
    final List<Quad> data2 = RDFPatch.asStream(rdf, file, identifier, later).collect(toList());
    assertEquals(data2.size(), data1.size() - delete.size() + add.size());
    add.forEach(q -> assertTrue(data2.contains(q)));
    delete.forEach(q -> assertFalse(data2.contains(q)));
    assertFalse(data2.contains(title));

    RDFPatch.write(file, empty(), of(rdf.createQuad(LDP.PreferContainment, identifier, LDP.contains,
                rdf.createIRI("trellis:repository/resource/1"))), later.plusSeconds(10L));

    final List<VersionRange> versions = RDFPatch.asTimeMap(file);
    assertEquals(1L, versions.size());
    assertEquals(time.truncatedTo(MILLIS), versions.get(0).getFrom().truncatedTo(MILLIS));
    assertEquals(later.truncatedTo(MILLIS), versions.get(0).getUntil().truncatedTo(MILLIS));
}
 
Example 4
Project: jdk8u-jdk   File: TCKInstant.java   Source Code and License Vote up 5 votes
@Test(dataProvider="PlusSeconds")
public void plusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant t = Instant.ofEpochSecond(seconds, nanos);
    t = t.plusSeconds(amount);
    assertEquals(t.getEpochSecond(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 5
Project: trellis-rosid   File: RDFPatchTest.java   Source Code and License Vote up 5 votes
@Test
public void testPatchWriter() throws IOException {
    final File file = new File(resDir1, RESOURCE_JOURNAL);
    final Instant time = now();
    final List<Quad> delete = new ArrayList<>();
    final List<Quad> add = new ArrayList<>();
    final Quad title = rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title, rdf.createLiteral("Title"));
    add.add(title);
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.description,
                rdf.createLiteral("A longer description")));
    add.add(rdf.createQuad(Trellis.PreferServerManaged, identifier, type, LDP.RDFSource));
    RDFPatch.write(file, delete.stream(), add.stream(), time);
    final List<Quad> data1 = RDFPatch.asStream(rdf, file, identifier, time).collect(toList());
    assertEquals(add.size() + 1, data1.size());
    add.forEach(q -> assertTrue(data1.contains(q)));

    final Instant later = time.plusSeconds(10L);
    add.clear();
    delete.add(title);
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title, rdf.createLiteral("Other Title")));
    add.add(rdf.createQuad(Trellis.PreferUserManaged, identifier, RDFS.label, rdf.createLiteral("Label")));
    RDFPatch.write(file, delete.stream(), add.stream(), later);
    final List<Quad> data2 = RDFPatch.asStream(rdf, file, identifier, later).collect(toList());
    assertEquals(data2.size(), data1.size() - delete.size() + add.size());
    add.forEach(q -> assertTrue(data2.contains(q)));
    delete.forEach(q -> assertFalse(data2.contains(q)));
    assertFalse(data2.contains(title));

    RDFPatch.write(file, empty(), of(rdf.createQuad(LDP.PreferContainment, identifier, LDP.contains,
                rdf.createIRI("trellis:repository/resource/1"))), later.plusSeconds(10L));

    final List<VersionRange> versions = RDFPatch.asTimeMap(file);
    assertEquals(1L, versions.size());
    assertEquals(time.truncatedTo(MILLIS), versions.get(0).getFrom().truncatedTo(MILLIS));
    assertEquals(later.truncatedTo(MILLIS), versions.get(0).getUntil().truncatedTo(MILLIS));
}
 
Example 6
Project: openjdk-jdk10   File: TCKInstant.java   Source Code and License Vote up 5 votes
@Test(dataProvider="PlusSeconds")
public void plusSeconds_long(long seconds, int nanos, long amount, long expectedSeconds, int expectedNanoOfSecond) {
    Instant t = Instant.ofEpochSecond(seconds, nanos);
    t = t.plusSeconds(amount);
    assertEquals(t.getEpochSecond(), expectedSeconds);
    assertEquals(t.getNano(), expectedNanoOfSecond);
}
 
Example 7
Project: secrets-proxy   File: JwtTokenService.java   Source Code and License Vote up 5 votes
/**
 * Generate a JWT token for the given user. The roles will be
 * stored as a claim in JWT token as a comma separated string.
 *
 * @param user authenticated user details object.
 * @return compact JWS (JSON Web Signature)
 */
public @Nonnull
String generateToken(OneOpsUser user) {
    Instant now = Instant.now();
    Instant expiresIn = now.plusSeconds(expiresInSec);

    JwtBuilder jwt = Jwts.builder()
            .setSubject(user.getUsername())
            .setIssuer(issuer)
            .setIssuedAt(Date.from(now))
            .setExpiration(Date.from(expiresIn))
            .signWith(SIGNATURE_ALGORITHM, String.valueOf(secretKey));
    if (user.getAuthorities() != null) {
        List<String> roles = user.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
        jwt.claim(ROLE_CLAIM, String.join(",", roles));
    }
    if (user.getDomain() != null) {
        jwt.claim(DOMAIN_CLAIM, user.getDomain());
    }
    if (user.getCn() != null) {
        jwt.claim(CN_CLAIM, user.getCn());
    }
    if (compressionEnabled) {
        jwt.compressWith(CompressionCodecs.DEFLATE);
    }
    return jwt.compact();
}
 
Example 8
Project: jdk8u-jdk   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=ArithmeticException.class)
public void plusSeconds_long_overflowTooBig() {
    Instant t = Instant.ofEpochSecond(1, 0);
    t.plusSeconds(Long.MAX_VALUE);
}
 
Example 9
Project: jdk8u-jdk   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=ArithmeticException.class)
public void plusSeconds_long_overflowTooSmall() {
    Instant t = Instant.ofEpochSecond(-1, 0);
    t.plusSeconds(Long.MIN_VALUE);
}
 
Example 10
Project: openjdk-jdk10   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=ArithmeticException.class)
public void plusSeconds_long_overflowTooBig() {
    Instant t = Instant.ofEpochSecond(1, 0);
    t.plusSeconds(Long.MAX_VALUE);
}
 
Example 11
Project: openjdk-jdk10   File: TCKInstant.java   Source Code and License Vote up 4 votes
@Test(expectedExceptions=ArithmeticException.class)
public void plusSeconds_long_overflowTooSmall() {
    Instant t = Instant.ofEpochSecond(-1, 0);
    t.plusSeconds(Long.MIN_VALUE);
}