Example usage for java.time LocalDate now

List of usage examples for java.time LocalDate now

Introduction

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

Prototype

public static LocalDate now() 

Source Link

Document

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

Usage

From source file:org.bedework.synch.cnctrs.file.FileConnectorInstance.java

@Override
public URI getUri() throws SynchException {
    try {//from   w ww.  java 2  s  . c om
        //Get yesterdays date
        final LocalDate yesterday = LocalDate.now().minus(1, ChronoUnit.DAYS);
        final String yesterdayStr = yesterday.format(DateTimeFormatter.ISO_LOCAL_DATE);

        final URI infoUri = new URI(info.getUri());
        return new URIBuilder().setScheme(infoUri.getScheme()).setHost(infoUri.getHost())
                .setPort(infoUri.getPort()).setPath(infoUri.getPath()).build();
    } catch (final SynchException se) {
        throw se;
    } catch (final Throwable t) {
        throw new SynchException(t);
    }
}

From source file:de.rahn.finances.domains.repositories.SecuritiesRepositoryTest.java

@Test
public void findAll() throws Exception {
    Security security = new Security();
    security.setName("Name");
    security.setWkn("123456");
    security.setSymbol("654321");
    security.setIsin("DE0012345600");
    security.setType(stock);/*from  www  .  j a va 2 s  .c  om*/
    security.setInventory(true);

    Entry entry = new Entry();
    entry.setAmount(new BigDecimal("152.415568", MC));
    entry.setDate(LocalDate.now());
    entry.setNumberOf(new BigDecimal("123.4567", MC));
    entry.setPrice(new BigDecimal("1.234567", MC));
    entry.setType(buy);

    security.addEntry(entry);

    security = entityManager.persist(security);
    entityManager.flush();

    security = repository.findOne(security.getId());

    assertThat(security).isNotNull();
    assertThat(security.getId()).isNotEmpty();
    assertThat(security.getName()).isEqualTo("Name");
    assertThat(security.getWkn()).isEqualTo("123456");
    assertThat(security.getSymbol()).isEqualTo("654321");
    assertThat(security.getIsin()).isEqualTo("DE0012345600");
    assertThat(security.getType()).isEqualTo(stock);
    assertThat(security.isInventory()).isTrue();
    assertThat(security.getEntries()).isNotEmpty();
    assertThat(security.getEntries()).hasSize(1);
    assertThat(security.getEntries().get(0)).isNotNull();
    assertThat(security.getEntries().get(0).getId()).isNotEmpty();
    assertThat(security.getEntries().get(0).getType()).isEqualTo(buy);

}

From source file:curly.artifactory.ArtifactoryTestHelper.java

public static Artifact createArtifact(MongoTemplate mongoTemplate) {
    mongoTemplate.findAllAndRemove(new Query(), Artifact.class);
    Artifact artifact = new Artifact();
    Set<Language> languages = new HashSet<>(0);
    Set<Tag> tags = new HashSet<>(0);
    tags.add(new Tag("document"));
    tags.add(new Tag("nosql"));
    languages.add(new Language("java"));
    languages.add(new Language("groovy"));
    languages.add(new Language("ruby"));
    languages.add(new Language("scala"));
    languages.add(new Language("javascript"));
    artifact.setName("curly");
    artifact.setDescription("a hobby project");
    artifact.setAuthor("joaoevangelista");
    artifact.setCategory(new Category("database"));
    artifact.setHomePage("http://example.com");
    artifact.setIncubation(LocalDate.now().toString());
    artifact.setLanguages(languages);//  w  w  w . j  a v a 2 s  .  com
    artifact.setTags(tags);
    artifact.setOwner("6969");
    mongoTemplate.insert(artifact);
    Assert.assertTrue(artifact.getId() != null);
    try {
        System.out.println(new ObjectMapper().writeValueAsString(artifact));
    } catch (JsonProcessingException e) {
        e.printStackTrace();
    }
    return artifact;
}

From source file:de.lgblaumeiser.ptm.rest.AnalysisControllerTest.java

