File tree Expand file tree Collapse file tree 3 files changed +9
-7
lines changed
main/java/org/spdx/library
test/java/org/spdx/library Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -332,7 +332,7 @@ public class SpdxConstants {
332332 @ Deprecated
333333 public static final String PROP_REVIEW_DATE = "reviewDate" ;
334334
335- // Date format
335+ // Date format - NOTE: This format does not handle milliseconds. Use Instant.parse for full ISO 8601 parsing
336336 public static final String SPDX_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'" ;
337337
338338 // license ID format
Original file line number Diff line number Diff line change 1717package org .spdx .library ;
1818
1919import java .net .URI ;
20- import java .text . ParseException ;
21- import java .text . SimpleDateFormat ;
20+ import java .time . Instant ;
21+ import java .time . format . DateTimeParseException ;
2222import java .util .Objects ;
2323
2424import org .spdx .library .model .enumerations .ChecksumAlgorithm ;
@@ -118,10 +118,9 @@ private static String verifyOriginatorOrSupplier(String originatorOrSupplier) {
118118 * @return
119119 */
120120 public static String verifyDate (String creationDate ) {
121- SimpleDateFormat format = new SimpleDateFormat (SpdxConstants .SPDX_DATE_FORMAT );
122121 try {
123- format .parse (creationDate );
124- } catch (ParseException e ) {
122+ Instant .parse (creationDate );
123+ } catch (DateTimeParseException e ) {
125124 return ("Invalid date format: " +e .getMessage ());
126125 }
127126 return null ;
Original file line number Diff line number Diff line change @@ -89,8 +89,11 @@ public void testVerifySupplier() {
8989 */
9090 public void testVerifyDate () {
9191 DateFormat format = new SimpleDateFormat (SpdxConstants .SPDX_DATE_FORMAT );
92- assertTrue (Objects .isNull (SpdxVerificationHelper .verifyDate (format .format (new Date ()))));
92+ String fullDate = format .format (new Date ());
93+ assertTrue (Objects .isNull (SpdxVerificationHelper .verifyDate (fullDate )));
9394 assertFalse (Objects .isNull (SpdxVerificationHelper .verifyDate (new Date ().toString ())));
95+ String withSubSeconds = fullDate .substring (0 , fullDate .length ()-1 ) + ".234Z" ;
96+ assertTrue (Objects .isNull (SpdxVerificationHelper .verifyDate (withSubSeconds )));
9497 }
9598
9699 /**
You can’t perform that action at this time.
0 commit comments