-
Notifications
You must be signed in to change notification settings - Fork 249
Yaml Frontmatter Date off by 1 day #944
Comments
Live example links won't work. I fixed this in userland: https://github.com/serverless/site/commit/0a9bc4045b63997f7fef17ae4e96b53d414f344b but still think this might be a core issue |
How can it be a core issue? Date are strings, so it's impossible Phenomic can be responsible of this.
I get a correct number. I don't have this issue on others projects that use the same technique. Even the default theme is not affected.
One thing that can be is maybe the machine building the site? |
I had this issue before, this is becuase of the different in timezone between the building machine, dev machine and user machine. I ended up not printing pretty day format |
That could be it. Not sure where netlify build takes place. Is there a way to set timezone in NODE.ENV or something? =) |
Anyway, client side should update this correctly, it can only be incorrect for static build. So if your JS is on, you should not get this bug. |
It's a JavaScript thing. I encountered it too with my event calendar and had to do something weird based on the suggestions here:
|
Yeah this is why I suggested fixing it in core.
Users will encounter this over and over.
The YAML date should be converted to YYYY/MM/DD (slashes with no T0000000) like Brian mentions.
… On Jan 19, 2017, at 2:05 AM, Brian Cruikshank ***@***.***> wrote:
It's a JavaScript thing. I encountered it too with my event calendar and had to do something weird based on the suggestions here:
http://stackoverflow.com/questions/7556591/javascript-date-object-always-one-day-off
const pageDate = head.date ? new Date(head.date.replace(/-/g, '\/').replace(/T.+/, '')) : null
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@DavidWells youre suggesting we fix the language. Lol. |
Maybe we should fix this via #397? |
Otherwise we can assume it's a userland thing and recommend a given format in the doc. |
Nah just auto format to the slashes and get rid of the ISO time stamp The date should render correctly regardless of where the build happens. If I give a markdown file a time stamp, I'd expect it to render the correct date out for me. Yes it's a JS and ISO issue but it can be easily fixed by making head.date return yyyy/mm/dd instead of the dashes |
I think the problem is that "YYYY-MM-DD" is probably considered as GMT00:00 by JS. So it will depend on your browser TZ. Pretty sure yyyy/mm/dd is considered as a local (non iso) date and is not likely going to be rendered the same depending on your TZ. We should try that on. What gives this for you?
Cause for me I see a one day diff! So this don't work for me :( (I am GMT+1) |
This is harder than I thought. https://nulogy.com/who-we-are/company-blog/articles/dealing-with-timezones-in-javascript/ Javascript is fucked up. Let's rewrite phenomic in Go ¯_(ツ)_/¯ How do we get |
I think UTC times might also address this issue |
@DavidWells dealing with date and time is fucking hard with Javascript, especially when it comes to server-side rendering. The output string would be different between the static HTML and client-rendered one. I have no solution for this really. :/ |
|
The problem with |
moment.js is a fat library. A quick search shows me this https://github.com/taylorhakes/fecha . 2KB |
There is another alternative: https://date-fns.org/ |
What about globalize.js date module? It and moment.js are what react-big-calendar supports. Not that that means anything, just giving another option. :) Also supports relative time. |
Simple problem, simple solution
const sortOfDate = "YYYY.MM.DD"
function dateify(date) {
// if we have a valid date
if (date.length === sortOfDate.length && !isNaN(Date.parse(date))) {
// we try to adjust depending on the format
switch (date[4]) {
case "/": return new Date(date + " 00:00:00 +00:00")
case "-": return new Date(date + "T00:00:00+00:00")
}
}
return new Date(date)
}
Do you want a very tiny util available somewhere? |
Add this to phenomic utils perhaps? |
See #999 |
Closing as the solution should be enough. |
Oups not released yet. |
user land solution. |
Just noticed this on the serverless.com blog. Looks like the date from
head
data is shifting the date one day backwards.This frontmatter:
In the Post layout
head.date
===2016-12-15T00:00:00.000Z
When converting this to date
new Date(head.date)
it gives backWed Dec 14 2016 16:00:00 GMT-0800 (PST)
which is a day offIs anyone else seeing this behavior?
This is the code printing out our date: https://github.com/serverless/site/blob/a1659dafc8ceffd3e5df5b14086eb63cffb90635/src/layouts/Post/index.js#L37-L46
I can fix this on my end with some math but it seems like a bug that might be effecting others.
This will shift the date to the correct
2016-12-15
dateHere is another example: https://serverless.com/blog/a-serverless-windclock-at-the-lake/ and the markdown https://github.com/serverless/blog/blob/master/posts/2017-01-17-a-serverless-windclock-at-the-lake.md (the date should be 2017-01-17 but it's not =P)
The text was updated successfully, but these errors were encountered: