@@ -149,6 +149,11 @@ public final class TimeModuleBuiltins extends PythonBuiltins {
149
149
"offset from UTC in seconds"
150
150
});
151
151
152
+ public static final TruffleString T_TZNAME = tsLiteral ("tzname" );
153
+ public static final TruffleString T_DAYLIGHT = tsLiteral ("daylight" );
154
+ public static final TruffleString T_TIMEZONE = tsLiteral ("timezone" );
155
+ public static final TruffleString T_ALTZONE = tsLiteral ("altzone" );
156
+
152
157
@ Override
153
158
protected List <? extends NodeFactory <? extends PythonBuiltinBaseNode >> getNodeFactories () {
154
159
return TimeModuleBuiltinsFactory .getFactories ();
@@ -157,30 +162,36 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
157
162
@ Override
158
163
public void initialize (Python3Core core ) {
159
164
super .initialize (core );
165
+ StructSequence .initType (core , STRUCT_TIME_DESC );
166
+ addBuiltinConstant ("_STRUCT_TM_ITEMS" , 11 );
167
+ }
168
+
169
+ @ Override
170
+ public void postInitialize (Python3Core core ) {
171
+ super .postInitialize (core );
160
172
// Should we read TZ env variable?
161
173
ZoneId defaultZoneId = core .getContext ().getEnv ().getTimeZone ();
162
174
ModuleState moduleState = new ModuleState ();
163
175
moduleState .currentZoneId = defaultZoneId ;
164
176
moduleState .timeSlept = 0 ;
165
- core .lookupBuiltinModule (T_TIME ).setModuleState (moduleState );
177
+ PythonModule timeModule = core .lookupBuiltinModule (T_TIME );
178
+ timeModule .setModuleState (moduleState );
166
179
167
180
TimeZone defaultTimeZone = TimeZone .getTimeZone (defaultZoneId );
168
181
TruffleString noDaylightSavingZone = toTruffleStringUncached (defaultTimeZone .getDisplayName (false , TimeZone .SHORT ));
169
182
TruffleString daylightSavingZone = toTruffleStringUncached (defaultTimeZone .getDisplayName (true , TimeZone .SHORT ));
170
183
171
184
boolean hasDaylightSaving = !noDaylightSavingZone .equalsUncached (daylightSavingZone , TS_ENCODING );
172
185
if (hasDaylightSaving ) {
173
- addBuiltinConstant ( "tzname" , core .factory ().createTuple (new Object []{noDaylightSavingZone , daylightSavingZone }));
186
+ timeModule . setAttribute ( T_TZNAME , core .factory ().createTuple (new Object []{noDaylightSavingZone , daylightSavingZone }));
174
187
} else {
175
- addBuiltinConstant ( "tzname" , core .factory ().createTuple (new Object []{noDaylightSavingZone }));
188
+ timeModule . setAttribute ( T_TZNAME , core .factory ().createTuple (new Object []{noDaylightSavingZone }));
176
189
}
177
190
178
- addBuiltinConstant ( "daylight" , PInt .intValue (hasDaylightSaving ));
191
+ timeModule . setAttribute ( T_DAYLIGHT , PInt .intValue (hasDaylightSaving ));
179
192
int rawOffsetSeconds = defaultTimeZone .getRawOffset () / -1000 ;
180
- addBuiltinConstant ("timezone" , rawOffsetSeconds );
181
- addBuiltinConstant ("altzone" , rawOffsetSeconds - 3600 );
182
- addBuiltinConstant ("_STRUCT_TM_ITEMS" , 11 );
183
- StructSequence .initType (core , STRUCT_TIME_DESC );
193
+ timeModule .setAttribute (T_TIMEZONE , rawOffsetSeconds );
194
+ timeModule .setAttribute (T_ALTZONE , rawOffsetSeconds - 3600 );
184
195
}
185
196
186
197
@ TruffleBoundary
0 commit comments