@@ -260,8 +260,10 @@ private TimestampPeriod createNewCache(long timestampInMillis, String formatted)
260260 //
261261 // ISO_OFFSET_DATE_TIME 2020-01-01T10:20:30.123+01:00
262262 // ISO_ZONED_DATE_TIME 2020-01-01T10:20:30.123+01:00[Europe/Brussels]
263+ // 2020-01-01T10:20:30.123Z[UTC]
263264 // ISO_LOCAL_DATE_TIME 2020-01-01T10:20:30.123
264265 // ISO_DATE_TIME 2020-01-01T10:20:30.123+01:00[Europe/Brussels]
266+ // 2020-01-01T10:20:30.123Z[UTC]
265267 // ISO_INSTANT 2020-01-01T09:20:30.123Z
266268 // +---------------+ +---------------------+
267269 // prefix suffix
@@ -272,17 +274,9 @@ private TimestampPeriod createNewCache(long timestampInMillis, String formatted)
272274
273275 // The part up to the minutes (included)
274276 String prefix = formatted .substring (0 , 17 );
275-
276277
277278 // The part of after the millis (i.e. the timezone)
278- int pos = formatted .indexOf ('+' , 17 );
279- if (pos == -1 ) {
280- pos = formatted .indexOf ('-' , 17 );
281- }
282- if (pos == -1 && formatted .charAt (formatted .length () - 1 ) == 'Z' ) {
283- pos = formatted .length () - 1 ;
284- }
285- String suffix = pos == -1 ? "" : formatted .substring (pos );
279+ String suffix = findSuffix (formatted , 17 );
286280
287281 // Determine how long we can use this cache
288282 long timstampInMinutes = timestampInMillis / MILLISECONDS_PER_MINUTE ;
@@ -293,6 +287,36 @@ private TimestampPeriod createNewCache(long timestampInMillis, String formatted)
293287 return new TimestampPeriod (minuteStartInMillis , minuteStopInMillis , prefix , suffix );
294288 }
295289
290+ private String findSuffix (String formatted , int beginIndex ) {
291+ boolean dotFound = false ;
292+ int pos = beginIndex ;
293+
294+ while (pos < formatted .length ()) {
295+ char c = formatted .charAt (pos );
296+
297+ // Allow for a single dot...
298+ if (c == '.' ) {
299+ if (dotFound ) {
300+ break ;
301+ }
302+ else {
303+ dotFound = true ;
304+ }
305+ }
306+ else if (!Character .isDigit (c )) {
307+ break ;
308+ }
309+
310+ pos ++;
311+ }
312+
313+ if (pos < formatted .length ()) {
314+ return formatted .substring (pos );
315+ }
316+ else {
317+ return "" ;
318+ }
319+ }
296320
297321 private String buildFromCache (TimestampPeriod cache , long timestampInMillis ) {
298322 return cache .format (timestampInMillis );
0 commit comments