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

Date formatting to ISO string invalid (adding timezone computation) #79

Open
Arteneko opened this issue Sep 21, 2018 · 6 comments
Open

Comments

@Arteneko
Copy link

Arteneko commented Sep 21, 2018

Describe the bug
When you create a date from an iso8601 string, and when you try to "render" it, e.g. with date.toISOString() (source: lib/atom.1.js:67),
it computes it and works with the time-zone.

I'm in a case in which I want to have absolutely 0 change from the original timestamp, but the JS conversion removes 2 hours from the actual timestamp on render.

Wouldn't it be possible for "updated" to take an iso-formatted string, either validating it or trusting the developer to not fuck up the format ?

To Reproduce
Steps to reproduce the behavior:

Tested in UTC+2 time zone

new Date("2018/09/09")
// Returns Date 2018-09-08T22:00:00.000Z

Expected behavior

I'd expect it to return Date 2018-09-09T00:00:00.000Z

More informations

The obtained error is:

TypeError: Cannot read property 'toISOString' of undefined
index.js:36
    at /home/nyx/git/Blog/node_modules/feed/lib/atom1.js:67:34

Because, since I pass a correctly-formatted ISO string and not a Date instance, the validator doesn't take the value, so it evaluates to undefined.

@jpmonette
Copy link
Owner

@IvanDelsinne If you don't want to change the timezone of your environment, you can use Date.UTC with vanilla JavaScript:

new Date(Date.UTC(2018, 8, 9)).toISOString()
// "2018-09-09T00:00:00.000Z"

Does that solve your issue?

@Arteneko
Copy link
Author

Arteneko commented Sep 30, 2018

I'm gonna try to do that, I haven't managed to find this solution anywhere. Thanks for the tip.

Still, allowing to provide a custom date value wouldn't be a good idea ?

@jpmonette
Copy link
Owner

@IvanDelsinne Maybe I could allow string-based date, but existing behaviour is to avoid someone messing up the date format 🤔. How would you generate the ISO string otherwise?

@Arteneko
Copy link
Author

Arteneko commented Oct 3, 2018

I tried that, I'm still getting the timezone conversion, with the following code snippet:

let date = i.data.date.substring(0, 10).split('-').map(i => Number.parseInt(i));
date = new Date(Date.UTC(date[0], date[1], date[2]));

Here, i.data.date is "2018-09-14T00:00:00Z" and I get "2018-09-14T02:00:00Z".

Edit:

It's weird, if I print the data as debug, I get the timezone converted, but if I print theISOString, it doesn't convert.

@karllhughes
Copy link

I'm having this same issue, but only with the atom1() method. It seems to work fine with rss2().

@brycewray
Copy link

brycewray commented Apr 18, 2022

(Perhaps) similar issue with json1() — I get an ISO string but trying to use the date triggers the item.date.toISOString is not a function error. What's getting returned is, for example, 2022-04-06T14:55:00.000Z.

Disregard. Figured it out. My apologies. Thanks for feed!

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

4 participants