Skip to content
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

Implement Date.prototype.toISOString() #418

Closed
wants to merge 1 commit into from

Conversation

rtakacs
Copy link
Contributor

@rtakacs rtakacs commented Jul 16, 2015

Moved toString() logic into the toISOString() method extended with a Z postfix as the standard said.
Since the toString() is "implementation-dependent" the toString() calls the toISOString() method.

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

egavrin commented Jul 16, 2015

Will this change unify smth later?

@@ -32,6 +32,10 @@ assert (new Date (NaN).toDateString () == "Invalid Date");
assert (new Date ("2015-02-13").toDateString () == "2015-02-13");
assert (new Date ("2015-07-08T11:29:05.023").toDateString () == "2015-07-08");

assert (new Date (NaN).toISOString () == "Invalid Date");
assert (new Date ("2015-07-16").toISOString () == "2015-07-16T00:00:00.000Z");
assert (new Date ("2015-07-16T11:29:05.023").toISOString () == "2015-07-16T11:29:05.023Z");
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move the new test cases to the end of the file and add test for TypeError too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

*
* See also:
* ECMA-262 v5, 15.9.5.2
* ECMA-262 v5, 15.9.5.43
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we keep the order of the functions as the ECMA standard declares them?

Copy link
Contributor

Choose a reason for hiding this comment

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

All builtin function names are already declared in ecma-builtin-date-prototype.inc.h. So we don't need to change the position of these functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we could. Added forward declaration for *to_iso_string.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh sorry, the declaration is already in the header.

@rtakacs rtakacs force-pushed the date_toisostring branch 2 times, most recently from 577fc6d to f1d10fd Compare July 16, 2015 12:56
@kkristof
Copy link
Contributor

Looks good to me.

@LaszloLango
Copy link
Contributor

+1 lgtm

{
ecma_number_t milliseconds = ecma_date_ms_from_time (*prim_value_num_p);
ecma_string_t *output_str_p = ecma_get_magic_string (LIT_MAGIC_STRING__EMPTY);
ecma_date_insert_num_with_sep (&output_str_p, milliseconds, LIT_MAGIC_STRING_UTC_TIME_ZONE_U, 3);
Copy link
Contributor

Choose a reason for hiding this comment

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

15.9.5.2 Date.prototype.toString ( )

This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form.

15.9.5.43 Date.prototype.toISOString ( )

This function returns a String value represent the instance in time represented by this Date object. The format of the String is the Date Time string format defined in 15.9.1.15. All fields are present in the String. The time zone is always UTC, denoted by the suffix Z. If the time value of this object is not a finite Number a RangeError exception is thrown.

As output of the toString and the toISOString are different only in timezone part (toISOString outputs in UTC timezone and toString should output in "current" timezone), maybe we should extract the code to a helper with arguments is_current_timezone, and add TODO comment about implementing output in "current" timezone mode.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, the helper could be called from both toString and toISOString implementations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, I missed that the time zone is different from toString and toISOString. The helper is a good solution. The toUTCString could use it as well.

@ruben-ayrapetyan
Copy link
Contributor

Looks good to me

JerryScript-DCO-1.0-Signed-off-by: Roland Takacs rtakacs.u-szeged@partner.samsung.com
@zherczeg
Copy link
Member

LGTM

@egavrin
Copy link
Contributor

egavrin commented Jul 22, 2015

Merged 63083b3

@egavrin egavrin closed this Jul 22, 2015
@galpeter galpeter mentioned this pull request Jul 22, 2015
50 tasks
@rtakacs rtakacs deleted the date_toisostring branch January 18, 2019 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Feature implementation ecma builtins Related to ECMA built-in routines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants