You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/03/12 23:09:26 UTC

[GitHub] [incubator-superset] kristw commented on issue #7020: Changing time table viz to pass formatTime a date

kristw commented on issue #7020: Changing time table viz to pass formatTime a date
URL: https://github.com/apache/incubator-superset/pull/7020#issuecomment-472215650
 
 
   There is a small catch that if you parse it with `new Date(string)` it will be parsing 
   * as UTC time for `YYYY-MM-DD`
   * as local time otherwise.
   
   and we normally format in UTC time by default
   
   From MDN:
   
   > Note: parsing of date strings with the `Date` constructor (and `Date.parse`, they are equivalent) is strongly discouraged due to browser differences and inconsistencies. Support for RFC 2822 format strings is by convention only. Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local.
   
   ![image](https://user-images.githubusercontent.com/1659771/54241864-a77e9f80-44df-11e9-8000-16824e7fd24f.png)
   
   ```js
   const { utcParse } = require('d3-time-format');
   const parseFn = utcParse('%Y-%m-%d');
   
   function parseDate(x) { 
     if (x instanceof Date) {
       return x;
     }
     if (typeof x === 'number') {
      // if it is timestamp, it is safe to use the native Date
       return new Date(x);
     }
     return parseFn(x);
   }
   
   ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org