7878import com .oracle .truffle .api .TruffleOptions ;
7979import com .oracle .truffle .api .dsl .Cached ;
8080import com .oracle .truffle .api .dsl .Cached .Shared ;
81+ import com .oracle .truffle .api .dsl .Fallback ;
8182import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
8283import com .oracle .truffle .api .dsl .NodeFactory ;
8384import com .oracle .truffle .api .dsl .Specialization ;
8687import com .oracle .truffle .api .library .CachedLibrary ;
8788import com .oracle .truffle .api .nodes .ExplodeLoop ;
8889import com .oracle .truffle .api .profiles .ConditionProfile ;
90+ import java .time .format .TextStyle ;
91+ import java .util .Locale ;
8992
9093@ CoreFunctions (defineModule = "time" )
9194public final class TimeModuleBuiltins extends PythonBuiltins {
@@ -181,7 +184,7 @@ private static Object[] getTimeStruct(long seconds, boolean local) {
181184 timeStruct [TM_WDAY ] = zonedDateTime .getDayOfWeek ().getValue () - 1 ; /* Want Monday == 0 */
182185 timeStruct [TM_YDAY ] = zonedDateTime .getDayOfYear (); /* Want January, 1 == 1 */
183186 timeStruct [TM_ISDST ] = (zonedDateTime .getZone ().getRules ().isDaylightSavings (instant )) ? 1 : 0 ;
184- timeStruct [9 ] = zone .getId ( );
187+ timeStruct [9 ] = zone .getDisplayName ( TextStyle . SHORT , Locale . ROOT );
185188 timeStruct [10 ] = zonedDateTime .getOffset ().getTotalSeconds ();
186189
187190 return timeStruct ;
@@ -541,8 +544,8 @@ protected static int[] checkStructtime(PTuple time,
541544 CastToJavaIntExactNode toJavaIntExact ,
542545 PRaiseNode raise ) {
543546 Object [] otime = getInternalObjectArrayNode .execute (time .getSequenceStorage ());
544- if (lenNode .execute (time .getSequenceStorage ()) < 9 ) {
545- throw raise .raise (TypeError , ErrorMessages .FUNC_TAKES_AT_LEAST_D_ARGS , 9 , otime . length );
547+ if (lenNode .execute (time .getSequenceStorage ()) != 9 ) {
548+ throw raise .raise (TypeError , ErrorMessages .S_ILLEGAL_TIME_TUPLE_ARG , "asctime()" );
546549 }
547550 int [] date = new int [9 ];
548551 for (int i = 0 ; i < 9 ; i ++) {
@@ -551,7 +554,7 @@ protected static int[] checkStructtime(PTuple time,
551554
552555 // This is specific to java
553556 if (date [TM_YEAR ] < Year .MIN_VALUE || date [TM_YEAR ] > Year .MAX_VALUE ) {
554- throw raise .raise (ValueError , "year out of range" );
557+ throw raise .raise (OverflowError , "year out of range" );
555558 }
556559
557560 if (date [TM_MON ] == 0 ) {
@@ -837,6 +840,9 @@ private static String format(String format, int[] date) {
837840
838841 @ Specialization
839842 public String formatTime (String format , @ SuppressWarnings ("unused" ) PNone time ) {
843+ if (format .indexOf (0 ) > -1 ) {
844+ throw raise (PythonBuiltinClassType .ValueError , ErrorMessages .EMBEDDED_NULL_CHARACTER );
845+ }
840846 return format (format , getIntLocalTimeStruct ((long ) timeSeconds ()));
841847 }
842848
@@ -846,6 +852,9 @@ public String formatTime(String format, PTuple time,
846852 @ Cached SequenceStorageNodes .LenNode lenNode ,
847853 @ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ,
848854 @ Cached CastToJavaIntExactNode castToInt ) {
855+ if (format .indexOf (0 ) > -1 ) {
856+ throw raise (PythonBuiltinClassType .ValueError , ErrorMessages .EMBEDDED_NULL_CHARACTER );
857+ }
849858 int [] date = checkStructtime (time , getArray , lenNode , lib , castToInt , getRaiseNode ());
850859 return format (format , date );
851860 }
@@ -941,6 +950,11 @@ public String localtime(PTuple time,
941950 return format (StrfTimeNode .checkStructtime (time , getArray , lenNode , asPIntLib , toJavaIntExact , getRaiseNode ()));
942951 }
943952
953+ @ Fallback
954+ public Object localtime (@ SuppressWarnings ("unused" ) Object time ) {
955+ throw raise (TypeError , ErrorMessages .TUPLE_OR_STRUCT_TIME_ARG_REQUIRED );
956+ }
957+
944958 protected static String format (int [] tm ) {
945959 return format (CTIME_FORMAT , tm );
946960 }
0 commit comments