0% found this document useful (0 votes)
60 views

Exploring The Java - Time API: Maurice Naftalin

This document summarizes the java.time API, specifically focusing on the core classes like LocalDateTime, LocalDate, LocalTime and Duration. It discusses how to create instances of these classes, access fields, adjust values, compare values and convert between types. It provides examples using a WorkPeriod class to demonstrate operations on dates and times, including generating work periods from a start date.

Uploaded by

KIRAKRATOS
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Exploring The Java - Time API: Maurice Naftalin

This document summarizes the java.time API, specifically focusing on the core classes like LocalDateTime, LocalDate, LocalTime and Duration. It discusses how to create instances of these classes, access fields, adjust values, compare values and convert between types. It provides examples using a WorkPeriod class to demonstrate operations on dates and times, including generating work periods from a start date.

Uploaded by

KIRAKRATOS
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 204

Exploring the java.

time API

Maurice Naftalin
@mauricenaftalin
Summary
Summary
Core classes

Summary
Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary
Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary Core class methods
Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary Core class methods
• Creation, field access, adjustment,
comparison, conversion
Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary Core class methods
• Creation, field access, adjustment,
comparison, conversion

Illustrated in operations on WorkPeriod


Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary Core class methods
• Creation, field access, adjustment,
comparison, conversion

Illustrated in operations on WorkPeriod


• Creation and splitting
What is a WorkPeriod?
6:00
Tue May 22 Wed May 23 Thu May 24

9:00

12:00

15:00

18:00

21:00
What is a WorkPeriod?
6:00
Tue May 22 Wed May 23 Thu May 24

9:00

12:00

15:00

18:00

21:00
What is a WorkPeriod?

1 2
WorkPeriod LocalDateTime
What is a WorkPeriod?

1 2
WorkPeriod LocalDateTime

Duration wpDuration = Duration.between(wp.getStartTime(), wp.getEndTime());


http://www.threeten.org/threeten-extra/
Generating WorkPeriods
6:00
Tue May 22 Wed May 23 Thu May 24

9:00

12:00

15:00

18:00

21:00
Generating WorkPeriods
6:00
Tue May 22 Wed May 23 Thu May 24

9:00

12:00

15:00

18:00

21:00
Generating WorkPeriods
The java.time API — examples
LocalTime LocalDate LocalDateTime Duration
Creation
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
24)
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
24)
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate factory methods
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
24)
of(int year,=int month,
List<WorkPeriod> workPeriods int dayOfMonth)
Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
of(int year, Month month, int dayOfMonth)
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate factory methods
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
24)
of(int year,=int month,
List<WorkPeriod> workPeriods int dayOfMonth)
Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
of(int year, Month month, int dayOfMonth)
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
ofEpochDay(long epochDay)
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate factory methods
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
24)
of(int year,=int month,
List<WorkPeriod> workPeriods int dayOfMonth)
Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
of(int year, Month month, int dayOfMonth)
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
ofEpochDay(long epochDay)
workPeriods.stream()
ofYearDay(int year, int dayOfYear)
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate factory methods
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
24)
of(int year,=int month,
List<WorkPeriod> workPeriods int dayOfMonth)
Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
of(int year, Month month, int dayOfMonth)
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
ofEpochDay(long epochDay)
workPeriods.stream()
ofYearDay(int year, int dayOfYear)
.map(WorkPeriod::getStartTime)
now(), now(ZoneId)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate factory methods
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
24)
of(int year,=int month,
List<WorkPeriod> workPeriods int dayOfMonth)
Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
of(int year, Month month, int dayOfMonth)
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
ofEpochDay(long epochDay)
workPeriods.stream()
ofYearDay(int year, int dayOfYear)
.map(WorkPeriod::getStartTime)
now(), now(ZoneId)
.map(LocalDateTime::getDayOfWeek)
.distinct()
now(Clock clock)
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY,
Arrays.asList(THURSDAY, FRIDAY, MONDAY),
MONDAY)
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
import static java.time.DayOfWeek.*;
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY,
Arrays.asList(THURSDAY, FRIDAY, MONDAY),
MONDAY)
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
map(LocalDateTime::getDayOfWeek)
LocalDateTime::getDayOfWeek
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
map(LocalDateTime::getDayOfWeek)
LocalDateTime::getDayOfWeek
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
distinct()
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
collect(toList())
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
@Test
public void testGenerateWorkPeriods() {
LocalDate thur24May2017 = LocalDate.of(2018, 5, 24);
List<WorkPeriod> workPeriods = Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
workPeriods.stream()
.map(WorkPeriod::getStartTime)
.map(LocalDateTime::getDayOfWeek)
.distinct()
.collect(toList()));
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
@Test LocalDateTime accessor methods
public void testGenerateWorkPeriods()
int {
getDayOfMonth()
LocalDate thur24May2017 = LocalDate.of(2018,
DayOfWeek getDayOfWeek() 5, 24);
List<WorkPeriod> workPeriods
int = getDayOfYear()
Utils.generateWorkPeriods(thur24May2017, 3);
assertEquals(6, workPeriods.size());
int getHour()
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
int getMinute()
workPeriods.stream()
Month getMonth()
.map(WorkPeriod::getStartTime)
int getMonthValue()
.map(LocalDateTime::getDayOfWeek)
int getNano()
.distinct()
int
.collect(toList())); getSecond
} int getYear()

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
@Test LocalDateTime accessor methods
public void testGenerateWorkPeriods()
int {
getDayOfMonth()
LocalDateTime field accessor methods
LocalDate thur24May2017 = LocalDate.of(2018,
DayOfWeek getDayOfWeek() 5, 24);
int get(TemporalField)
List<WorkPeriod> workPeriods
int = getDayOfYear()
Utils.generateWorkPeriods(thur24May2017, 3);
long
assertEquals(6, workPeriods.size());getLong(TemporalField)
int getHour()
assertEquals(Arrays.asList(THURSDAY, FRIDAY, MONDAY),
int getMinute()
workPeriods.stream()
Month getMonth()
.map(WorkPeriod::getStartTime)
int getMonthValue()
.map(LocalDateTime::getDayOfWeek)
int getNano()
.distinct()
int
.collect(toList())); getSecond
} int getYear()

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
LocalDateTime field accessor methods
int get(TemporalField)
long getLong(TemporalField)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
LocalDateTime field accessor methods
int get(TemporalField)
long getLong(TemporalField)

