Skip to content

Commit

Permalink
add date format to support offset
Browse files Browse the repository at this point in the history
Signed-off-by: Sahiba Mittal <[email protected]>
  • Loading branch information
sahibamittal authored and netomi committed Aug 8, 2024
1 parent 2a773ae commit b407146
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class NugetMetaAnalyzer extends AbstractMetaAnalyzer {

public static final DateFormat[] SUPPORTED_DATE_FORMATS = new DateFormat[]{
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"),
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"),
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
};
private static final Logger LOGGER = Logger.getLogger(NugetMetaAnalyzer.class);
private static final String DEFAULT_BASE_URL = "https://api.nuget.org";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@

import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import static org.dependencytrack.tasks.repositories.NugetMetaAnalyzer.SUPPORTED_DATE_FORMATS;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;

Expand Down Expand Up @@ -121,6 +126,19 @@ public void testAnalyzerWithPrivatePackageRepository() throws Exception {
Assert.assertEquals("5.0.2", metaModel.getLatestVersion());
Assert.assertNotNull(metaModel.getPublishedTimestamp());
}

@Test
public void testPublishedDateTimeFormat() throws ParseException {
Date dateParsed = null;
for (DateFormat dateFormat : SUPPORTED_DATE_FORMATS) {
try {
dateParsed = dateFormat.parse("1900-01-01T00:00:00+00:00");
} catch (ParseException e) {}
}
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Assert.assertEquals(dateFormat.parse("1900-01-01T00:00:00+00:00"), dateParsed);
}

private String readResourceFileToString(String fileName) throws Exception {
return Files.readString(Paths.get(getClass().getResource(fileName).toURI()));
}
Expand Down

0 comments on commit b407146

Please sign in to comment.