Someone previously asked how to detect hemispheres and the accepted answer was this:
window.whatHemisphere= (function(){
var y= new Date().getFullYear();
if(y.getTimezoneOffset()==undefined) return null;
var jan= -(new Date(y, 0, 1, 0, 0, 0, 0).getTimezoneOffset()),
jul= -(new Date(y, 6, 1, 0, 0, 0, 0).getTimezoneOffset()),
diff= jan-jul;
if(diff> 0) return 'N';
if(diff< 0) return 'S'
return null;
})()
However, if I'm using Moment.js and Moment Timezone, is there a method that's more reliable than this using the tools provided by these libraries?
No, there's nothing built in to moment to give you a north/south hemisphere for a user.
Also, the function you showed is always going to return null
because getTimezoneOffset
is on Date
, but y
is just a number.
Even if you called it on a Date
, DST is not observed by all countries of the world. In fact, according to Wikipedia, DST is not observed in the majority of the world.
The only bit that makes sense is that if (and only if) a location observes DST, countries in the northern hemisphere will be in DST when July is in their summer, and countries in the southern hemisphere will be in DST when January is in their summer.