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

fix: narrow type for add and subtract #1576

Merged
merged 2 commits into from
Jul 31, 2021
Merged

fix: narrow type for add and subtract #1576

merged 2 commits into from
Jul 31, 2021

Conversation

susiwen8
Copy link
Contributor

Close #1575

@addisonElliott
Copy link

addisonElliott commented Jul 13, 2021

Your fix removes the UnitTypeLongPlural type. So any pluralized types would return errors now. Looking at the code, it also applies to diff() function. Not only that, this doesn't remove the dates plural type.

However, I wonder if it would be better to add support for date in add/subtract/diff. It would be relatively easy and make it consistent with startOf, endOf functions.

FYI, if you use dayjs.add(1, 'date'), it will add 1ms to the date. See here: https://github.com/iamkun/dayjs/blob/dev/src/index.js#L243

If the date keyword is not going to be supported for add/subtract/, I recommend just omitting the date & dates types from the OpUnitType itself.

type OpUnitType2 = Omit<OpUnitType, 'date' | 'dates'>;

@susiwen8
Copy link
Contributor Author

susiwen8 commented Jul 14, 2021

@addisonElliott Thanks,

So any pluralized types would return errors now.

Indeed pluralized type should be included.

if you use dayjs.add(1, 'date'), it will add 1ms to the date

You are right, I tried myself, date act like ms

I wonder if it would be better to add support for date in add/subtract/diff

Agree, I was going to fix this way. But I thought this might be intentional or someting that left date behind

@codecov
Copy link

codecov bot commented Jul 14, 2021

Codecov Report

Merging #1576 (bf7c478) into dev (5a79cc6) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##               dev     #1576   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          177       177           
  Lines         1989      1989           
  Branches       505       505           
=========================================
  Hits          1989      1989           

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 5a79cc6...bf7c478. Read the comment docs.

@susiwen8 susiwen8 closed this Jul 30, 2021
@iamkun
Copy link
Owner

iamkun commented Jul 30, 2021

Yes, date should not be supported in dayjs.add, cause add a date make no sense

@susiwen8
Copy link
Contributor Author

@iamkun should I reopen this PR?

@iamkun
Copy link
Owner

iamkun commented Jul 30, 2021

why not 😁

@susiwen8 susiwen8 reopened this Jul 30, 2021
@susiwen8
Copy link
Contributor Author

@iamkun please review 😁

@iamkun
Copy link
Owner

iamkun commented Jul 30, 2021

BTW, is any special reason to close it?

@susiwen8
Copy link
Contributor Author

Just thought you might not interested in this pr.

@iamkun
Copy link
Owner

iamkun commented Jul 31, 2021

@addisonElliott according to moment.js date is not support as well.

let's just omit it

https://momentjs.com/docs/#/manipulating/add/

image

@iamkun iamkun merged commit 1686962 into iamkun:dev Jul 31, 2021
iamkun pushed a commit that referenced this pull request Sep 10, 2021
## [1.10.7](v1.10.6...v1.10.7) (2021-09-10)

### Bug Fixes

* Add  Spanish (Mexico) [es-mx] locale ([#1614](#1614)) ([3393f2a](3393f2a))
* Add Arabic (Iraq) [ar-iq] locale ([#1627](#1627)) ([b5a1391](b5a1391))
* add format object type to type file ([#1572](#1572)) ([5a79cc6](5a79cc6))
* duration plugin when parsing duration from ISO string, set missing components to 0 instead of NaN ([#1611](#1611)) ([252585b](252585b))
* narrow type for `add` and `subtract` ([#1576](#1576)) ([1686962](1686962))
* update customParseFormat plugin strict x X parsing ([#1571](#1571)) ([08adda5](08adda5))
* update Lithuanian [lt] locale spelling for single month ([#1609](#1609)) ([255dc54](255dc54))
* Update Norwegian Bokmål [nb] local yearStart 4 ([#1608](#1608)) ([7a8467c](7a8467c))
* update plugin advancedFormat `isValid` validation ([#1566](#1566)) ([755fc8b](755fc8b))
* update Sinhalese [si] locale month name ([#1475](#1475)) ([63de2a8](63de2a8))
* update utcOffset plugin type file ([#1604](#1604)) ([f68e4b1](f68e4b1))
@iamkun
Copy link
Owner

iamkun commented Sep 10, 2021

🎉 This PR is included in version 1.10.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this pull request May 10, 2022
## [1.10.7](iamkun/dayjs@v1.10.6...v1.10.7) (2021-09-10)

### Bug Fixes

* Add  Spanish (Mexico) [es-mx] locale ([#1614](iamkun/dayjs#1614)) ([3393f2a](iamkun/dayjs@3393f2a))
* Add Arabic (Iraq) [ar-iq] locale ([#1627](iamkun/dayjs#1627)) ([b5a1391](iamkun/dayjs@b5a1391))
* add format object type to type file ([#1572](iamkun/dayjs#1572)) ([5a79cc6](iamkun/dayjs@5a79cc6))
* duration plugin when parsing duration from ISO string, set missing components to 0 instead of NaN ([#1611](iamkun/dayjs#1611)) ([252585b](iamkun/dayjs@252585b))
* narrow type for `add` and `subtract` ([#1576](iamkun/dayjs#1576)) ([1686962](iamkun/dayjs@1686962))
* update customParseFormat plugin strict x X parsing ([#1571](iamkun/dayjs#1571)) ([08adda5](iamkun/dayjs@08adda5))
* update Lithuanian [lt] locale spelling for single month ([#1609](iamkun/dayjs#1609)) ([255dc54](iamkun/dayjs@255dc54))
* Update Norwegian Bokmål [nb] local yearStart 4 ([#1608](iamkun/dayjs#1608)) ([7a8467c](iamkun/dayjs@7a8467c))
* update plugin advancedFormat `isValid` validation ([#1566](iamkun/dayjs#1566)) ([755fc8b](iamkun/dayjs@755fc8b))
* update Sinhalese [si] locale month name ([#1475](iamkun/dayjs#1475)) ([63de2a8](iamkun/dayjs@63de2a8))
* update utcOffset plugin type file ([#1604](iamkun/dayjs#1604)) ([f68e4b1](iamkun/dayjs@f68e4b1))
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this pull request May 10, 2022
## [1.10.7](iamkun/dayjs@v1.10.6...v1.10.7) (2021-09-10)

### Bug Fixes

* Add  Spanish (Mexico) [es-mx] locale ([#1614](iamkun/dayjs#1614)) ([3393f2a](iamkun/dayjs@3393f2a))
* Add Arabic (Iraq) [ar-iq] locale ([#1627](iamkun/dayjs#1627)) ([b5a1391](iamkun/dayjs@b5a1391))
* add format object type to type file ([#1572](iamkun/dayjs#1572)) ([5a79cc6](iamkun/dayjs@5a79cc6))
* duration plugin when parsing duration from ISO string, set missing components to 0 instead of NaN ([#1611](iamkun/dayjs#1611)) ([252585b](iamkun/dayjs@252585b))
* narrow type for `add` and `subtract` ([#1576](iamkun/dayjs#1576)) ([1686962](iamkun/dayjs@1686962))
* update customParseFormat plugin strict x X parsing ([#1571](iamkun/dayjs#1571)) ([08adda5](iamkun/dayjs@08adda5))
* update Lithuanian [lt] locale spelling for single month ([#1609](iamkun/dayjs#1609)) ([255dc54](iamkun/dayjs@255dc54))
* Update Norwegian Bokmål [nb] local yearStart 4 ([#1608](iamkun/dayjs#1608)) ([7a8467c](iamkun/dayjs@7a8467c))
* update plugin advancedFormat `isValid` validation ([#1566](iamkun/dayjs#1566)) ([755fc8b](iamkun/dayjs@755fc8b))
* update Sinhalese [si] locale month name ([#1475](iamkun/dayjs#1475)) ([63de2a8](iamkun/dayjs@63de2a8))
* update utcOffset plugin type file ([#1604](iamkun/dayjs#1604)) ([f68e4b1](iamkun/dayjs@f68e4b1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not all unit in OpUnitType is legal unit for add and subtract
3 participants