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

Frontmatter dates a day off? #25

Open
reallymello opened this issue Jan 15, 2020 · 1 comment
Open

Frontmatter dates a day off? #25

reallymello opened this issue Jan 15, 2020 · 1 comment

Comments

@reallymello
Copy link
Collaborator

reallymello commented Jan 15, 2020

In my post if I have a frontmatter like

---
title: Chronoblog is amazing
cover: ./chrono.png
date: 2020-01-14
description: Dates are a day behind
tags: ['post']
---

The date will show as January 13th instead of the 14th. Is this expected behavior or an off by 1 or internationalization defect?

@ganevdev
Copy link
Member

To show the date, chronoblog uses this component:

https://github.com/Chronoblog/gatsby-theme-chronoblog/blob/master/packages/gatsby-theme-chronoblog/src/components/date.js

It is very simple and uses the usual javascript tools.

I think the problem is in time zones. In general, of course, we must make sure that the specified date is displayed - since we are making a static string from the date.

Here is a function from a component that can be run in isolation (in nodejs for example), I added a time zone option to it:

const makeDate = (
  date,
  language = 'en',
  options = {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    //timeZone: 'America/New_York',
    timeZone: 'Asia/Shanghai',
  }
) => {
  if (!date) return undefined;
  const newDate = new Date(date);
  const dateString = newDate.toLocaleString(language, options);
  return dateString;
};

console.log(makeDate(new Date('2020-01-15')));

With different time zones, it gives different dates (if today's date is indicated).

@lucasrla lucasrla mentioned this issue Aug 14, 2020
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

2 participants