@@ -2310,22 +2310,14 @@ private static Object parse(String string, String format, PythonContext context,
23102310 TimeZone timeZone = TimeModuleBuiltins .getGlobalTimeZone (context );
23112311 String zoneName = timeZone .getDisplayName (false , TimeZone .SHORT );
23122312 String zoneNameDaylightSaving = timeZone .getDisplayName (true , TimeZone .SHORT );
2313+ String matchedZoneName = matchTimeZoneName (string , i , zoneName , zoneNameDaylightSaving , "UTC" , "GMT" );
23132314
2314- if (string .startsWith ("UTC" , i )) {
2315- builder .setTimeZoneName ("UTC" );
2316- i += 3 ;
2317- } else if (string .startsWith ("GMT" , i )) {
2318- builder .setTimeZoneName ("GMT" );
2319- i += 3 ;
2320- } else if (string .startsWith (zoneName , i )) {
2321- builder .setTimeZoneName (zoneName );
2322- i += zoneName .length ();
2323- } else if (string .startsWith (zoneNameDaylightSaving , i )) {
2324- builder .setTimeZoneName (zoneNameDaylightSaving );
2325- i += zoneNameDaylightSaving .length ();
2326- } else {
2315+ if (matchedZoneName == null ) {
23272316 throw PRaiseNode .raiseStatic (inliningTarget , ValueError , ErrorMessages .TIME_DATA_S_DOES_NOT_MATCH_FORMAT_S , string , format );
23282317 }
2318+
2319+ builder .setTimeZoneName (matchedZoneName );
2320+ i += matchedZoneName .length ();
23292321 }
23302322 case 'j' -> {
23312323 var pos = new ParsePosition (i );
@@ -2487,6 +2479,16 @@ private static Integer parseDigits(String source, int from, int digitsCount) {
24872479 return result ;
24882480 }
24892481
2482+ private static String matchTimeZoneName (String string , int from , String ... candidates ) {
2483+ String matched = null ;
2484+ for (String candidate : candidates ) {
2485+ if (candidate != null && string .startsWith (candidate , from ) && (matched == null || candidate .length () > matched .length ())) {
2486+ matched = candidate ;
2487+ }
2488+ }
2489+ return matched ;
2490+ }
2491+
24902492 @ TruffleBoundary
24912493 private static Integer parseDigitsUpTo (String source , ParsePosition from , int maxDigitsCount ) {
24922494 int result = 0 ;
0 commit comments