Skip to content

Commit

Permalink
✨ add support for session end time
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Fihlon <[email protected]>
  • Loading branch information
McPringle committed Mar 25, 2024
1 parent 5d61806 commit 9ceb168
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/swiss/fihlon/apus/conference/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

import java.time.LocalDateTime;

public record Session(String id, LocalDateTime date, String title, String speaker) { }
public record Session(String id, LocalDateTime startDate, LocalDateTime endDate, String title, String speaker) { }
12 changes: 10 additions & 2 deletions src/main/java/swiss/fihlon/apus/conference/doag/ConferenceAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand Down Expand Up @@ -68,7 +69,8 @@ public List<Session> getSessions() {
if (!"lecture".equalsIgnoreCase(type)) {
continue;
}
final LocalTime time = LocalTime.parse(slot.getString("start"));
final LocalTime startTime = LocalTime.parse(slot.getString("start"));
final Duration duration = parseDuration(slot.getString("duration"));
final JSONArray persons = slot.getJSONArray("persons");
final ArrayList<String> speakers = new ArrayList<>(persons.length());
for (int personCounter = 0; personCounter < persons.length(); personCounter++) {
Expand All @@ -78,7 +80,8 @@ public List<Session> getSessions() {
}
final Session session = new Session(
String.format("%s:%d", acronym, slot.getInt("id")),
LocalDateTime.of(date, time),
LocalDateTime.of(date, startTime),
LocalDateTime.of(date, startTime).plus(duration),
slot.getString("title"),
String.join(", ", speakers));
sessions.add(session);
Expand All @@ -91,6 +94,11 @@ public List<Session> getSessions() {
return sessions;
}

private Duration parseDuration(@NotNull final String duration) {
final String minutes = duration.split(":")[1];
return Duration.ofMinutes(Long.parseLong(minutes));
}

private String getJSON() throws IOException, URISyntaxException {
try (InputStream in = new URI(location).toURL().openStream()) {
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
Expand Down

0 comments on commit 9ceb168

Please sign in to comment.