moment icon indicating copy to clipboard operation
moment copied to clipboard

Incorrect calendar time localization for Vietnamese

Open tduyduc opened this issue 2 years ago • 0 comments

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.

tduyduc avatar Jan 24 '23 12:01 tduyduc