import static java.time.temporal.ChronoField.*;

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
LocalDateTime field accessor methods
int get(TemporalField)
long getLong(TemporalField)

import static java.time.temporal.ChronoField.*;

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
LocalDateTime field accessor methods
int get(TemporalField)
long getLong(TemporalField)

import static java.time.temporal.ChronoField.*;

workPeriod.getStartTime().get(AMPM_OF_DAY)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
LocalDateTime field accessor methods
int get(TemporalField)
long getLong(TemporalField)

import static java.time.temporal.ChronoField.*;

workPeriod.getStartTime().get(AMPM_OF_DAY)
workPeriod.getStartTime().get(DAY_OF_WEEK)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
The java.time API — examples
LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
dayCount)
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
The java.time API — examples
LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)
.limit(dayCount)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)
.limit(dayCount)
.collect(toList());

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)
.limit(dayCount)
.collect(toList());
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
The java.time API — examples
LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalDate adjustment methods startDate, int dayCount) {
List<LocalDate> generateWorkingDays(LocalDate
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalDate adjustment methods startDate, int dayCount) {
List<LocalDate> generateWorkingDays(LocalDate
plusDays(long), plusMonths(long), plusWeeks(long), plusYears(long)
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalDate adjustment methods startDate, int dayCount) {
List<LocalDate> generateWorkingDays(LocalDate
plusDays(long), plusMonths(long), plusWeeks(long), plusYears(long)
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)
minusDays(long), minusMonths(long),...

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalDate adjustment methods startDate, int dayCount) {
List<LocalDate> generateWorkingDays(LocalDate
plusDays(long), plusMonths(long), plusWeeks(long), plusYears(long)
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)
minusDays(long), minusMonths(long),...
plus(long, TemporalUnit), minus(long, TemporalUnit)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
(from JDK source)
public enum ChronoUnit implements TemporalUnit {
NANOS(…),MICROS(…),MILLIS(…),SECONDS(…),MINUTES(…),HOURS(…),…
}
LocalDate adjustment methods startDate, int dayCount) {
List<LocalDate> generateWorkingDays(LocalDate
plusDays(long), plusMonths(long), plusWeeks(long), plusYears(long)
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)
minusDays(long), minusMonths(long),...
plus(long, TemporalUnit), minus(long, TemporalUnit)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalDate adjustment methods startDate, int dayCount) {
List<LocalDate> generateWorkingDays(LocalDate
plusDays(long), plusMonths(long), plusWeeks(long), plusYears(long)
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)
minusDays(long), minusMonths(long),...
plus(long, TemporalUnit), minus(long, TemporalUnit)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalDate adjustment methods startDate, int dayCount) {
List<LocalDate> generateWorkingDays(LocalDate
plusDays(long), plusMonths(long), plusWeeks(long), plusYears(long)
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)
minusDays(long), minusMonths(long),...
plus(long, TemporalUnit), minus(long, TemporalUnit)
plus(TemporalAmount), minus(TemporalAmount)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalDate adjustment methods startDate, int dayCount) {
List<LocalDate> generateWorkingDays(LocalDate
plusDays(long), plusMonths(long), plusWeeks(long), plusYears(long)
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)
minusDays(long), minusMonths(long),...
plus(long, TemporalUnit), minus(long, TemporalUnit)
plus(TemporalAmount), minus(TemporalAmount)
withDayOfMonth(int), withDayOfYear(int), withMonth(int), withYear(int)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
d.plusDays(1)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
private static boolean isWorkingDay(LocalDate d) {
return d.getDayOfWeek() != DayOfWeek.SATURDAY && 

d.getDayOfWeek() != DayOfWeek.SUNDAY;
}
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
private static boolean isWorkingDay(LocalDate d) {
return d.getDayOfWeek() != DayOfWeek.SATURDAY && 

d.getDayOfWeek() != DayOfWeek.SUNDAY;
}
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
private static boolean isWorkingDay(LocalDate d) {
return d.getDayOfWeek() != DayOfWeek.SATURDAY && 

d.getDayOfWeek() != DayOfWeek.SUNDAY;
} LocalDate accessor methods
int getDayOfMonth()
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
DayOfWeek getDayOfWeek()
return Stream.iterate(startDate, d -> d.plusDays(1))
int getDayOfYear()
.filter(Utils::isWorkingDay)
Month getMonth()
int getMonthValue()
int getYear()

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
private static boolean isWorkingDay(LocalDate d) {
return d.getDayOfWeek() != DayOfWeek.SATURDAY && 

d.getDayOfWeek() != DayOfWeek.SUNDAY;
} LocalDate accessor methods
int getDayOfMonth()
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
DayOfWeek LocalDate
getDayOfWeek()
field accessor methods
return Stream.iterate(startDate, d -> d.plusDays(1))
int int getDayOfYear()
get(TemporalField)
.filter(Utils::isWorkingDay)
Month long getMonth()
getLong(TemporalField)
int getMonthValue()
int getYear()

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
private static boolean isWorkingDay(LocalDate d) {
return d.getDayOfWeek() != DayOfWeek.SATURDAY && 

d.getDayOfWeek() != DayOfWeek.SUNDAY;
}
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
private static boolean isWorkingDay(LocalDate d) {
return d.getDayOfWeek() != DayOfWeek.SATURDAY && 

d.getDayOfWeek() != DayOfWeek.SUNDAY;
}
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)
.limit(dayCount)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
private static boolean isWorkingDay(LocalDate d) {
return d.getDayOfWeek() != DayOfWeek.SATURDAY && 

d.getDayOfWeek() != DayOfWeek.SUNDAY;
}
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)
.limit(dayCount)
.collect(toList());

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
private static boolean isWorkingDay(LocalDate d) {
return d.getDayOfWeek() != DayOfWeek.SATURDAY && 

d.getDayOfWeek() != DayOfWeek.SUNDAY;
}
List<LocalDate> generateWorkingDays(LocalDate startDate, int dayCount) {
return Stream.iterate(startDate, d -> d.plusDays(1))
.filter(Utils::isWorkingDay)
.limit(dayCount)
.collect(toList());
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart
amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);

List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {


List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart
amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0)
0);