@Test
public void test() throws Exception {
    ActivityRestController.ActivityBody data = new ActivityRestController.ActivityBody();
    data.activityName = "MyTestActivity";
    data.bookingNumber = "0815";
    mockMvc.perform(/*from   w  w  w . j ava2 s.co  m*/
            post("/activities").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(data)))
            .andDo(print()).andExpect(status().isCreated());

    LocalDate date = LocalDate.now();
    String dateString = date.format(ISO_LOCAL_DATE);
    BookingRestController.BookingBody booking = new BookingRestController.BookingBody();
    booking.activityId = "1";
    booking.user = "TestUser";
    booking.starttime = LocalTime.of(8, 15).format(ISO_LOCAL_TIME);
    booking.endtime = LocalTime.of(16, 45).format(ISO_LOCAL_TIME);
    booking.comment = "";
    mockMvc.perform(post("/bookings/" + dateString).contentType(APPLICATION_JSON)
            .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isCreated());

    mockMvc.perform(get("/analysis/hours/" + dateString.substring(0, 7))).andDo(print())
            .andExpect(status().isOk()).andExpect(content().string(containsString(dateString)))
            .andExpect(content().string(containsString("08:15")))
            .andExpect(content().string(containsString("16:45")))
            .andExpect(content().string(containsString("08:30")))
            .andExpect(content().string(containsString("00:00")));

    mockMvc.perform(get("/analysis/projects/" + dateString.substring(0, 7))).andDo(print())
            .andExpect(status().isOk()).andExpect(content().string(containsString("0815")))
            .andExpect(content().string(containsString("08,50")))
            .andExpect(content().string(containsString("100")))
            .andExpect(content().string(containsString("8")));

}

From source file:pl.java.scalatech.domain.User.java

public static Function<User, Integer> daysSinceBirth() {
    return x -> between(x.getBirthDate(), LocalDate.now()).getDays();
}

From source file:com.github.drbookings.LocalDates.java

public static boolean isCurrentMonth(final LocalDate date) {
    final Month month = LocalDate.now().getMonth();
    return date.getMonth().equals(month) && date.getYear() == LocalDate.now().getYear();
}

From source file:ch.algotrader.dao.trade.OrderDaoImpl.java

@Override
public List<Order> getDailyOrdersByStrategy(String strategyName) {

    Validate.notEmpty(strategyName, "Strategy name is empty");

    LocalDate today = LocalDate.now();
    return find("Order.findDailyOrdersByStrategy", QueryType.BY_NAME,
            new NamedParam("curdate", DateTimeLegacy.toLocalDate(today)),
            new NamedParam("strategyName", strategyName));
}

From source file:retsys.client.controller.StandardController.java

public void setAuditValues() {
    if (id != null && id.getText().isEmpty()) {
        auditId.setText("");
        createdBy.setText("");
        createdOn.setValue(null);/*from w w  w . j  a va 2  s. co m*/
        modifiedBy.setText("");
        modifiedOn.setValue(null);
    }
    if (!createdBy.getText().isEmpty()) { //modification
        modifiedBy.setText(AppContext.getInstance().getUsername());
        modifiedOn.setValue(LocalDate.now());
    } else { //new record
        createdBy.setText(AppContext.getInstance().getUsername());
        createdOn.setValue(LocalDate.now());
    }

}

From source file:rapture.dp.invocable.calendar.steps.CalendarLookupStep.java

