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

Accept strings in with() methods #1027

Merged
merged 2 commits into from
Oct 21, 2020
Merged

Accept strings in with() methods #1027

merged 2 commits into from
Oct 21, 2020

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Oct 21, 2020

Closes: #934

In Date.with(), DateTime.with(), and Time.with() (and in the future in
ZonedDateTime.with(),) we now accept strings as well as property bags.
The strings are parsed as if with ZonedDateTime.from(), Date.from(),
DateTime.from(), and Time.from() in order, with the stipulation that
Date.from() is skipped if a time part is present in the string. (Otherwise
you would never get a DateTime since Date.from(YYYY-MM-DDTHH:MM:SS) gives
you YYYY-MM-DD.)

The useful reasons to do this are DateTime.with(dateString),
DateTime.with(timeString), ZonedDateTime.with(dateString),
ZonedDateTime.with(timeString), and ZonedDateTime.with(dateTimeString).
However, for the sake of consistency, we allow it as much as possible in
other cases.

Cases were it is not allowed are, YearMonth.with() and MonthDay.with(),
which cannot accept calendars in their property bags, so passing other
Temporal objects there is not allowed in the first place; and YYYY-MM and
MM-DD strings, which are ambiguous with HHMM-ZZ and HH-ZZ.

Closes: #934
@codecov
Copy link

codecov bot commented Oct 21, 2020

Codecov Report

Merging #1027 into main will decrease coverage by 0.01%.
The diff coverage is 92.10%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1027      +/-   ##
==========================================
- Coverage   94.23%   94.22%   -0.02%     
==========================================
  Files          18       18              
  Lines        6284     6321      +37     
  Branches      932      945      +13     
==========================================
+ Hits         5922     5956      +34     
- Misses        355      358       +3     
  Partials        7        7              
Flag Coverage Δ
#test262 45.97% <3.70%> (-0.41%) ⬇️
#tests 90.24% <92.10%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 95.72% <88.00%> (-0.09%) ⬇️
polyfill/lib/date.mjs 92.46% <100.00%> (+0.08%) ⬆️
polyfill/lib/datetime.mjs 95.32% <100.00%> (+0.02%) ⬆️
polyfill/lib/regex.mjs 100.00% <100.00%> (ø)
polyfill/lib/time.mjs 97.32% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e792594...4f97c4e. Read the comment docs.

@Ms2ger Ms2ger merged commit 013a99b into main Oct 21, 2020
@Ms2ger Ms2ger deleted the 934-strings-in-with-methods branch October 21, 2020 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make with() methods accept an ISO string
2 participants