List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {


List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart
amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0)
0);

List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {


List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart
amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0)
0);
LocalTime factory methods
of(int hour, int minute)
List<WorkPeriod> generateWorkPeriods(LocalDate
of(int hour, int minute, int second) date, int dayCount) {
of(int hour, int minute,
List<LocalDate> workingDays = int second, int nanoOfSecond)
generateWorkingDays(date, dayCount);
ofNanoOfDay(long nanoOfDay)
return generateWorkPeriods(workingDays, amStart amStart, workPeriodLength,
ofSecondOfDay(long secondOfDay)
now(), now(Clock), now(ZoneId)
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);

List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {


List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart
amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);

List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {


List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);

List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {


List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
workPeriodLength
pmStart, workPeriodLength);
workPeriodLength
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration.ofHours(3).plusMinutes(30);
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
workPeriodLength
pmStart, workPeriodLength);
workPeriodLength
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration.ofHours(3).plusMinutes(30);
ofHours(3)
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration.ofHours(3).plusMinutes(30);
ofHours(3)
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration
Duration.ofHours(3).plusMinutes(30);
ofHours(3)
factory methods
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration Duration.ofHours(3).plusMinutes(30);
ofHours(3)
factory methods
List<WorkPeriod> generateWorkPeriods(LocalDate
ofDays(long), ofHours(long), date,
ofMinutes(long), ofSeconds(long), int dayCount)
ofMillis(long), {
ofNanos(long)
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration Duration.ofHours(3).plusMinutes(30);
ofHours(3)
factory methods
List<WorkPeriod> generateWorkPeriods(LocalDate
ofDays(long), ofHours(long), date,
ofMinutes(long), ofSeconds(long), int dayCount)
ofMillis(long), {
ofNanos(long)
List<LocalDate>
of(long, TemporalUnit)workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration Duration.ofHours(3).plusMinutes(30);
ofHours(3)
factory methods
List<WorkPeriod> generateWorkPeriods(LocalDate
ofDays(long), ofHours(long), date,
ofMinutes(long), ofSeconds(long), int dayCount)
ofMillis(long), {
ofNanos(long)
List<LocalDate>
of(long, TemporalUnit)workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays,
between(Temporal, Temporal) amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration Duration.ofHours(3).plusMinutes(30);
ofHours(3)
factory methods
List<WorkPeriod> generateWorkPeriods(LocalDate
ofDays(long), ofHours(long), date,
ofMinutes(long), ofSeconds(long), int dayCount)
ofMillis(long), {
ofNanos(long)
List<LocalDate>
of(long, TemporalUnit)workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays,
between(Temporal, Temporal) amStart, workPeriodLength,
from(TemporalAmount) pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration.ofHours(3).plusMinutes(30);
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration.ofHours(3).plusMinutes(30);
plusMinutes(30)
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek()
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration.ofHours(3).plusMinutes(30);
plusMinutes(30)
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration adjustment methods
Duration workPeriodLength
plusDays(long), =plusHours(long),
Duration.ofHours(3).plusMinutes(30);
plusMinutes(30)
plusMinutes(long),
List<WorkPeriod> plusSeconds(long),plusMillis(long),
generateWorkPeriods(LocalDate plusNanos(long)
date, int dayCount) {
minusDays(long), minusHours(long),...
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
plus(Duration), minus(Duration)
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
minus(long, TemporalUnit), plus(long, TemporalUnit)
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
LocalTime amStart = LocalTime.of(9, 0);
LocalTime pmStart = LocalTime.of(13, 30);
Duration workPeriodLength = Duration.ofHours(3).plusMinutes(30);
List<WorkPeriod> generateWorkPeriods(LocalDate date, int dayCount) {
List<LocalDate> workingDays = generateWorkingDays(date, dayCount);
return generateWorkPeriods(workingDays, amStart, workPeriodLength,
pmStart, workPeriodLength);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
The java.time API — examples
LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
amStart)
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
amStart)
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
amStart)
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute, int second, int nanoOfSecond)
amStart)
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month, second, int nanoOfSecond)
days) {int dayOfMonth, int hour, int minute, int second)
amStart)
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute) second, int nanoOfSecond)
minute, int second)
amStart)
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute) second, int nanoOfSecond)
minute, int second)
LocalDateTime
of(int thisAmStart
year, Month month, int= dayOfMonth,
LocalDateTime.of(d, amStart)
int hour,amStart);
int minute, int second, int nanoOfSecond)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute) second, int nanoOfSecond)
minute, int second)
LocalDateTime
of(int thisAmStart
year, Month month, int= dayOfMonth,
LocalDateTime.of(d, amStart)
int hour,amStart);
int minute, int second,
second) int nanoOfSecond)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute) second, int nanoOfSecond)
minute, int second)
LocalDateTime
of(int thisAmStart
year, Month month, int= dayOfMonth,
LocalDateTime.of(d, amStart)
int hour,amStart);
minute, int second,
int minute) second) int nanoOfSecond)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute) second, int nanoOfSecond)
minute, int second)
LocalDateTime
of(int thisAmStart
year, Month month, int= dayOfMonth,
LocalDateTime.of(d, amStart)
int hour,amStart);
minute, int second,
int minute) second) int nanoOfSecond)
of(LocalDate date, LocalTime time)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute) second, int nanoOfSecond)
minute, int second)
LocalDateTime
of(int thisAmStart
year, Month month, int= dayOfMonth,
LocalDateTime.of(d, amStart)
int hour,amStart);
minute, int second,
int minute) second) int nanoOfSecond)
of(LocalDate date, LocalTime time)
now(), now(Clock), now(ZoneId)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute) second, int nanoOfSecond)
minute, int second)
LocalDateTime
of(int thisAmStart
year, Month month, int= dayOfMonth,
LocalDateTime.of(d, amStart)
int hour,amStart);
minute, int second,
int minute) second) int nanoOfSecond)
of(LocalDate date, LocalTime time)
now(), now(Clock), now(ZoneId)
ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
LocalDateTime factory methods
List<WorkPeriod> periods = new ArrayList<>();
of(int
for year, int
(LocalDate d : month,
days) {int dayOfMonth, int hour, int minute) second, int nanoOfSecond)
minute, int second)
LocalDateTime
of(int thisAmStart
year, Month month, int= dayOfMonth,
LocalDateTime.of(d, amStart)
int hour,amStart);
minute, int second,
int minute) second) int nanoOfSecond)
of(LocalDate date, LocalTime time)
now(), now(Clock), now(ZoneId)
ofEpochSecond(long epochSecond, int nanoOfSecond, ZoneOffset offset)
ofInstant(Instant instant, ZoneId zone)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);
periods.add(new WorkPeriod(thisAmStart, thisAmStart.plus(amDuration)));

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);
periods.add(new WorkPeriod(thisAmStart, thisAmStart.plus(amDuration)
thisAmStart.plus(amDuration)));

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);
periods.add(new WorkPeriod(thisAmStart, thisAmStart.plus(amDuration)
thisAmStart.plus(amDuration)));

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
LocalDateTime adjustment methods
for (LocalDate d : days) {
plusDays(long),
LocalDateTime thisAmStart plusHours(long),
= LocalDateTime.of(d, plusMinutes(long),
amStart);
plusSeconds(long),plusMillis(long),
periods.add(new WorkPeriod(thisAmStart, plusNanos(long)
thisAmStart.plus(amDuration)));
thisAmStart.plus(amDuration)
minusDays(long), minusHours(long),...
plus(Duration), minus(Duration)
minus(long, TemporalUnit), plus(long, TemporalUnit)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);
periods.add(new WorkPeriod(thisAmStart, thisAmStart.plus(amDuration)));

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);
periods.add(new WorkPeriod(thisAmStart, thisAmStart.plus(amDuration)));
LocalDateTime thisPmStart = LocalDateTime.of(d, pmStart);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);
periods.add(new WorkPeriod(thisAmStart, thisAmStart.plus(amDuration)));
LocalDateTime thisPmStart = LocalDateTime.of(d, pmStart);
periods.add(new WorkPeriod(thisPmStart, thisPmStart.plus(pmDuration)));

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
List<WorkPeriod> generateWorkPeriods(List<LocalDate> days, LocalTime amStart, Duration amDuration,
LocalTime pmStart, Duration pmDuration) {
List<WorkPeriod> periods = new ArrayList<>();
for (LocalDate d : days) {
LocalDateTime thisAmStart = LocalDateTime.of(d, amStart);
periods.add(new WorkPeriod(thisAmStart, thisAmStart.plus(amDuration)));
LocalDateTime thisPmStart = LocalDateTime.of(d, pmStart);
periods.add(new WorkPeriod(thisPmStart, thisPmStart.plus(pmDuration)));
}
return periods;
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
Splitting periods

WorkPeriod p1 = new WorkPeriod(ldt1,ldt2);


Splitting periods

WorkPeriod p1 = new WorkPeriod(ldt1,ldt2);

ldt1 ldt2

p1
Splitting periods

WorkPeriod p1 = new WorkPeriod(ldt1,ldt2);


Optional<WorkPeriod> p2 = p1.split(splitTime);

ldt1 ldt2

p1
Splitting periods

WorkPeriod p1 = new WorkPeriod(ldt1,ldt2);


Optional<WorkPeriod> p2 = p1.split(splitTime);

ldt1 splitTime ldt2

p1
Splitting periods

WorkPeriod p1 = new WorkPeriod(ldt1,ldt2);


Optional<WorkPeriod> p2 = p1.split(splitTime);

ldt1 splitTime ldt2

p1
Splitting periods

WorkPeriod p1 = new WorkPeriod(ldt1,ldt2);


Optional<WorkPeriod> p2 = p1.split(splitTime);

ldt1 splitTime ldt2

p1 p2
The java.time API — examples
LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(1, 0);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(1, 0);
WorkPeriod p = new WorkPeriod(startTime, endTime);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(1, 0);
WorkPeriod p = new WorkPeriod(startTime, endTime);
Optional<WorkPeriod> newPeriod = p.split();

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(1, 0);
WorkPeriod p = new WorkPeriod(startTime, endTime);
Optional<WorkPeriod> newPeriod = p.split();

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(1, 0);
WorkPeriod p = new WorkPeriod(startTime, endTime);
Optional<WorkPeriod> newPeriod = p.split();

LocalDateTime midnight = LocalDate.now().plusDays(1).atStartOfDay();

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(1, 0);
WorkPeriod p = new WorkPeriod(startTime, endTime);
Optional<WorkPeriod> newPeriod = p.split();

LocalDateTime midnight = LocalDate.now().plusDays(1).atStartOfDay();


assertEquals(Optional.of(new WorkPeriod(startTime,midnight)), newPeriod);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(1, 0);
WorkPeriod p = new WorkPeriod(startTime, endTime);
Optional<WorkPeriod> newPeriod = p.split();

LocalDateTime midnight = LocalDate.now().plusDays(1).atStartOfDay();


assertEquals(Optional.of(new WorkPeriod(startTime,midnight)), newPeriod);
assertEquals(new WorkPeriod(midnight, endTime),p);

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
@Test
public void basicSplitTest() {
LocalDateTime startTime = LocalDate.now().atTime(23, 0);
LocalDateTime endTime = LocalDate.now().plusDays(1).atTime(1, 0);
WorkPeriod p = new WorkPeriod(startTime, endTime);
Optional<WorkPeriod> newPeriod = p.split();

LocalDateTime midnight = LocalDate.now().plusDays(1).atStartOfDay();


assertEquals(Optional.of(new WorkPeriod(startTime,midnight)), newPeriod);
assertEquals(new WorkPeriod(midnight, endTime),p);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
public Optional<WorkPeriod> split(LocalDateTime splitTime) {
if (startTime.isBefore(splitTime) && splitTime.isBefore(endTime)) {
WorkPeriod newPeriod =
new WorkPeriod(startTime, Duration.between(startTime, splitTime));
startTime = splitTime;
return Optional.of(newPeriod);
} else {
return Optional.empty();
}
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
public Optional<WorkPeriod> split(LocalDateTime splitTime) {
startTime.isBefore(splitTime) && splitTime.isBefore(endTime)
if (startTime.isBefore(splitTime) splitTime.isBefore(endTime)) {
WorkPeriod newPeriod =
new WorkPeriod(startTime, Duration.between(startTime, splitTime));
startTime = splitTime;
return Optional.of(newPeriod);
} else {
return Optional.empty();
}
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison
Conversion
public Optional<WorkPeriod> split(LocalDateTime splitTime) {
startTime.isBefore(splitTime) && splitTime.isBefore(endTime)
if (startTime.isBefore(splitTime) splitTime.isBefore(endTime)) {
WorkPeriod newPeriod =
new WorkPeriod(startTime, Duration.between(startTime, splitTime));
startTime = splitTime;
return Optional.of(newPeriod);
} else {
return Optional.empty();
}
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion
public Optional<WorkPeriod> split(LocalDateTime splitTime) {
startTime.isBefore(splitTime) && splitTime.isBefore(endTime)
if (startTime.isBefore(splitTime) splitTime.isBefore(endTime)) {
WorkPeriod newPeriodLocalDateTime
= comparison methods
new WorkPeriod(startTime, Duration.between(startTime, splitTime));
isAfter(ChronoLocalDateTime<?>)
startTime = splitTime;
isBefore(ChronoLocalDateTime<?>)
return Optional.of(newPeriod);
isEqual(ChronoLocalDateTime<?>)
} else {
compareTo(ChronoLocalDateTime<?>)
return Optional.empty();
}
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion
public WorkPeriod split() {
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime midnight = startTime.toLocalDate().plusDays(1).atStartOfDay();
return split(midnight);

} return split(midnight);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion
public WorkPeriod split() {
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime midnight = startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate()
return split(midnight);

} return split(midnight);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion
public WorkPeriod split() {
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime midnight = startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate()
return split(midnight);

} return split(midnight);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion toLocalDate()
public WorkPeriod split() {
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime midnight = startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight);

} return split(midnight);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion toLocalDate()
public WorkPeriod split() {
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime midnight = startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight);

} return split(midnight);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion atStartOfDay() toLocalDate()
public WorkPeriod split() { Conversion methods
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime midnight = startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight);

} return split(midnight);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion atStartOfDay() toLocalDate()
public WorkPeriod split() { Conversion methods
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
toLocalDate()
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime ->midnight
LocalDateTime LocalDate/Time
= startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight); toLocalTime()

} return split(midnight);
}

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion atStartOfDay() toLocalDate()
public WorkPeriod split() { Conversion methods
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
toLocalDate()
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime ->midnight
LocalDateTime LocalDate/Time
= startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight); toLocalTime()

} return split(midnight); atStartOfDay()
}
LocalDate -> LocalDateTime atTime(int hour, int minute, int second, int nanos)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion atStartOfDay() toLocalDate()
public WorkPeriod split() { Conversion methods
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
toLocalDate()
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime ->midnight
LocalDateTime LocalDate/Time
= startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight); toLocalTime()

} return split(midnight); atStartOfDay()
} atTime(int hour, int minute, int second)
LocalDate -> LocalDateTime atTime(int hour, int minute, int second, int nanos)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion atStartOfDay() toLocalDate()
public WorkPeriod split() { Conversion methods
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
toLocalDate()
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime ->midnight
LocalDateTime LocalDate/Time
= startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight); toLocalTime()

} return split(midnight); atStartOfDay()
} atTime(int hour, int minute, int second)
LocalDate -> LocalDateTime atTime(int hour, int minute)
minute, int second, int nanos)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion atStartOfDay() toLocalDate()
public WorkPeriod split() { Conversion methods
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
toLocalDate()
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime ->midnight
LocalDateTime LocalDate/Time
= startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight); toLocalTime()

} return split(midnight); atStartOfDay()
} atTime(int hour, int minute, int second)
LocalDate -> LocalDateTime atTime(int hour, int minute)
minute, int second, int nanos)
atTime(LocalTime)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion atStartOfDay() toLocalDate()
public WorkPeriod split() { Conversion methods
public Optional<WorkPeriod>
LocalDateTime midnight = split() {
toLocalDate()
startTime.toLocalDate().atStartOfDay().plusDays(1);
LocalDateTime ->midnight
LocalDateTime LocalDate/Time
= startTime.toLocalDate().plusDays(1).atStartOfDay();
toLocalDate() atStartOfDay()
return split(midnight); toLocalTime()

} return split(midnight); atStartOfDay()
} atTime(int hour, int minute, int second)
LocalDate -> LocalDateTime atTime(int hour, int minute)
minute, int second, int nanos)
atTime(LocalTime)
LocalTime -> LocalDateTime atDate(LocalDate)

The java.time API — examples


LocalTime LocalDate LocalDateTime Duration
Creation of(int,int) of(int,int,int) of(LocalDate,LocalTime) ofHours(long)
Field access getDayOfWeek() getDayOfWeek() plusMinutes(long)
Adjustment plusDays(long) plus(Duration)
Comparison isBefore(ChronoLocalDateTime)
Conversion atStartOfDay() toLocalDate()
Splitting a non-
empty WorkPeriod
Splitting a non-
empty WorkPeriod
In the demo for this module, we’ll see
Splitting a non-
empty WorkPeriod
In the demo for this module, we’ll see
Splitting a non-
• a demo class with a main method that
empty WorkPeriod creates a WorkPeriod containing three
tasks
In the demo for this module, we’ll see
Splitting a non-
• a demo class with a main method that
empty WorkPeriod creates a WorkPeriod containing three
tasks
• how to write the method that splits the
WorkPeriod
A Task Scheduler
6:00
Tue May 22 Wed May 23 Thu May 24

9:00

12:00
answer urgent e-mail 1:00

write deployment report 4:00


15:00
plan security config 4:00

18:00

21:00
A Task Scheduler
6:00
Tue May 22 Wed May 23 Thu May 24

9:00

12:00
answer urgent e-mail 1:00

