|
22 | 22 |
|
23 | 23 | import java.io.File; |
24 | 24 | import java.io.IOException; |
25 | | -import java.time.Instant; |
26 | 25 | import java.util.Date; |
| 26 | + |
27 | 27 | import junitparams.JUnitParamsRunner; |
28 | 28 | import junitparams.Parameters; |
| 29 | +import org.joda.time.DateTime; |
29 | 30 | import org.junit.Test; |
30 | 31 | import org.junit.runner.RunWith; |
31 | 32 | import pl.project13.core.PropertiesFileGenerator; |
@@ -74,135 +75,75 @@ public void testCraftPropertiesOutputFileWithFullPath() throws IOException { |
74 | 75 | } |
75 | 76 |
|
76 | 77 | private Object[] parametersParseOutputTimestamp() { |
| 78 | + /** |
| 79 | + * test cases for output timestamp parsing. |
| 80 | + * This timestamp is configured for Reproducible Builds' archive entries |
| 81 | + * (https://maven.apache.org/guides/mini/guide-reproducible-builds.html). The value from <code> |
| 82 | + * ${project.build.outputTimestamp}</code> is either formatted as ISO 8601 <code> |
| 83 | + * yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like <a |
| 84 | + * href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>. |
| 85 | + * When using ISO 8601 formatting please note that the entire expression must be entirely either |
| 86 | + * in the basic format (20240215T135459+0100) or in the |
| 87 | + * extended format (e.g. 2024-02-15T13:54:59+01:00). |
| 88 | + * The maven plugin only supports the extended format. |
| 89 | + */ |
77 | 90 | return new Object[] { |
78 | 91 | // long since epoch |
79 | 92 | new Object[] { |
80 | 93 | "1644689403", |
81 | | - Instant.ofEpochMilli(1644689403000L) |
82 | | - }, |
83 | | - // Date only: |
84 | | - new Object[] { |
85 | | - "2022-02", |
86 | | - Instant.ofEpochMilli(1643670000000L) |
87 | | - }, |
88 | | - new Object[] { |
89 | | - "2022-02-12", |
90 | | - Instant.ofEpochMilli(1644620400000L) |
91 | | - }, |
92 | | - // Date and time: |
93 | | - new Object[] { |
94 | | - "2022-02-12T15:30", |
95 | | - Instant.ofEpochMilli(1644676200000L) |
96 | | - }, |
97 | | - new Object[] { |
98 | | - "2022-02-12T15:30:45", |
99 | | - Instant.ofEpochMilli(1644676245000L) |
| 94 | + new DateTime("2022-02-12T19:10:03").toDate() |
100 | 95 | }, |
101 | 96 | // Date and time with timezone: |
102 | 97 | new Object[] { |
103 | 98 | "2022-02-12T15:30+00:00", |
104 | | - Instant.ofEpochMilli(1644679800000L) |
| 99 | + new DateTime("2022-02-12T15:30:00+00:00").toDate() |
105 | 100 | }, |
106 | 101 | new Object[] { |
107 | 102 | "2022-02-12T15:30:45-05:00", |
108 | | - Instant.ofEpochMilli(1644697845000L) |
| 103 | + new DateTime("2022-02-12T15:30:45-05:00").toDate() |
109 | 104 | }, |
110 | 105 | new Object[] { |
111 | 106 | "2022-02-12T15:30:00+00:00", |
112 | | - Instant.ofEpochMilli(1644679800000L) |
| 107 | + new DateTime("2022-02-12T15:30:00+00:00").toDate() |
113 | 108 | }, |
114 | 109 | new Object[] { |
115 | 110 | "2023-11-30T09:17:06+05:30", |
116 | | - Instant.ofEpochMilli(1701316026000L) |
| 111 | + new DateTime("2023-11-30T09:17:06+05:30").toDate() |
117 | 112 | }, |
118 | 113 | new Object[] { |
119 | 114 | "2024-08-15T20:45:30-03:00", |
120 | | - Instant.ofEpochMilli(1723765530000L) |
| 115 | + new DateTime("2024-08-15T20:45:30-03:00").toDate() |
121 | 116 | }, |
122 | 117 | new Object[] { |
123 | 118 | "2022-02-12T15:30:00Z", |
124 | | - Instant.ofEpochMilli(1644679800000L) |
| 119 | + new DateTime("2022-02-12T15:30:00Z").toDate() |
125 | 120 | }, |
126 | | - // Not valid according to the ISO 8601 standard. The issue is with the time zone |
127 | | - // representation. ISO 8601 uses a specific format for time zones, either as "Z" for UTC or |
128 | | - // in the format "+HH:MM" or "-HH:MM" for the offset from UTC. |
129 | | - // The time zone "EST" or "PST" does not follow this format. |
130 | | - // new Object[] { "2023-11-30T09:17:06PST", null }, |
131 | | - // new Object[] { "2024-08-15T20:45:30EST", null }, |
132 | 121 | new Object[] { |
133 | 122 | "2023-11-30T09:17:06+0100", |
134 | | - Instant.ofEpochMilli(1701332226000L) |
135 | | - }, |
136 | | - // Week date: |
137 | | - new Object[] { |
138 | | - "2022-W06", |
139 | | - Instant.ofEpochMilli(1644188400000L) |
140 | | - }, |
141 | | - new Object[] { |
142 | | - "2022-W06-5", |
143 | | - Instant.ofEpochMilli(1644534000000L) |
144 | | - }, |
145 | | - // Week date with time: |
146 | | - new Object[] { |
147 | | - "2022-W06-5T15:30", |
148 | | - Instant.ofEpochMilli(1644589800000L) |
149 | | - }, |
150 | | - new Object[] { |
151 | | - "2022-W06-5T15:30:45", |
152 | | - Instant.ofEpochMilli(1644589845000L) |
153 | | - }, |
154 | | - // https://tc39.es/proposal-uniform-interchange-date-parsing/cases.html |
155 | | - // positive leap second |
156 | | - // not working: new Object[] { "1972-06-30T23:59:60Z", null }, |
157 | | - // Too few fractional second digits |
158 | | - new Object[] { |
159 | | - "2019-03-26T14:00:00.9Z", |
160 | | - Instant.ofEpochMilli(1553608800900L) |
161 | | - }, |
162 | | - // Too many fractional second digits |
163 | | - new Object[] { |
164 | | - "2019-03-26T14:00:00.4999Z", |
165 | | - Instant.ofEpochMilli(1553608800499L) |
166 | | - }, |
167 | | - // Too many fractional second digits (pre-epoch) |
168 | | - new Object[] { |
169 | | - "1969-03-26T14:00:00.4999Z", |
170 | | - Instant.ofEpochMilli(-24227999501L) |
171 | | - }, |
172 | | - // Too many fractional second digits (BCE) |
173 | | - new Object[] { |
174 | | - "-000043-03-15T14:00:00.4999Z", |
175 | | - Instant.ofEpochMilli(-63517773599501L) |
| 123 | + new DateTime("2023-11-30T09:17:06+01:00").toDate() |
176 | 124 | }, |
177 | 125 | // Lowercase time designator |
178 | 126 | new Object[] { |
179 | 127 | "2019-03-26t14:00Z", |
180 | | - Instant.ofEpochMilli(1553608800000L) |
| 128 | + new DateTime("2019-03-26T14:00Z").toDate() |
181 | 129 | }, |
182 | 130 | // Lowercase UTC designator |
183 | 131 | new Object[] { |
184 | 132 | "2019-03-26T14:00z", |
185 | | - Instant.ofEpochMilli(1553608800000L) |
| 133 | + new DateTime("2019-03-26T14:00:00Z").toDate() |
186 | 134 | }, |
187 | 135 | // Hours-only offset |
188 | 136 | new Object[] { |
189 | 137 | "2019-03-26T10:00-04", |
190 | | - Instant.ofEpochMilli(1553608800000L) |
191 | | - }, |
192 | | - // Fractional minutes |
193 | | - new Object[] { |
194 | | - "2019-03-26T14:00.9Z", |
195 | | - Instant.ofEpochMilli(1553608854000L) |
| 138 | + new DateTime("2019-03-26T10:00-04:00").toDate() |
196 | 139 | }, |
197 | | - // ISO basic format date and time |
198 | | - // not working: new Object[] { "20190326T1400Z", null }, |
199 | 140 | }; |
200 | 141 | } |
201 | 142 |
|
202 | 143 | @Test |
203 | 144 | @Parameters(method = "parametersParseOutputTimestamp") |
204 | | - public void testParseOutputTimestamp(String input, Instant expected) { |
| 145 | + public void testParseOutputTimestamp(String input, Date expected) { |
205 | 146 | Date actual = GitCommitIdMojo.parseOutputTimestamp(input); |
206 | | - assertThat(actual.toInstant()).isEqualTo(expected); |
| 147 | + assertThat(actual).isEqualTo(expected); |
207 | 148 | } |
208 | 149 | } |
0 commit comments