Example usage for java.time LocalDateTime now

List of usage examples for java.time LocalDateTime now

Introduction

In this page you can find the example usage for java.time LocalDateTime now.

Prototype

public static LocalDateTime now() 

Source Link

Document

Obtains the current date-time from the system clock in the default time-zone.

Usage

From source file:ch.wisv.areafiftylan.web.service.TournamentServiceImpl.java

private Collection<Tournament> getDummyTournaments() {
    Collection<Tournament> tournaments = new ArrayList<>();
    tournaments.add(new Tournament("CS:GO", "5v5", "Counter Strike: Global Offensive",
            "Counter-Strike: Global Offensive (CS:GO) is a tactical first-person shooter developed by "
                    + "Valve Corporation and Hidden Path Entertainment. It is the fourth game in the main "
                    + "Counter-Strike franchise. Like the previous games in the series, Global Offensive is"
                    + " an objective-based multiplayer first-person shooter. Each player joins either the "
                    + "Terrorist or Counter-Terrorist team and attempts to complete objectives or eliminate"
                    + " the enemy team. The game operates in short rounds that end when all players on one "
                    + "side are dead or a team's objective is completed",
            "/images/background/tournaments/lol.jpg", new Sponsor("Logitech", "path/to/image", "logitech.com"),
            new LinkedList<>(Arrays.asList("Mooie koptelegoof", "Mooie koptelegoof", "Mooie koptelegoof")),
            Format.FIVE_VS_FIVE, LocalDateTime.now(), "link/to/rules", Platform.MAC, Platform.PC));

    tournaments.add(new Tournament("CS:GO", "5v5", "Counter Strike: Global Offensive",
            "Counter-Strike: Global Offensive (CS:GO) is a tactical first-person shooter developed by "
                    + "Valve Corporation and Hidden Path Entertainment. It is the fourth game in the main "
                    + "Counter-Strike franchise. Like the previous games in the series, Global Offensive is"
                    + " an objective-based multiplayer first-person shooter. Each player joins either the "
                    + "Terrorist or Counter-Terrorist team and attempts to complete objectives or eliminate"
                    + " the enemy team. The game operates in short rounds that end when all players on one "
                    + "side are dead or a team's objective is completed",
            "/images/background/tournaments/lol.jpg", new Sponsor("Logitech", "path/to/image", "logitech.com"),
            new LinkedList<>(Arrays.asList("Mooie koptelegoof", "Mooie koptelegoof", "Mooie koptelegoof")),
            Format.FIVE_VS_FIVE, LocalDateTime.now(), "link/to/rules", Platform.OFFLINE));
    return tournaments;
}

From source file:org.jspare.server.transaction.TidGeneratorImpl.java

@Override
public boolean validate(final String tid) {

    try {/*from   w w w . j a va 2  s.c o m*/
        if (StringUtils.isEmpty(tid)) {
            return false;
        }

        String prefix = tid.substring(0, TIMESTAMP_FORMAT.length() + MILLI_OF_SECOND);
        if (!LocalDateTime.parse(prefix, dtf).isBefore(LocalDateTime.now())) {
            return false;
        }

        long sufix = Long
                .parseLong(tid.substring(TIMESTAMP_FORMAT.length() + MILLI_OF_SECOND, tid.length() - 1));
        if (sufix <= MIN || sufix >= MAX) {
            return false;
        }
        int verifyDigit = Integer.parseInt(String.valueOf(tid.charAt(tid.length() - 1)));

        return validateVerifyDigit(tid, verifyDigit);

    } catch (Exception e) {

        return false;
    }
}

From source file:com.fns.grivet.service.EntityServiceTest.java

@Test
public void testCreateThenFindByType() throws IOException {
    registerType("TestType");
    Resource r = resolver.getResource("classpath:TestTypeData.json");
    String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
    JSONObject payload = new JSONObject(json);

    entityService.create("TestType", payload);

    String result = entityService.findByCreatedTime("TestType", LocalDateTime.now().minusSeconds(3),
            LocalDateTime.now(), null);
    JSONArray resultAsJsonArray = new JSONArray(result);
    JsonAssert.assertJsonEquals(payload.toString(), resultAsJsonArray.get(0).toString());
}

From source file:org.oesf.eque.services.impl.QueueDispatcherImpl.java

@Override
public Integer allocateNumber() throws NoFreePlaceAvailableException {

    Lock atomic = this.lock;

    try {//from   ww w  .  j a va2s.c  o  m
        atomic.lock();

        occupiedQueue.add(freeQueue.element());
        Integer allocatedNumber = freeQueue.remove();
        LOG.debug("QDS-34C5F87A3F23: The on-demand allocated number is: \"{}\"", allocatedNumber);

        notifyStateChange(allocatedNumber, LocalDateTime.now(), FREE, OCCUPIED);
        return allocatedNumber;

    } catch (IllegalStateException ex) { // occupiedQueue.add()

        LOG.error("QDS-0EAE6367CEEE: Can not occupy a number.");
        throw new ChangeStateException();

    } catch (NoSuchElementException ex) { // freeQueue .element() | .remove()

        LOG.debug("QDS-3A2DFE3EE673: Allocating a new place number.");
        throw new NoFreePlaceAvailableException();

    } finally {
        atomic.unlock();
    }
}

From source file:com.serphacker.serposcope.db.google.GoogleRankDBIT.java

