Skip to content

Commit

Permalink
#972: Ensure a consistent timezone is used in comparisons
Browse files Browse the repository at this point in the history
The service code uses DateUtils to convert a long into a String format,
which DateUtils converting the long to an instant, then an
OffsetDateTime before passing this through a formatter, using the local
timezone during the OffsetDateTime conversion.
As the test was using a pre-created String based on the UTC timezone,
the test does not correctly compare the values when being executed in a
different timezone. To overcome this, the test has been altered to use
the same DateUtils methods to convert from the long to a String, thereby
ensuring the same timezone handling is using in both test and live code.
  • Loading branch information
mc1arke committed Oct 5, 2024
1 parent 5932956 commit 9dbeec4
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.DateUtils;
import org.sonar.db.DbClient;
import org.sonar.db.component.BranchDao;
import org.sonar.db.component.BranchDto;
Expand Down Expand Up @@ -157,7 +158,7 @@ void shouldExecuteRequestWithValidParameter() {
.setKey("prKey2")
.setTitle("title2")
.setBranch("prBranch2")
.setAnalysisDate("2009-02-13T23:31:31+0000")
.setAnalysisDate(DateUtils.formatDateTime(1234567891234L))
.setStatus(ProjectPullRequests.Status.newBuilder()
.build())
.setIsOrphan(true)
Expand Down

0 comments on commit 9dbeec4

Please sign in to comment.