It's intriguing to note that I'm facing the same issue as well. It appears to be a bug in the moment.js
library, where date conversion from different time zones is not working correctly. However, using do
instead seems to resolve the issue temporarily. Perhaps we should consider using do
until we can report and address this problem on GitHub.
Furthermore, it's worth mentioning that do
is equivalent to d
, which is specified in the documentation. Both options return the same day value, but one as a number
and the other as a string
.
After conducting more tests, I've noticed that the issue starts occurring in IST after 18:30. The exact cause remains unclear to me, but it could potentially be linked to the application of timezone adjustments to real-time values, leading to errors. For instance, while in IST, 00:00 - 5:30
corresponds to the problematic timeframe when the error occurs.
To address this, the updated code snippet should look like this:
var myTime1 = moment.tz('30 3 14:59', 'w d HH:mm', 'America/Los_Angeles');
console.log(myTime1.format());
var myTime = moment.tz('30 3rd 14:59', 'w do HH:mm', 'America/Los_Angeles');
console.log(myTime.format());
// In IST, the issue arises from 18:30 onwards
var myTime1 = moment.tz('30 3 19:30', 'w d HH:mm', 'America/Los_Angeles');
console.log(myTime1.format());
var myTime1 = moment.tz('30 3rd 19:30', 'w do HH:mm', 'America/Los_Angeles');
console.log(myTime1.format());
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.21/moment-timezone-with-data-2012-2022.min.js"></script>