Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid date handling #89

Open
cfal opened this issue Apr 1, 2016 · 0 comments
Open

Invalid date handling #89

cfal opened this issue Apr 1, 2016 · 0 comments

Comments

@cfal
Copy link

cfal commented Apr 1, 2016

There doesn't seem to be a way to override the default Date object, while setting the timezone without breaking handling of invalid dates.

The default Date object returns "Invalid Date" for new Date(NaN). Babel's ES6 transpiler does the test (new Date(NaN) + '') == 'Invalid Date', which fails with node-time's extended Date.

> new time.Date(NaN) + ''
TypeError: Cannot read property 'substring' of undefined
    at Date.toDateString (/Users/user/node_modules/time/index.js:471:39)
    at Date.toString (/Users/user/node_modules/time/index.js:484:17)
    at repl:1:20
    at REPLServer.defaultEval (repl.js:252:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:417:12)

(new time.Date(NaN)).toString() gives the same error.

This seems to work when extending the default Date object, but then it breaks setting the timezone using time.tzset:

> var time = require('time')
> new Date()
Thu Mar 31 2016 21:54:15 GMT-0700 (PDT)
> time.tzset('America/New_York')
{ tzname: [ 'EST', 'EDT' ], timezone: 18000, daylight: 1 }
> time(Date)
> new Date()
Thu Mar 31 2016 21:54:36 GMT-0700 (EDT)
> new Date(NaN)
Invalid Date
@cfal cfal changed the title Invalid time handling Invalid date handling Apr 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant