66import junit .framework .TestCase ;
77
88import java .nio .ByteBuffer ;
9- import java .text .DateFormat ;
10- import java .text .ParseException ;
11- import java .text .SimpleDateFormat ;
12- import java .util .TimeZone ;
9+ import java .time .Instant ;
10+ import java .time .ZoneId ;
11+ import java .time .format .DateTimeFormatter ;
1312
1413@ SuppressWarnings ("UnusedAssignment" )
1514public class TestConvert extends TestCase {
@@ -149,9 +148,9 @@ public void testAppendDoubleBuffer() {
149148
150149 // ################################################################
151150
152- public void testAppendISO8601Millis () throws ParseException {
153- DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd'T'HH:mm:ss.SSS" );
154- dateFormat . setTimeZone ( TimeZone . getTimeZone ("GMT" ));
151+ public void testAppendISO8601Millis () {
152+ DateTimeFormatter dateFormat =
153+ DateTimeFormatter . ofPattern ( "yyyy-MM-dd'T'HH:mm:ss.SSS" ). withZone ( ZoneId . of ("GMT" ));
155154
156155 long [] testCases = {
157156 0L , 1L , 10L , 100L , 1000L , 10000L , 100000L , 1000000L , 10000000L , 100000000L , 1000000000L , 10000000000L ,
@@ -160,7 +159,7 @@ public void testAppendISO8601Millis() throws ParseException {
160159 -10000000000L , -100000000000L , -1000000000000L , -10000000000000L ,
161160 };
162161 for (long testCase : testCases ) {
163- checkAppendIso8601Millis (testCase , dateFormat .format (testCase ));
162+ checkAppendIso8601Millis (testCase , dateFormat .format (Instant . ofEpochMilli ( testCase ) ));
164163 }
165164
166165 checkAppendIso8601Millis (-62167132799999L , "0000-01-01T00:00:00.001" );
@@ -170,9 +169,12 @@ public void testAppendISO8601Millis() throws ParseException {
170169 checkAppendIso8601Millis (253402300799999L , "9999-12-31T23:59:59.999" );
171170 checkAppendIso8601Millis (253402300800000L , "9999-99-99T99:99:99.999" );
172171
173- checkAppendIso8601Millis (dateFormat .parse ("2004-02-20T11:12:13.014" ).getTime (), "2004-02-20T11:12:13.014" );
174- checkAppendIso8601Millis (dateFormat .parse ("2000-02-20T11:12:13.014" ).getTime (), "2000-02-20T11:12:13.014" );
175- checkAppendIso8601Millis (dateFormat .parse ("1900-02-20T11:12:13.014" ).getTime (), "1900-02-20T11:12:13.014" );
172+ checkAppendIso8601Millis (Instant .from (dateFormat .parse ("2004-02-20T11:12:13.014" )).toEpochMilli (),
173+ "2004-02-20T11:12:13.014" );
174+ checkAppendIso8601Millis (Instant .from (dateFormat .parse ("2000-02-20T11:12:13.014" )).toEpochMilli (),
175+ "2000-02-20T11:12:13.014" );
176+ checkAppendIso8601Millis (Instant .from (dateFormat .parse ("1900-02-20T11:12:13.014" )).toEpochMilli (),
177+ "1900-02-20T11:12:13.014" );
176178
177179 {
178180 ByteBuffer byteBuffer = ByteBuffer .allocate (100 );
@@ -188,9 +190,9 @@ private void checkAppendIso8601Millis(long millis, String expectedString) {
188190 assertBufferEqual (byteBuffer , 0 , expectedString );
189191 }
190192
191- public void testAppendISO8601Micros () throws ParseException {
192- DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd'T'HH:mm:ss.SSS" );
193- dateFormat . setTimeZone ( TimeZone . getTimeZone ("GMT" ));
193+ public void testAppendISO8601Micros () {
194+ DateTimeFormatter dateFormat =
195+ DateTimeFormatter . ofPattern ( "yyyy-MM-dd'T'HH:mm:ss.SSS" ). withZone ( ZoneId . of ("GMT" ));
194196
195197 long [] testCases = {
196198 0L ,
@@ -225,7 +227,7 @@ public void testAppendISO8601Micros() throws ParseException {
225227 -10000000000000000L
226228 };
227229 for (long testCase : testCases ) {
228- checkAppendIso8601Micros (testCase , dateFormat .format (testCase / 1000 ) + "000" );
230+ checkAppendIso8601Micros (testCase , dateFormat .format (Instant . ofEpochMilli ( testCase / 1000 ) ) + "000" );
229231 }
230232
231233 checkAppendIso8601Micros (-62167132799999999L , "0000-01-01T00:00:00.000001" );
@@ -235,11 +237,11 @@ public void testAppendISO8601Micros() throws ParseException {
235237 checkAppendIso8601Micros (253402300799999000L , "9999-12-31T23:59:59.999000" );
236238 checkAppendIso8601Micros (253402300800000000L , "9999-99-99T99:99:99.999999" );
237239
238- checkAppendIso8601Micros (dateFormat .parse ("2004-02-20T11:12:13.014" ). getTime () * 1000 ,
240+ checkAppendIso8601Micros (Instant . from ( dateFormat .parse ("2004-02-20T11:12:13.014" )). toEpochMilli () * 1000 ,
239241 "2004-02-20T11:12:13.014000" );
240- checkAppendIso8601Micros (dateFormat .parse ("2000-02-20T11:12:13.014" ). getTime () * 1000 ,
242+ checkAppendIso8601Micros (Instant . from ( dateFormat .parse ("2000-02-20T11:12:13.014" )). toEpochMilli () * 1000 ,
241243 "2000-02-20T11:12:13.014000" );
242- checkAppendIso8601Micros (dateFormat .parse ("1900-02-20T11:12:13.014" ). getTime () * 1000 ,
244+ checkAppendIso8601Micros (Instant . from ( dateFormat .parse ("1900-02-20T11:12:13.014" )). toEpochMilli () * 1000 ,
243245 "1900-02-20T11:12:13.014000" );
244246
245247 {
0 commit comments