0

I have referred similar questions too, but nothing seems helpful to me. (Angular Moment : Moment Timezone has no data for America/New_York)

a simple jsfiddle

document.getElementById("output").innerText = moment.tz("IST"); //throws error
document.getElementById("output1").innerText = moment.tz("Asia/Kolkata"); 
document.getElementById("output2").innerText = moment.tz.names().includes("IST") // returns false
document.getElementById("output3").innerText = moment.tz.names().includes("Asia/Kolkata")

enter image description here

https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.31/moment-timezone-with-data.js has data for IST, but why the moment is throwing error when IST is used? Do i need to manually add IST to timezone? Also, moment.tz.names() doesn't have IST in it, is that the reason for the error?

James Z
  • 12,209
  • 10
  • 24
  • 44
Raj Kumari
  • 57
  • 1
  • 5
  • 1
    You clearly expect IST to have a standard interpretation. It doesn't. There is no canonical list of timezone abbreviations, and in Ireland and Israel IST means something quite different from what you may be expecting. – BoarGules Jul 06 '21 at 06:23

1 Answers1

0

It's perhaps not particularly helpful to suggest switching packages entirely, but there is a useful alternative to Moment named Day.js which has support for IST timezone (I have verified this myself).

As an added bonus, it has a much smaller package size than Moment and comes with pretty much all of the functionality of Moment with an almost-identical syntax as Moment.