javascript - new Date(epoch) returning invalid date inside Ember component -


i have date-filter component using in ember application works on initial render, not on page reload, or if save file (which triggers application live update).

in main template of application, render date-filter passing unix timestamp

{{date-filter unixepoch=item.date}} 

then, in components/date-filter.js, use computed property called timeconverter change unix epoch time string formatted according user's language of choice, , in templates/components/date-filter.hbs file {{timeconverter}} display results

timeconverter: function(){     //step 1: epoch passed in component     var epoch = this.get('unixepoch');     //step 2: create human readable date string such `jun 29, 2015, 12:36pm`     var datestring = new date(epoch)      //do language formatting --code omitted problem step2  } 

it step 2 fails (returning invalid date) if refresh page or save file. returns proper date string first time component called. if new date(epoch) in parent component, , try pass result in component (to foreign language formatting), i'm having same problem.

question: how can figure out what's happening inside new date(epoch), or whether it's issue related component?

i suspect epoch value string (of digits). if so, then

var datestring = new date(+epoch); // note ------------------^ 

...will fix it. note javascript uses newer "milliseconds since epoch" rather older (original) "seconds since epoch." if doing starts giving dates, they're further in time expecting, might want epoch * 1000.

if it's string isn't digits, it's not epoch value @ all. only string value specification requires new date understand 1 added in ecmascript5 , fixed in ecmascript6 (regarding when there's no timezone indicator).


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -