Example usage for java.time YearMonth parse

List of usage examples for java.time YearMonth parse

Introduction

In this page you can find the example usage for java.time YearMonth parse.

Prototype

public static YearMonth parse(CharSequence text) 

Source Link

Document

Obtains an instance of YearMonth from a text string such as 2007-12 .

Usage

From source file:Main.java

public static void main(String[] args) {
    YearMonth y = YearMonth.parse("2013-09");

    System.out.println(y);

}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java

@Override
public Collection<Collection<Object>> analyze(final Collection<String> parameter) {
    YearMonth requestedMonth = YearMonth.now();
    if (parameter.size() > 0) {
        requestedMonth = YearMonth.parse(Iterables.get(parameter, 0));
    }/*from www  . ja v a 2  s . co  m*/
    Collection<Collection<Object>> result = Lists.newArrayList();
    result.add(Arrays.asList("Work Day", "Starttime", "Endtime", "Presence", "Worktime", "Breaktime",
            "Overtime", "Comment"));
    Duration overtime = Duration.ZERO;
    LocalDate currentday = requestedMonth.atDay(1);
    while (!currentday.isAfter(requestedMonth.atEndOfMonth())) {
        Collection<Booking> currentBookings = getBookingsForDay(currentday);
        if (hasCompleteBookings(currentBookings)) {
            String day = currentday.format(DateTimeFormatter.ISO_LOCAL_DATE);
            LocalTime starttime = Iterables.getFirst(currentBookings, null).getStarttime();
            LocalTime endtime = Iterables.getLast(currentBookings).getEndtime();
            Duration presence = calculatePresence(starttime, endtime);
            Duration worktime = calculateWorktime(currentBookings);
            Duration breaktime = calculateBreaktime(presence, worktime);
            Duration currentOvertime = calculateOvertime(worktime, currentday);
            overtime = overtime.plus(currentOvertime);
            result.add(Arrays.asList(day, starttime.format(DateTimeFormatter.ofPattern("HH:mm")),
                    endtime.format(DateTimeFormatter.ofPattern("HH:mm")), formatDuration(presence),
                    formatDuration(worktime), formatDuration(breaktime), formatDuration(overtime),
                    validate(worktime, breaktime)));
        }
        currentday = currentday.plusDays(1);
    }
    return result;
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.ProjectComputer.java

private Collection<Booking> getRelevantBookings(final Collection<String> dayOrMonthParameter) {
    if (dayOrMonthParameter.size() > 0) {
        String dayOrMonthString = Iterables.get(dayOrMonthParameter, 0);
        if (dayOrMonthString.length() == 10) {
            return getBookingsForDay(LocalDate.parse(dayOrMonthString));
        }//from   w  ww  .ja  va2s .co  m
        if (dayOrMonthString.length() == 7) {
            return getBookingsForMonth(YearMonth.parse(dayOrMonthString));
        }
    }
    return getBookingsForMonth(YearMonth.now());
}