sanx / metalsmith-date-in-filename

11 stars 6 forks source link

Date function returning 8 hours in the past (previous day) #2

Open micahgodbolt opened 8 years ago

micahgodbolt commented 8 years ago

new Date(2015-12-17) returns

 Wed Dec 16 2015 16:00:00 GMT-0800 (PST)

I had to specify process.env.TZ = 'Pacific'; to get the output to actually be the 17th.

I know this isn't really a "bug" in the module, but can the module be enhanced to detect timezone if it is not set?

micahgodbolt commented 8 years ago

Thinking about it more, it looks like Date(2015-12-17) assumes that we're talking December 17h, 00:00 UTC, and it is returning the local time.

So how can we change the function to use local time for input and output, or to add on the offset to the date before returning a value.

ninjasort commented 8 years ago

I had the same issue, did this ever get addressed? @micahgodbolt There's also metalsmith-jekyll-dates that seems to be working pretty well for me.

micahgodbolt commented 8 years ago

@cameronjroe i had to specify my timezone in order to get it to work

https://github.com/micahgodbolt/micahcodes/blob/master/metalsmith.js#L18

process.env.TZ = 'Pacific';
ninjasort commented 8 years ago

Ah, I see your comment. Okay, can one just specify that in the metadata? Maybe it should documented?