78
78
import com .oracle .truffle .api .TruffleOptions ;
79
79
import com .oracle .truffle .api .dsl .Cached ;
80
80
import com .oracle .truffle .api .dsl .Cached .Shared ;
81
+ import com .oracle .truffle .api .dsl .Fallback ;
81
82
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
82
83
import com .oracle .truffle .api .dsl .NodeFactory ;
83
84
import com .oracle .truffle .api .dsl .Specialization ;
86
87
import com .oracle .truffle .api .library .CachedLibrary ;
87
88
import com .oracle .truffle .api .nodes .ExplodeLoop ;
88
89
import com .oracle .truffle .api .profiles .ConditionProfile ;
90
+ import java .time .format .TextStyle ;
91
+ import java .util .Locale ;
89
92
90
93
@ CoreFunctions (defineModule = "time" )
91
94
public final class TimeModuleBuiltins extends PythonBuiltins {
@@ -181,7 +184,7 @@ private static Object[] getTimeStruct(long seconds, boolean local) {
181
184
timeStruct [TM_WDAY ] = zonedDateTime .getDayOfWeek ().getValue () - 1 ; /* Want Monday == 0 */
182
185
timeStruct [TM_YDAY ] = zonedDateTime .getDayOfYear (); /* Want January, 1 == 1 */
183
186
timeStruct [TM_ISDST ] = (zonedDateTime .getZone ().getRules ().isDaylightSavings (instant )) ? 1 : 0 ;
184
- timeStruct [9 ] = zone .getId ( );
187
+ timeStruct [9 ] = zone .getDisplayName ( TextStyle . SHORT , Locale . ROOT );
185
188
timeStruct [10 ] = zonedDateTime .getOffset ().getTotalSeconds ();
186
189
187
190
return timeStruct ;
@@ -541,8 +544,8 @@ protected static int[] checkStructtime(PTuple time,
541
544
CastToJavaIntExactNode toJavaIntExact ,
542
545
PRaiseNode raise ) {
543
546
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()" );
546
549
}
547
550
int [] date = new int [9 ];
548
551
for (int i = 0 ; i < 9 ; i ++) {
@@ -551,7 +554,7 @@ protected static int[] checkStructtime(PTuple time,
551
554
552
555
// This is specific to java
553
556
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" );
555
558
}
556
559
557
560
if (date [TM_MON ] == 0 ) {
@@ -837,6 +840,9 @@ private static String format(String format, int[] date) {
837
840
838
841
@ Specialization
839
842
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
+ }
840
846
return format (format , getIntLocalTimeStruct ((long ) timeSeconds ()));
841
847
}
842
848
@@ -846,6 +852,9 @@ public String formatTime(String format, PTuple time,
846
852
@ Cached SequenceStorageNodes .LenNode lenNode ,
847
853
@ CachedLibrary (limit = "1" ) PythonObjectLibrary lib ,
848
854
@ Cached CastToJavaIntExactNode castToInt ) {
855
+ if (format .indexOf (0 ) > -1 ) {
856
+ throw raise (PythonBuiltinClassType .ValueError , ErrorMessages .EMBEDDED_NULL_CHARACTER );
857
+ }
849
858
int [] date = checkStructtime (time , getArray , lenNode , lib , castToInt , getRaiseNode ());
850
859
return format (format , date );
851
860
}
@@ -941,6 +950,11 @@ public String localtime(PTuple time,
941
950
return format (StrfTimeNode .checkStructtime (time , getArray , lenNode , asPIntLib , toJavaIntExact , getRaiseNode ()));
942
951
}
943
952
953
+ @ Fallback
954
+ public Object localtime (@ SuppressWarnings ("unused" ) Object time ) {
955
+ throw raise (TypeError , ErrorMessages .TUPLE_OR_STRUCT_TIME_ARG_REQUIRED );
956
+ }
957
+
944
958
protected static String format (int [] tm ) {
945
959
return format (CTIME_FORMAT , tm );
946
960
}
0 commit comments