@Test
public void testInsertBatch() {

    Group grp = new Group(Group.Module.GOOGLE, "grp");
    baseDB.group.insert(grp);/*from  w  w  w.  j  a v a2  s .c  o  m*/

    GoogleSearch search1 = new GoogleSearch("search1");
    GoogleSearch search2 = new GoogleSearch("search2");
    googleDB.search.insert(Arrays.asList(search1, search2), grp.getId());

    GoogleTarget target = new GoogleTarget(grp.getId(), "name", GoogleTarget.PatternType.REGEX, "pattern");
    googleDB.target.insert(Arrays.asList(target));

    Run run = new Run(Run.Mode.CRON, Group.Module.GOOGLE, LocalDateTime.now().withNano(0));
    baseDB.run.insert(run);

    GoogleRank rank1 = new GoogleRank(run.getId(), grp.getId(), target.getId(), search1.getId(), 1, 2, "url-1");
    GoogleRank rank2 = new GoogleRank(run.getId(), grp.getId(), target.getId(), search2.getId(), 2, 3, "url-2");

    assertTrue(googleDB.rank.insert(Arrays.asList(rank1, rank2)));
    List<GoogleRank> ranks = googleDB.rank.list(run.getId(), grp.getId(), target.getId());
    assertEquals(2, ranks.size());
    assertEquals("url-1", ranks.get(0).url);
    assertEquals("url-2", ranks.get(1).url);

    rank1 = new GoogleRank(run.getId(), grp.getId(), target.getId(), search1.getId(), 10, 20, "url-xxx-1");
    rank2 = new GoogleRank(run.getId(), grp.getId(), target.getId(), search2.getId(), 20, 30, "url-xxx-2");

    assertTrue(googleDB.rank.insert(Arrays.asList(rank1, rank2)));
    ranks = googleDB.rank.list(run.getId(), grp.getId(), target.getId());
    assertEquals(2, ranks.size());
    assertEquals("url-xxx-1", ranks.get(0).url);
    assertEquals("url-xxx-2", ranks.get(1).url);

}

From source file:ch.wisv.areafiftylan.utils.TaskScheduler.java

@Scheduled(fixedRate = ORDER_EXPIRY_CHECK_INTERVAL_SECONDS * 1000)
public void ExpireOrders() {
    LocalDateTime expireBeforeDate = LocalDateTime.now().minusMinutes(ORDER_STAY_ALIVE_MINUTES);

    Collection<Order> allOrdersBeforeDate = orderRepository.findAllByCreationDateTimeBefore(expireBeforeDate);

    List<Order> expiredOrders = allOrdersBeforeDate.stream().filter(isExpired()).collect(Collectors.toList());

    expiredOrders.forEach(o -> orderService.expireOrder(o));
}

From source file:org.ow2.proactive.workflow_catalog.rest.service.BucketServiceTest.java

@Test
public void testCreateBucket() throws Exception {
    Bucket mockedBucket = newMockedBucket(1L, "BUCKET-NAME-TEST", LocalDateTime.now());
    when(bucketRepository.save(any(Bucket.class))).thenReturn(mockedBucket);
    BucketMetadata bucketMetadata = bucketService.createBucket("BUCKET-NAME-TEST", DEFAULT_BUCKET_NAME);
    verify(bucketRepository, times(1)).save(any(Bucket.class));
    assertEquals(mockedBucket.getName(), bucketMetadata.name);
    assertEquals(mockedBucket.getCreatedAt(), bucketMetadata.createdAt);
    assertEquals(mockedBucket.getId(), bucketMetadata.id);
    assertEquals(mockedBucket.getOwner(), bucketMetadata.owner);
}

From source file:com.mec.Services.JWTService.java

public void addAuthentication(HttpServletResponse res, String username) {
    //System.out.println("TokenAuthenticationService addAuth");
    try {// ww  w  .j  a  v  a2 s.  co m
        res.setHeader("Date", DateUtils.formatterTime.format(LocalDateTime.now()));
        Date expires = new Date(System.currentTimeMillis() + EXPIRATIONTIME);
        String token = JWT.create().withSubject(username).withIssuer("MEC").withExpiresAt(expires)
                .sign(algorithm);
        res.addHeader(HEADER_STRING, TOKEN_PREFIX + " " + token);
        res.addHeader("Content-Type", "application/json");
        res.setHeader("Expires", DateUtils.formatterTime.format(DateUtils.asLocalDateTime(expires)));
        try {
            JSONObject json = new JSONObject("{\"token\":\"" + token + "\",\"expires\":\""
                    + DateUtils.formatterTime.format(DateUtils.asLocalDateTime(expires)) + "\"}");
            json.write(res.getWriter());
        } catch (JSONException ex) {
            Logger.getLogger(JWTService.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(JWTService.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (JWTCreationException exception) {
        System.out.println("JWTCreationException " + exception.toString());
        try {
            JSONObject json = new JSONObject("{\"token\":\"" + exception.toString() + "\"}");
            json.write(res.getWriter());
        } catch (JSONException ex) {
            Logger.getLogger(JWTService.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(JWTService.class.getName()).log(Level.SEVERE, null, ex);
        } /*finally{
          throw new JWTCreationException(exception.toString(), exception.getCause());/*finally{
          throw new JWTCreationException(exception.toString(), exception.getCause());
          }*/
    }
}

From source file:org.ow2.proactive.workflow_catalog.rest.entity.Bucket.java

public Bucket(String name, String owner, Workflow... workflows) {
    this(name, LocalDateTime.now(), owner, workflows);
}

From source file:cz.muni.fi.editor.database.test.NotificationDAOTest.java

@Test
public void create() {
    Notification n = new Notification();
    n.setNotified(userDAO.getById(8L));/*from w w  w . ja  v a2s  . c  om*/
    n.setRequest(requestDAO.getById(8L));
    n.setNotificationDate(LocalDateTime.now());
    n.setMessage("demo");

    Assert.assertNull(n.getId());
    notificationDAO.create(n);
    Assert.assertNotNull(n.getId());
}