Example usage for java.time LocalDate toString

List of usage examples for java.time LocalDate toString

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Outputs this date as a String , such as 2007-12-03 .

Usage

From source file:org.flockdata.transform.ExpressionHelper.java

public static Long parseDate(ColumnDefinition colDef, String value) {
    if (value == null || value.equals(""))
        return null;
    if (colDef.isDateEpoc()) {
        return Long.parseLong(value) * 1000;
    }//from w w w .j  a va  2 s  .  c o m

    if (colDef.getDateFormat() == null || colDef.getDateFormat().equalsIgnoreCase("automatic")) {
        try {
            return Date.parse(value);
        } catch (IllegalArgumentException e) {
            // Try other formats
        }
    }
    if (colDef.getDateFormat() != null && colDef.getDateFormat().equalsIgnoreCase("timestamp")) {
        try {
            return Timestamp.valueOf(value).getTime();
        } catch (IllegalArgumentException e) {
            // attempt other conversions
        }
    }

    if (NumberUtils.isDigits(value)) // plain old java millis
        return Long.parseLong(value);

    // Custom Date formats
    String tz = colDef.getTimeZone();
    if (tz == null)
        tz = TimeZone.getDefault().getID();

    try {

        // Try first as DateTime
        return new SimpleDateFormat(colDef.getDateFormat()).parse(value).getTime();
    } catch (DateTimeParseException | IllegalArgumentException | ParseException e) {
        // Just a plain date
        DateTimeFormatter pattern = DateTimeFormatter.ofPattern(colDef.getDateFormat(), Locale.ENGLISH);
        LocalDate date = LocalDate.parse(value, pattern);
        return new DateTime(date.toString(), DateTimeZone.forID(tz)).getMillis();
    }
}

From source file:com.epam.ta.reportportal.core.project.impl.ProjectInfoWidgetDataConverter.java

private static String formattedDate(ProjectInfoGroup criteria, LocalDate localDate) {
    return criteria == BY_DAY ? localDate.toString() : formatter.format(localDate);
}

From source file:com.github.drbookings.ui.controller.UpcomingController.java

private static String getDateString(final LocalDate date) {
    if (LocalDate.now().equals(date)) {
        return "Today (" + date.toString() + ")";
    } else if (LocalDate.now().plusDays(1).equals(date)) {
        return "Tomorrow (" + date.toString() + ")";
    } else if (LocalDate.now().plusDays(2).equals(date) || LocalDate.now().plusDays(3).equals(date)
            || LocalDate.now().plusDays(4).equals(date)) {
        return "on " + date.getDayOfWeek().toString().charAt(0)
                + date.getDayOfWeek().toString().substring(1).toLowerCase() + " (" + date.toString() + ")";
    } else {//from w w w .j  a v a2  s . c  o  m
        return "on " + date;
    }
}

From source file:net.resheim.eclipse.timekeeper.ui.Activator.java

/**
 * Returns the number of seconds the task has been active on the given date.
 * If the task has not been active on the date, 0 will be returned.
 *
 * @param task/*from   w ww . ja  v a2 s. co m*/
 *            the task to get active time for
 * @param date
 *            the date to get active time for
 * @return duration in seconds
 */
public static int getActiveTime(ITask task, LocalDate date) {
    String value = getValue(task, date.toString());
    if (value != null) {
        return Integer.parseInt(value);
    }
    return 0;
}

From source file:fi.csc.emrex.smp.model.VerificationReply.java

public static VerificationReply verify(Person firstPerson, Person otherPerson, double threshold) {
    VerificationReply r = new VerificationReply();
    if (firstPerson == null || otherPerson == null) {
        r.setNameVerified(false);//from ww  w.j  a v  a 2 s  .co m
        r.setbDayVerified(false);
        r.addMessage("Person missing");
        return r;
    }
    r.setFullNameFromHomeInstitute(firstPerson.getFullName());
    r.setFullNameInElmo(otherPerson.getFullName());
    r.setHomeInstitute(firstPerson.getHomeOrganizationName());
    boolean bdMatch = false;
    boolean nameMatch = false;
    int match = 0;
    LocalDate vbd = firstPerson.getBirthDate();
    LocalDate ebd = otherPerson.getBirthDate();

    String message = "";
    if (ebd == null || vbd == null) {
        message = "Birthdate not set for " + (ebd == null ? "elmo" : "local") + " person.";
        r.addMessage(message);
        log.info(message);
    } else if (!ebd.equals(vbd)) {
        message = "Birthdate does not match.";
        r.addMessage(message);
        log.info(message);
        log.info("haka bday " + vbd.toString() + "elmo bday:" + ebd.toString());

    } else {
        bdMatch = true;
    }
    double score = 0;
    score += levenshteinDistance(firstPerson.getLastName(), otherPerson.getLastName());
    score += levenshteinDistance(firstPerson.getFirstName(), otherPerson.getFirstName());
    double length = 0;
    String fullname = firstPerson.getFullName();
    if (fullname != null) {
        length = fullname.length();
    } else {
        length = 1;
    }
    double ratio = score / length;
    r.addMessage("Error ratio " + ratio + " based on Levenshtein check on name.");
    if (ratio > threshold) {
        r.addMessage("Ratio over threshold " + threshold);
    } else {
        nameMatch = true;
    }

    r.setNameVerified(nameMatch);
    r.setbDayVerified(bdMatch);

    return r;
}

From source file:de.lgblaumeiser.ptm.cli.engine.handler.OpenDayTest.java

@Test
public void testOpenDayOneParamFresh() {
    LocalDate testDate = DATE1.minusWeeks(1);
    testee.handleCommand(asList(testDate.toString()));
    assertEquals(testDate, services.getStateStore().getCurrentDay());
}

From source file:ch.rasc.edsutil.jackson.ISO8601LocalDateSerializer.java

@Override
public void serialize(LocalDate value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    jgen.writeString(value.toString());
}

From source file:OrderDAOEmptyTests.java

@Before
public void setup() {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    orderTest = (OrderDAO) ctx.getBean("orderTest");
    LocalDate currentDate = LocalDate.now();
    currentDateString = currentDate.toString();
}

From source file:com.inversoft.json.LocalDateSerializer.java

@Override
public void serialize(LocalDate value, JsonGenerator jgen, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    jgen.writeObject(value.toString());
}

From source file:OrderItemDAOTests.java

@Before
public void setup() {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    orderItemTest = (OrderItemDAO) ctx.getBean("orderItemTest");
    LocalDate currentDate = LocalDate.now();
    currentDateString = currentDate.toString();
}