write deployment report 4:00


15:00
plan security config 4:00

18:00

21:00
A Task Scheduler
6:00
Tue May 22 Wed May 23 Thu May 24

9:00

12:00
answer urgent e-mail 1:00

write deployment report 4:00


15:00
plan security config 4:00

18:00

21:00
A Task Scheduler
6:00
Tue May 22 Wed May 23 Thu May 24

9:00
Answer urgent e-mail

12:00
Write deployment report answer urgent e-mail 1:00

write deployment report 4:00


15:00
plan security config 4:00
Plan security configuration

18:00

21:00
A Task Scheduler
6:00
Tue May 22 Wed May 23 Thu May 24

9:00
Answer urgent e-mail

12:00
Write deployment report answer urgent e-mail 1:00

write deployment report 4:00


15:00
plan security config 4:00
Plan security configuration

18:00

21:00
A Task Scheduler
6:00
Tue May 22 Wed May 23 Thu May 24

9:00
Answer urgent e-mail

Write deployment report


(1 of 2)
12:00
answer urgent e-mail 1:00
Write deployment report
(2 of 2) write deployment report 4:00
15:00
plan security config 4:00
Plan security configuration

18:00

21:00
A Task Scheduler
6:00
Tue May 22 Wed May 23 Thu May 24

9:00
Answer urgent e-mail

