@@ -174,7 +174,57 @@ ecma_builtin_date_prototype_to_string (ecma_value_t this_arg) /**< this argument
174
174
static ecma_completion_value_t
175
175
ecma_builtin_date_prototype_to_date_string (ecma_value_t this_arg) /* *< this argument */
176
176
{
177
- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
177
+ ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
178
+
179
+ if (!ecma_is_value_object (this_arg))
180
+ {
181
+ ret_value = ecma_raise_type_error (" Incompatible type" );
182
+ }
183
+ else if (ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
184
+ {
185
+ ret_value = ecma_raise_type_error (" Incompatible type" );
186
+ }
187
+ else
188
+ {
189
+ ECMA_TRY_CATCH (obj_this,
190
+ ecma_op_to_object (this_arg),
191
+ ret_value);
192
+
193
+ ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
194
+ ecma_property_t *prim_value_prop_p;
195
+ prim_value_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
196
+ ecma_number_t *prim_value_num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t ,
197
+ prim_value_prop_p->u .internal_property .value );
198
+
199
+ if (ecma_number_is_nan (*prim_value_num_p))
200
+ {
201
+ ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INVALID_DATE_UL);
202
+ ret_value = ecma_make_normal_completion_value (ecma_make_string_value (magic_str_p));
203
+ }
204
+ else
205
+ {
206
+ ecma_number_t day = ecma_date_date_from_time (*prim_value_num_p);
207
+ ecma_string_t *output_str_p = ecma_new_ecma_string_from_number (day);
208
+ ecma_date_insert_leading_zeros (&output_str_p, day, 2 );
209
+
210
+ /*
211
+ * Note:
212
+ * 'ecma_date_month_from_time' (ECMA 262 v5, 15.9.1.4) returns a number from 0 to 11,
213
+ * but we have to print the month from 1 to 12 for ISO 8601 standard (ECMA 262 v5, 15.9.1.15).
214
+ */
215
+ ecma_number_t month = ecma_date_month_from_time (*prim_value_num_p) + 1 ;
216
+ ecma_date_insert_num_with_sep (&output_str_p, month, LIT_MAGIC_STRING_MINUS_CHAR, 2 );
217
+
218
+ ecma_number_t year = ecma_date_year_from_time (*prim_value_num_p);
219
+ ecma_date_insert_num_with_sep (&output_str_p, year, LIT_MAGIC_STRING_MINUS_CHAR, 4 );
220
+
221
+ ret_value = ecma_make_normal_completion_value (ecma_make_string_value (output_str_p));
222
+ }
223
+
224
+ ECMA_FINALIZE (obj_this);
225
+ }
226
+
227
+ return ret_value;
178
228
} /* ecma_builtin_date_prototype_to_date_string */
179
229
180
230
/* *
@@ -189,7 +239,51 @@ ecma_builtin_date_prototype_to_date_string (ecma_value_t this_arg) /**< this arg
189
239
static ecma_completion_value_t
190
240
ecma_builtin_date_prototype_to_time_string (ecma_value_t this_arg) /* *< this argument */
191
241
{
192
- ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
242
+ ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
243
+
244
+ if (ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
245
+ {
246
+ ret_value = ecma_raise_type_error (" Incomplete Date type" );
247
+ }
248
+ else
249
+ {
250
+ ECMA_TRY_CATCH (obj_this,
251
+ ecma_op_to_object (this_arg),
252
+ ret_value);
253
+
254
+ ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
255
+ ecma_property_t *prim_value_prop_p;
256
+ prim_value_prop_p = ecma_get_internal_property (obj_p, ECMA_INTERNAL_PROPERTY_PRIMITIVE_NUMBER_VALUE);
257
+ ecma_number_t *prim_value_num_p = ECMA_GET_NON_NULL_POINTER (ecma_number_t ,
258
+ prim_value_prop_p->u .internal_property .value );
259
+
260
+ if (ecma_number_is_nan (*prim_value_num_p))
261
+ {
262
+ ecma_string_t *magic_str_p = ecma_get_magic_string (LIT_MAGIC_STRING_INVALID_DATE_UL);
263
+ ret_value = ecma_make_normal_completion_value (ecma_make_string_value (magic_str_p));
264
+ }
265
+ else
266
+ {
267
+ ecma_number_t milliseconds = ecma_date_ms_from_time (*prim_value_num_p);
268
+ ecma_string_t *output_str_p = ecma_new_ecma_string_from_number (milliseconds);
269
+ ecma_date_insert_leading_zeros (&output_str_p, milliseconds, 3 );
270
+
271
+ ecma_number_t seconds = ecma_date_sec_from_time (*prim_value_num_p);
272
+ ecma_date_insert_num_with_sep (&output_str_p, seconds, LIT_MAGIC_STRING_DOT_CHAR, 2 );
273
+
274
+ ecma_number_t minutes = ecma_date_min_from_time (*prim_value_num_p);
275
+ ecma_date_insert_num_with_sep (&output_str_p, minutes, LIT_MAGIC_STRING_COLON_CHAR, 2 );
276
+
277
+ ecma_number_t hours = ecma_date_hour_from_time (*prim_value_num_p);
278
+ ecma_date_insert_num_with_sep (&output_str_p, hours, LIT_MAGIC_STRING_COLON_CHAR, 2 );
279
+
280
+ ret_value = ecma_make_normal_completion_value (ecma_make_string_value (output_str_p));
281
+ }
282
+
283
+ ECMA_FINALIZE (obj_this);
284
+ }
285
+
286
+ return ret_value;
193
287
} /* ecma_builtin_date_prototype_to_time_string */
194
288
195
289
/* *
0 commit comments