Skip to content
Merged
Next Next commit
Migrate legacy date-time api to new date-time api
Signed-off-by: solonovamax <[email protected]>
  • Loading branch information
solonovamax committed Mar 27, 2025
commit 85f14afde2250ad2cee1fc292bd36931c0ee47d6
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>com.infradna.tool</groupId>
<artifactId>bridge-method-annotation</artifactId>
Expand Down Expand Up @@ -636,7 +640,7 @@
<!--
This plugin is used to generate AOT metadata during tests so that it can be
compared against those in META-INF/native-image/org.kohsuke/github-api/*.
The tests are start with the name "Aot..."
The tests are start with the name "Aot..."
-->
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -158,10 +158,10 @@ public PagedIterable<GHAppInstallation> listInstallations() {
* @return a list of App installations since a given time.
* @see <a href="https://developer.github.com/v3/apps/#list-installations">List installations</a>
*/
public PagedIterable<GHAppInstallation> listInstallations(final Date since) {
public PagedIterable<GHAppInstallation> listInstallations(final Instant since) {
Requester requester = root().createRequest().withUrlPath("/app/installations");
if (since != null) {
requester.with("since", GitHubClient.printDate(since));
requester.with("since", GitHubClient.printInstant(since));
}
return requester.toIterable(GHAppInstallation[].class, null);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHAppInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -189,8 +189,8 @@ public GHRepositorySelection getRepositorySelection() {
*
* @return the suspended at
*/
public Date getSuspendedAt() {
return GitHubClient.parseDate(suspendedAt);
public Instant getSuspendedAt() {
return GitHubClient.parseInstant(suspendedAt);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/kohsuke/github/GHAppInstallationToken.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.kohsuke.github;

import java.time.Instant;
import java.util.*;

// TODO: Auto-generated Javadoc
Expand Down Expand Up @@ -66,7 +67,7 @@ public GHRepositorySelection getRepositorySelection() {
*
* @return date when this token expires
*/
public Date getExpiresAt() {
return GitHubClient.parseDate(expires_at);
public Instant getExpiresAt() {
return GitHubClient.parseInstant(expires_at);
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHArtifact.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import java.io.IOException;
import java.net.URL;
import java.util.Date;
import java.time.Instant;
import java.util.Objects;

import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -77,8 +77,8 @@ public boolean isExpired() {
*
* @return the date of expiration
*/
public Date getExpiresAt() {
return GitHubClient.parseDate(expiresAt);
public Instant getExpiresAt() {
return GitHubClient.parseInstant(expiresAt);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/kohsuke/github/GHCheckRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -269,17 +269,17 @@ public URL getDetailsUrl() {
*
* @return Timestamp of the start time
*/
public Date getStartedAt() {
return GitHubClient.parseDate(startedAt);
public Instant getStartedAt() {
return GitHubClient.parseInstant(startedAt);
}

/**
* Gets the completed time of the check run in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.
*
* @return Timestamp of the completed time
*/
public Date getCompletedAt() {
return GitHubClient.parseDate(completedAt);
public Instant getCompletedAt() {
return GitHubClient.parseInstant(completedAt);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/kohsuke/github/GHCheckRunBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -172,9 +172,9 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) {
* the started at
* @return the GH check run builder
*/
public @NonNull GHCheckRunBuilder withStartedAt(@CheckForNull Date startedAt) {
public @NonNull GHCheckRunBuilder withStartedAt(@CheckForNull Instant startedAt) {
if (startedAt != null) {
requester.with("started_at", GitHubClient.printDate(startedAt));
requester.with("started_at", GitHubClient.printInstant(startedAt));
}
return this;
}
Expand All @@ -186,9 +186,9 @@ private GHCheckRunBuilder(GHRepository repo, Requester requester) {
* the completed at
* @return the GH check run builder
*/
public @NonNull GHCheckRunBuilder withCompletedAt(@CheckForNull Date completedAt) {
public @NonNull GHCheckRunBuilder withCompletedAt(@CheckForNull Instant completedAt) {
if (completedAt != null) {
requester.with("completed_at", GitHubClient.printDate(completedAt));
requester.with("completed_at", GitHubClient.printInstant(completedAt));
}
return this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHCheckSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;

// TODO: Auto-generated Javadoc
Expand Down Expand Up @@ -257,8 +257,8 @@ public String getMessage() {
*
* @return timestamp of the commit
*/
public Date getTimestamp() {
return GitHubClient.parseDate(timestamp);
public Instant getTimestamp() {
return GitHubClient.parseInstant(timestamp);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/kohsuke/github/GHCommit.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import java.io.IOException;
import java.net.URL;
import java.time.Instant;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

// TODO: Auto-generated Javadoc
Expand Down Expand Up @@ -471,7 +471,7 @@ public GHUser getAuthor() throws IOException {
* @throws IOException
* if the information was not already fetched and an attempt at fetching the information failed.
*/
public Date getAuthoredDate() throws IOException {
public Instant getAuthoredDate() throws IOException {
return getCommitShortInfo().getAuthoredDate();
}

Expand All @@ -494,7 +494,7 @@ public GHUser getCommitter() throws IOException {
* @throws IOException
* if the information was not already fetched and an attempt at fetching the information failed.
*/
public Date getCommitDate() throws IOException {
public Instant getCommitDate() throws IOException {
return getCommitShortInfo().getCommitDate();
}

Expand Down
16 changes: 5 additions & 11 deletions src/main/java/org/kohsuke/github/GHCommitBuilder.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package org.kohsuke.github;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

// TODO: Auto-generated Javadoc
/**
Expand All @@ -23,13 +20,10 @@ private static final class UserInfo {
private final String email;
private final String date;

private UserInfo(String name, String email, Date date) {
private UserInfo(String name, String email, Instant date) {
this.name = name;
this.email = email;
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
df.setTimeZone(tz);
this.date = df.format((date != null) ? date : new Date());
this.date = GitHubClient.printInstant(date);
}
}

Expand Down Expand Up @@ -91,7 +85,7 @@ public GHCommitBuilder parent(String parent) {
* the date
* @return the gh commit builder
*/
public GHCommitBuilder author(String name, String email, Date date) {
public GHCommitBuilder author(String name, String email, Instant date) {
req.with("author", new UserInfo(name, email, date));
return this;
}
Expand Down Expand Up @@ -120,7 +114,7 @@ public GHCommitBuilder withSignature(String signature) {
* the date
* @return the gh commit builder
*/
public GHCommitBuilder committer(String name, String email, Date date) {
public GHCommitBuilder committer(String name, String email, Instant date) {
req.with("committer", new UserInfo(name, email, date));
return this;
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.kohsuke.github;

import java.util.Date;
import java.time.Instant;

// TODO: Auto-generated Javadoc
/**
Expand Down Expand Up @@ -89,8 +89,8 @@ public GHCommitQueryBuilder pageSize(int pageSize) {
* the dt
* @return the gh commit query builder
*/
public GHCommitQueryBuilder since(Date dt) {
req.with("since", GitHubClient.printDate(dt));
public GHCommitQueryBuilder since(Instant dt) {
req.with("since", GitHubClient.printInstant(dt));
return this;
}

Expand All @@ -102,7 +102,7 @@ public GHCommitQueryBuilder since(Date dt) {
* @return the gh commit query builder
*/
public GHCommitQueryBuilder since(long timestamp) {
return since(new Date(timestamp));
return since(Instant.ofEpochMilli(timestamp));
}

/**
Expand All @@ -112,8 +112,8 @@ public GHCommitQueryBuilder since(long timestamp) {
* the dt
* @return the gh commit query builder
*/
public GHCommitQueryBuilder until(Date dt) {
req.with("until", GitHubClient.printDate(dt));
public GHCommitQueryBuilder until(Instant dt) {
req.with("until", GitHubClient.printInstant(dt));
return this;
}

Expand All @@ -125,7 +125,7 @@ public GHCommitQueryBuilder until(Date dt) {
* @return the gh commit query builder
*/
public GHCommitQueryBuilder until(long timestamp) {
return until(new Date(timestamp));
return until(Instant.ofEpochMilli(timestamp));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/kohsuke/github/GHDeployKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.IOException;
import java.util.Date;
import java.time.Instant;

// TODO: Auto-generated Javadoc
/**
Expand Down Expand Up @@ -89,17 +89,17 @@ public boolean isVerified() {
*
* @return the created_at
*/
public Date getCreatedAt() {
return GitHubClient.parseDate(created_at);
public Instant getCreatedAt() {
return GitHubClient.parseInstant(created_at);
}

/**
* Gets last_used.
*
* @return the last_used
*/
public Date getLastUsedAt() {
return GitHubClient.parseDate(last_used);
public Instant getLastUsedAt() {
return GitHubClient.parseInstant(last_used);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/kohsuke/github/GHEventInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.io.IOException;
import java.time.Instant;
import java.util.*;

// TODO: Auto-generated Javadoc
Expand Down Expand Up @@ -128,8 +129,8 @@ public long getId() {
*
* @return the created at
*/
public Date getCreatedAt() {
return GitHubClient.parseDate(created_at);
public Instant getCreatedAt() {
return GitHubClient.parseInstant(created_at);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import java.io.IOException;
import java.io.Reader;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -1363,8 +1363,8 @@ public List<String> getModified() {
*
* @return the timestamp
*/
public Date getTimestamp() {
return GitHubClient.parseDate(timestamp);
public Instant getTimestamp() {
return GitHubClient.parseInstant(timestamp);
}
}
}
Expand Down Expand Up @@ -1809,8 +1809,8 @@ public Star() {
*
* @return the date when the star is added
*/
public Date getStarredAt() {
return GitHubClient.parseDate(starredAt);
public Instant getStarredAt() {
return GitHubClient.parseInstant(starredAt);
}
}

Expand Down
Loading
Loading