Skip to content

Implement Date.prototype.toDateString and Date.prototype.toTimeString #360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

LaszloLango
Copy link
Contributor

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com

@LaszloLango LaszloLango added ecma builtins Related to ECMA built-in routines development Feature implementation labels Jul 10, 2015
@LaszloLango LaszloLango added this to the ECMA builtins milestone Jul 10, 2015
@LaszloLango
Copy link
Contributor Author

@ruben-ayrapetyan, sorry if I merged the #336 too early. I did everything you asked. If I missed something or there are any other issues with it, then we can fix them in this PR too, because is related to it.

ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();

if (ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if I call the function this way?:

Date.prototype.toDateString.call(-1)

@LaszloLango LaszloLango force-pushed the date_todatestring_and_totimestring branch 2 times, most recently from 90f1a78 to 7ca0470 Compare July 13, 2015 09:17
@LaszloLango
Copy link
Contributor Author

@ruben-ayrapetyan, I've updated the PR based on comments on #336. I've added the fixes as a separate commit as you asked. Please check.

}
else if (ecma_object_get_class_name (ecma_get_object_from_value (this_arg)) != LIT_MAGIC_STRING_DATE_UL)
{
ret_value = ecma_raise_type_error ("Incompatible type");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As actions under the conditions of the if and else if blocks are the same, and conditions are not complex, it is better to merge the blocks.

@ruben-ayrapetyan
Copy link
Contributor

After fixing, #360 (comment) and likewise, the changes would look good to me.

@ruben-ayrapetyan
Copy link
Contributor

@ruben-ayrapetyan, I've updated the PR based on comments on #336. I've added the fixes as a separate commit as you asked. Please check.

Thank you for the update.

JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
@LaszloLango LaszloLango force-pushed the date_todatestring_and_totimestring branch from 7ca0470 to e1b9fb6 Compare July 14, 2015 07:02
@LaszloLango
Copy link
Contributor Author

@ruben-ayrapetyan, fixed. Sorry again for inconvenience with #336. @galpeter, please check.

@LaszloLango LaszloLango assigned galpeter and unassigned LaszloLango Jul 14, 2015
@galpeter
Copy link
Contributor

lgtm

@galpeter galpeter removed their assignment Jul 14, 2015
@galpeter galpeter mentioned this pull request Jul 14, 2015
50 tasks
for (uint32_t i = length - 1; i > 0 && num < pow (10,i); i--)
uint32_t first_index = length - 1u;
ecma_number_t power_i = (ecma_number_t) pow (10, first_index);
for (uint32_t i = first_index; i > 0 && num < power_i; i--, power_i /= 10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the range of length? I mean what happens if power_i cannot precisely represent the value? Is that possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it is not possible, the range is 1-4.

assert (new Date(NaN) == "Invalid Date");
assert (new Date("2015-02-13") == "2015-02-13T00:00:00.000");
assert (new Date("2015-07-08T11:29:05.023") == "2015-07-08T11:29:05.023");
assert (new Date (NaN) == "Invalid Date");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't we use 3 equal signs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always write tests like this. :) Should I change this? Why would be 3 equal signs better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it also checks the type, so it is more strict than the two. I would recommend to use it in the future.

Later you can make a style patch to change these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for explain. I'll raise an issue for this.

@zherczeg
Copy link
Member

LGTM

@LaszloLango
Copy link
Contributor Author

@ruben-ayrapetyan, still good? May I push this?

@egavrin egavrin assigned ruben-ayrapetyan and unassigned egavrin Jul 15, 2015
@egavrin egavrin added the critical Raises security concerns label Jul 15, 2015
@ruben-ayrapetyan
Copy link
Contributor

@LaszloLango, yes, the changes look good to me.

@egavrin
Copy link
Contributor

egavrin commented Jul 15, 2015

Merged at 84f09ff and 051c7b6

@egavrin egavrin closed this Jul 15, 2015
@LaszloLango LaszloLango deleted the date_todatestring_and_totimestring branch December 14, 2015 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
critical Raises security concerns development Feature implementation ecma builtins Related to ECMA built-in routines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants