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

Dayjs returns next year instead of passed one when trying to parse date #1656

Open
sirpravdi opened this issue Oct 4, 2021 · 4 comments
Open

Comments

@sirpravdi
Copy link

Describe the bug

I'm trying to parse some date strings in russian locale, but dayjs returns dates with passed year + 1, e.g. 2020 instead of 2019

import dayjs from 'dayjs';
import 'dayjs/locale/ru';
import customParseFormat from 'dayjs/plugin/customParseFormat';

dayjs.locale('ru');   
dayjs.extend(customParseFormat);

dayjs('11 декабря 2019', 'DD MMMM YYYY', 'ru').format('DD MMMM YYYY');
dayjs('11 декабря 2018', 'DD MMMM YYYY', 'ru').format('DD MMMM YYYY');      
dayjs('11 декабря 2017', 'DD MMMM YYYY', 'ru').format('DD MMMM YYYY');

Expected behavior
Dayjs returns date with correct year

Information

  • Day.js Version - 1.10.7
  • OS: Windows 10
  • Browser: Chrome 94.0.4606.61
  • Time zone: GMT+3 (Moscow)
@BePo65
Copy link
Contributor

BePo65 commented May 26, 2022

As I don't speak russian and have my problems with cyrillic characters, it is not so easy to find out, where this effect comes from.

But as I found out with the help of google translator, there are 2 words for 'december': декабря and декабрь.
In the locale file for russian (src/locale/ru.js) one is used for monthFormat and one for monthStandalone, whatever the reason might be :-)

Can you explain what these 2 'decembers' mean?

Using декабрь the date is parsed correctly.

@sirpravdi
Copy link
Author

sirpravdi commented May 26, 2022

Hi, thank you for your reply

I'll try to explain the difference between these two decembers

FIrst one - декабрь is just a name of a month, but if you want to talk about a specific date декабрь changes to декабря
So in russian it's correct to say 5 декабря, not 5 декабрь
Actually it happens to all the months names, январь -> января, февраль -> февраля, март -> марта, апрель -> апреля, май -> мая, июнь -> июня, июль -> июля, август -> августа, сентябрь -> сентября, октябрь -> октября, ноябрь -> ноября, декабрь -> декабря

Hope this explanation helps

@BePo65
Copy link
Contributor

BePo65 commented May 26, 2022

oh thank you; now I do understand he transformation of month names to the month number.

So we have a hidden error in the customParseFormat plugin - the implementation misinterpreted the modulo function.

I will prepare a PR and let's hope that it will be accepted soon.

BePo65 added a commit to BePo65/dayjs that referenced this issue May 26, 2022
This error gets visible in the russion month names (issue iamkun#1656).
Added test to test/locale/ru.test.js to show this error.
@KostblLb
Copy link

KostblLb commented Dec 7, 2022

this is still relevant on 1.11.3! @iamkun pls take a look at the PR

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

No branches or pull requests

3 participants