@Override
public String invoke(CallingContext ctx) {
    DecisionApi decision = Kernel.getDecision();
    try {/* w  w  w.  j  a v a 2s.  c o m*/
        decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());

        String dateStr = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "DATE"));
        String calendar = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "CALENDAR"));
        String translator = StringUtils
                .stripToNull(decision.getContextValue(ctx, getWorkerURI(), "TRANSLATOR"));
        if (translator == null)
            translator = StringUtils
                    .stripToNull(decision.getContextValue(ctx, getWorkerURI(), "DEFAULT_TRANSLATOR"));
        LocalDate date = (dateStr == null) ? LocalDate.now() : LocalDate.parse(dateStr);

        // Translate the date to a name - eg Good Friday, Yom Kippur, Thanksgiving
        // Expected format is a map of dates (with or without years) to names or lists of names
        // Example:
        // {
        // "31Dec" : ["New Tear's Eve", "Hogmanay"] ,
        // "05Sep2016" : "Labor Day",
        // "04Sep2017" : "Labor Day"
        // "2015-01-01" : "New Year's Day"
        // }

        Map<String, Object> calendarTable = new HashMap<>();
        if (calendar != null) {
            String calendarJson = StringUtils.stripToNull(Kernel.getDoc().getDoc(ctx, calendar));
            if (calendarJson != null) {
                calendarTable = JacksonUtil.getMapFromJson(calendarJson);
            }
        }

        // Translate the date to a name - eg Good Friday, Yom Kippur, Thanksgiving
        Map<String, Object> translationTable = new HashMap<>();
        if (translator != null) {
            String translationJson = StringUtils.stripToNull(Kernel.getDoc().getDoc(ctx, translator));
            if (translationJson != null) {
                translationTable = JacksonUtil.getMapFromJson(translationJson);
            }
        }

        List<String> lookup = new ArrayList<>();

        String languageTag = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "LOCALE"));
        Locale locale = (languageTag == null) ? Locale.getDefault() : Locale.forLanguageTag(languageTag);

        for (DateTimeFormatter formatter : ImmutableList.of(DateTimeFormatter.ISO_LOCAL_DATE,
                DateTimeFormatter.ofPattern("ddMMMuuuu", locale), DateTimeFormatter.ofPattern("ddMMM", locale),
                DateTimeFormatter.ofPattern("MMMdduuuu", locale), DateTimeFormatter.ofPattern("MMMdd", locale),
                DateTimeFormatter.ofPattern("uuuuMMMdd", locale))) {

            String formattedDate = date.format(formatter);
            Object transList = translationTable.get(formattedDate);
            if (transList != null) {
                if (transList instanceof Iterable) {
                    for (Object o : (Iterable) transList) {
                        lookup.add(o.toString());
                    }
                } else
                    lookup.add(transList.toString());
            }
            lookup.add(formattedDate);
        }
        lookup.add(DayOfWeek.from(date).getDisplayName(TextStyle.FULL, locale));

        decision.setContextLiteral(ctx, getWorkerURI(), "DATE_TRANSLATIONS",
                JacksonUtil.jsonFromObject(lookup));

        // Calendar table defines the priority. getMapFromJson returns a LinkedHashMap so order is preserved.
        for (Entry<String, Object> calEntry : calendarTable.entrySet()) {
            if (lookup.contains(calEntry.getKey())) {
                decision.setContextLiteral(ctx, getWorkerURI(), "CALENDAR_LOOKUP_ENTRY",
                        JacksonUtil.jsonFromObject(calEntry));
                decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                        calEntry.getKey() + " matched as " + calEntry.getValue().toString(), false);
                return calEntry.getValue().toString();
            }
        }
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), getStepName() + ": No matches for "
                + DateTimeFormatter.ISO_LOCAL_DATE.format(date) + " found in calendar", false);
        return getNextTransition();
    } catch (Exception e) {
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                "Unable to access the calendar : " + e.getLocalizedMessage());
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName() + "Error", ExceptionToString.summary(e));
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                "Problem in " + getStepName() + ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
                true);
        return getErrorTransition();
    }
}

From source file:com.yqboots.initializer.core.ProjectInitializerImpl.java

@Override
public Path startup(final ProjectMetadata metadata, final Theme theme, final InputStream file)
        throws IOException {
    Path targetPath = Paths.get(properties.getTargetPath() + File.separator + LocalDate.now() + File.separator
            + metadata.getName());/*from w ww  . j  a v a 2 s  .c  om*/
    if (!Files.exists(targetPath)) {
        LOG.info("Creating the target path: {}", targetPath);
        Files.createDirectories(targetPath);
    }

    final VelocityContext velocityContext = new VelocityContext();
    velocityContext.put("metadata", metadata);
    velocityContext.put("theme", theme);
    velocityContext.put("StringUtils", StringUtils.class);

    for (FileBuilder builder : getFileBuilders()) {
        if (builder instanceof TemplateBuilder) {
            TemplateBuilder _builder = (TemplateBuilder) builder;
            if (!getVelocityEngine().resourceExists(_builder.getTemplate())) {
                LOG.warn("Template {} not found, ignore...", _builder.getTemplate());
                continue;
            }

            Template template = getVelocityEngine().getTemplate(_builder.getTemplate());
            try (Writer writer = new FileWriter(builder.getFile(targetPath, metadata).toFile())) {
                // retrieve the root path of the target project
                template.merge(velocityContext, writer);
                writer.flush();
            }
        }

        if (file != null && builder instanceof ProjectFileBuilder) {
            ProjectFileBuilder _builder = (ProjectFileBuilder) builder;
            // call getFile to generate files
            _builder.getFiles(targetPath, metadata, file);
        }
    }

    // compress to one file for downloading
    return ZipUtils.compress(targetPath);
}