spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.97k stars 184 forks source link

toNativeDate does not factor in timezone offset #391

Closed copleykj closed 1 year ago

copleykj commented 1 year ago

calling the toNativeDate() method returns a date equal to the date when initialized.

The correct functionality is housed within the spacetimeInstance.d getter but it is marked as deprecated and specifies to use the toNativeDate()

spencermountain commented 1 year ago

hey Kelly, yep the js Date object will be in your local timezone, without the offset applied. If you want a js date with the offset applied, i'd do let d = new Date(s.epoch)

i know this is a mess, receptive to ideas to improve either the docs or API cheers

copleykj commented 1 year ago
let d = new Date(s.epoch)

This is exactly what .toNativeDate() does and the date returned is the same as the original starting date.

spencermountain commented 1 year ago

oh right - maybe this could work then

let d = new Date(s.iso())

cheers