Write deployment report


(1 of 2)
12:00
answer urgent e-mail 1:00

Write deployment report write deployment report 4:00


(2 of 2)
15:00
plan security config 4:00

Plan security configuration


18:00

21:00
A Task Scheduler
6:00
Tue May 22 Wed May 23 Thu May 24

9:00
Answer urgent e-mail

Write deployment report


(1 of 2)
12:00
answer urgent e-mail 1:00

Write deployment report write deployment report 4:00


(2 of 2)
15:00
plan security config 4:00

Plan security configuration


18:00

21:00
What is a WorkPeriod?

1 2
WorkPeriod LocalDateTime
What is a WorkPeriod?

2
LocalDateTime

1
WorkPeriod
What is a WorkPeriod?

2
LocalDateTime

1
WorkPeriod

Task
What is a WorkPeriod?

2
LocalDateTime

1
WorkPeriod

TaskPart Task
What is a WorkPeriod?

2
LocalDateTime

1
WorkPeriod

TaskPart Task
* 1
What is a WorkPeriod?

2
LocalDateTime

1
WorkPeriod
1
* TaskPart Task
* 1
Splitting a task-containing period
LocalDate may22 = LocalDate.of(2018,Month.MAY,22);
LocalDateTime startTime = LocalDateTime.of(may22,LocalTime.of(9,0));
WorkPeriod p1 = new WorkPeriod(startTime,startTime.plus(Duration.ofHours(3));

9:00 12:00
Splitting a task-containing period
LocalDate may22 = LocalDate.of(2018,Month.MAY,22);
LocalDateTime startTime = LocalDateTime.of(may22,LocalTime.of(9,0));
WorkPeriod p1 = new WorkPeriod(startTime,startTime.plus(Duration.ofHours(3));

p1.addTaskPart(…); p1.addTaskPart(…); ...

9:00 12:00

Task 1 part 1 Task 2 part 1 Task 3 part 1 Task 4 part 1 Task 5 part 1
Splitting a task-containing period
LocalDate may22 = LocalDate.of(2018,Month.MAY,22);
LocalDateTime startTime = LocalDateTime.of(may22,LocalTime.of(9,0));
WorkPeriod p1 = new WorkPeriod(startTime,startTime.plus(Duration.ofHours(3));

p1.addTaskPart(…); p1.addTaskPart(…); ...

LocalDateTime splitTime = startTime.plus(Duration.ofMinutes(90));

9:00 10:30 12:00

Task 1 part 1 Task 2 part 1 Task 3 part 1 Task 4 part 1 Task 5 part 1
Using NavigableMap

NavigableMap<LocalDateTime,TaskPart> timeToTaskPart;
Using NavigableMap

NavigableMap<LocalDateTime,TaskPart> timeToTaskPart;

keys values
2018-05-22T09:00 Task 1 part 1

2018-05-22T09:40 Task 2 part 1

2018-05-22T10:15 Task 3 part 1

2018-05-22T10:45 Task 4 part 1

2018-05-22T11:20 Task 5 part 1


Using NavigableMap

NavigableMap<LocalDateTime,TaskPart> timeToTaskPart;

keys values
2018-05-22T09:00 Task 1 part 1

2018-05-22T09:40 Task 2 part 1

2018-05-22T10:15 Task 3 part 1


2018-05-22T10:30
2018-05-22T10:45 Task 4 part 1

2018-05-22T11:20 Task 5 part 1


Using NavigableMap

NavigableMap<LocalDateTime,TaskPart> timeToTaskPart;

keys values
2018-05-22T09:00 Task 1 part 1 timeToTaskPart.headMap(
2018-05-22T10:30)
2018-05-22T09:40 Task 2 part 1

2018-05-22T10:15 Task 3 part 1


2018-05-22T10:30
2018-05-22T10:45 Task 4 part 1

2018-05-22T11:20 Task 5 part 1


Using NavigableMap

NavigableMap<LocalDateTime,TaskPart> timeToTaskPart;

keys values
2018-05-22T09:00 Task 1 part 1 timeToTaskPart.headMap(
2018-05-22T10:30)
2018-05-22T09:40 Task 2 part 1

2018-05-22T10:15 Task 3 part 1


2018-05-22T10:30 timeToTaskPart.tailMap(
2018-05-22T10:45 Task 4 part 1 2018-05-22T10:30)

2018-05-22T11:20 Task 5 part 1


Using NavigableMap

NavigableMap<LocalDateTime,TaskPart> timeToTaskPart;

keys values
2018-05-22T09:00 Task 1 part 1 timeToTaskPart.headMap(
timeToTaskPart.lowerEntry(
2018-05-22T10:30)
2018-05-22T10:30)
2018-05-22T09:40 Task 2 part 1

2018-05-22T10:15 Task 3 part 1


2018-05-22T10:30 timeToTaskPart.tailMap(
2018-05-22T10:45 Task 4 part 1 2018-05-22T10:30)

2018-05-22T11:20 Task 5 part 1


Splitting a task-containing period

WorkPeriod p2 = p1.split(splitTime);

9:00 10:30 12:00

Task 1 part 1 Task 2 part 1 Task 3 part 1 Task 4 part 1 Task 5 part 1
Splitting a task-containing period

WorkPeriod p2 = p1.split(splitTime);

9:00 10:30 12:00

p2 Task 1 part 1 Task 2 part 1 Task 3 part 1 Task 4 part 1 Task 5 part 1

p1
Splitting a task-containing period

WorkPeriod p2 = p1.split(splitTime);

9:00 10:30 12:00

Task 1 part 1 Task 2 part 1 Task 3 part 1

Task 4 part 1 Task 5 part 1


Splitting a task-containing period

WorkPeriod p2 = p1.split(splitTime);

9:00 10:30 12:00

Task 1 part 1 Task 2 part 1 Task 3 part 1

Task 4 part 1 Task 5 part 1


Splitting a task-containing period

WorkPeriod p2 = p1.split(splitTime);

9:00 10:30 12:00

Task 1 part 1 Task 2 part 1 T3part1 T3part2

Task 4 part 1 Task 5 part 1


Splitting a task-containing period

WorkPeriod p2 = p1.split(splitTime);

9:00 10:30 12:00

Task 1 part 1 Task 2 part 1 T3part1

T3part2 Task 4 part 1 Task 5 part 1


Summary
Summary
Core classes

Summary
Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary
Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary Core class methods
Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary Core class methods
• Creation, field access, adjustment,
comparison, conversion
Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary Core class methods
• Creation, field access, adjustment,
comparison, conversion

Illustrated in operations on WorkPeriod


Core classes

• LocalDateTime, LocalDate,
LocalTime, Duration
Summary Core class methods
• Creation, field access, adjustment,
comparison, conversion

Illustrated in operations on WorkPeriod


• Creation and splitting

You might also like