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

Incorrect calendar time localization for Vietnamese #6091

Open
tduyduc opened this issue Jan 24, 2023 · 0 comments
Open

Incorrect calendar time localization for Vietnamese #6091

tduyduc opened this issue Jan 24, 2023 · 0 comments

Comments

@tduyduc
Copy link

tduyduc commented Jan 24, 2023

Describe the bug

Calendar time localization for Vietnamese is incorrect.

  • moment().locale('vi').subtract(2, 'days').calendar(); always adds "tuần trước" (previous week) to the result string even if the day before yesterday is in the same week as today; that is, any previous day (that displays the day of week) would always appear to be from the last week.
  • moment().locale('vi').add(2, 'days').calendar(); always adds "tuần tới" (next week) to the result string even if the day before yesterday is in the same week as today; that is, any following day (that displays the day of week) would always appear to be from the next week.

To Reproduce

Invoke a calendar time method to a day within the same week but not yesterday or tomorrow, using Vietnamese locale.

A current time-agnostic way to reproduce is to open a Node.js REPL session or to go to https://momentjs.com/ and then start typing.

This output is copied from a Node.js REPL session.

Welcome to Node.js v16.18.1.
Type ".help" for more information.
> var moment = require('moment');
undefined
> moment('2023-01-23').locale('vi').calendar('2023-01-25');
'thứ hai tuần trước lúc 00:00'
> moment('2023-01-27').locale('vi').calendar('2023-01-25');
'thứ sáu tuần tới lúc 00:00'
> moment('2023-01-23').locale('ja').calendar('2023-01-25');
'月曜日 00:00'
> moment('2023-01-27').locale('ja').calendar('2023-01-25');
'金曜日 00:00'
> moment('2023-01-20').locale('ja').calendar('2023-01-25');
'先週金曜日 00:00'
> moment('2023-01-31').locale('ja').calendar('2023-01-25');
'来週火曜日 00:00'

Expected behavior

If the date to show calendar time is within the same week as the reference date, "tuần trước" (previous week) or "tuần tới" (next week) must not be added. For example:

moment('2023-01-20').locale('vi').calendar('2023-01-25') // --> 'thứ sáu tuần trước lúc 00:00'
moment('2023-01-23').locale('vi').calendar('2023-01-25') // --> 'thứ hai lúc 00:00'
moment('2023-01-27').locale('vi').calendar('2023-01-25') // --> 'thứ sáu lúc 00:00'
moment('2023-01-31').locale('vi').calendar('2023-01-25') // --> 'thứ ba tuần tới lúc 00:00'

Moment-specific environment

  • Node.js 16.18.1 (I believe this should be reproducible on any supported Node version)
  • The issue is independent on local time and time zone

Additional context

The Japanese locale is a good reference for fixing the issue. From the REPL output above, "先週" (previous week) and "来週" (next week) are not shown when the date is within the same week as the reference date.

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

1 participant