本文整理汇总了Java中java.time.Instant.plusSeconds方法的典型用法代码示例。如果您正苦于以下问题:Java Instant.plusSeconds方法的具体用法?Java Instant.plusSeconds怎么用?Java Instant.plusSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.Instant
的用法示例。
在下文中一共展示了Instant.plusSeconds方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: maxInstant
import java.time.Instant; //导入方法依赖的package包/类
@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);
}
示例2: startGiveaway
import java.time.Instant; //导入方法依赖的package包/类
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;
}
示例3: testPatchWriter
import java.time.Instant; //导入方法依赖的package包/类
@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));
}
示例4: plusSeconds_long
import java.time.Instant; //导入方法依赖的package包/类
@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);
}
示例5: generateToken
import java.time.Instant; //导入方法依赖的package包/类
/**
* 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();
}
示例6: plusSeconds_long_overflowTooBig
import java.time.Instant; //导入方法依赖的package包/类
@Test(expectedExceptions=ArithmeticException.class)
public void plusSeconds_long_overflowTooBig() {
Instant t = Instant.ofEpochSecond(1, 0);
t.plusSeconds(Long.MAX_VALUE);
}
示例7: plusSeconds_long_overflowTooSmall
import java.time.Instant; //导入方法依赖的package包/类
@Test(expectedExceptions=ArithmeticException.class)
public void plusSeconds_long_overflowTooSmall() {
Instant t = Instant.ofEpochSecond(-1, 0);
t.plusSeconds(Long.MIN_VALUE);
}