question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add & use a global blog timezone

See original GitHub issue

It’s time 🕙 for us to finally add proper timezone support to Ghost. The original main issue for this (with a great deal of discussion) is here: https://github.com/TryGhost/Ghost/issues/1265.

Other related issues which may or may not be helpful:

  • Add timezone dropdown to settings #2360
  • Determine the best list of time zones for use in Ghost #2359
  • An ancient PR #2387

The timezone problem:

The problem we face with timezones revolves almost entirely around published dates.

Take the following scenario:

  • A user in UTC-8 (San Fran) opens their post settings menu, and sets the published at date to be 8pm on Dec 31st 2015.
  • Ghost correctly stores that as 4am Jan 1st 2016 UTC.
  • The blog is set to use Casper, which doesn’t have localisation in the theme.
  • They share their post straight away and all the readers see it marked as published in the future!

This gets more confusing when post scheduling comes into play. Take the example of a San Fran startup blog. They like to publish posts at lunchtime for their readership which is mostly also in San Fran. They hire a writer in Singapore, who is in UTC+8.

  • The writer creates their post, and sets the published at date to be 12:30pm (lunchtime) on Feb 1st 2016 (a date that is in the future).
  • Ghost correctly stores that as 4:30am Feb 1st 2016 UTC.
  • The scheduler will publish the post at 4:30am Feb 1st 2016 UTC which lunchtime in Singapore, but for the San Fran readership, that’s 8:30pm on the previous day.
  • Meanwhile the post itself will output on the frontend saying it was posted at 4:30am.

There are two underlying problems here:

  1. There’s no way to tell Ghost what timezone to use when outputting a date in your theme (other than using localisation in the theme), or anywhere else that a date might be output.

  2. When you set a date in the PSM, there’s no way to know whether that’s using your timezone, the server’s timezone, or the blog’s timezone (which doesn’t exist yet). It actually uses your own timezone, but then stores UTC, which makes things work sort of correctly, but is confusing.

We’re going to solve this the same way that Twitter, Tumblr, WP, Slack etc all do. Add a setting to the general settings, and use this to output all dates everywhere, including when setting the published at date.

The Timezone Setting

The timezone setting itself will take the form of a dropdown list, exactly the same as you see in Tumblr or Slack.

Tumblr:

  • The setting should exist under general settings in the Ghost admin
  • This setting should be a dropdown list
  • The format should be (UTC<offset>) List, Of, Cities just like Tumblr
  • The list should contain exactly the same entries as Tumblr
  • The default should be GMT London (the closest real TZ to UTC and the middle of the list)
  • The text under the dropdown should read “The local time here is currently HH:mm am/pm” - the time should reflect the TZ selected, and should ideally tick over each minute (like on Buffer)

The Post Settings Menu

In the post settings menu, the date picker needs to be updated to use the new global blog timezone instead of the user’s timezone.

That means, if I’m in UTC+2, and I login to my blog which is set to GMT, when I create a new draft the PSM should show me the time in GMT, not in UTC+2. Equally if I set a post to publish at 2pm, this should be 2pm GMT not 2pm UTC+2 i.e.12pm GMT.

The Date Helper

There are actually 2 date helpers in Ghost:

  • /core/server/helpers/date.js -> used in themes
  • /core/client/app/helpers/gh-format-timeago.js -> used in the admin panel

Both of the Date helpers need to be updated to take the timezone into account. As a result, the date output should always be correct according to the blog’s timezone.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
nuclearpengycommented, Jan 27, 2016

this is going to be rad.

1reaction
acburdinecommented, Mar 22, 2016

@aileen that sounds good to me, but I’ll defer to @erisds 's judgement before merging the PR 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add & use a global blog timezone · Issue #6406
Take the following scenario: A user in UTC-8 (San Fran) opens their post settings menu, and sets the published at date to be...
Read more >
javascript - Set global time zone
You can set the default timezone in Moment by using: moment.tz.setDefault(String);. For example. moment.tz.setDefault("America/New_York");.
Read more >
Set Your Blog's Timezone by City
Log in to your dashboard, click on Settings > General, and scroll to Timezone. You now have the option to pick a city...
Read more >
How to handle Time Zones in JavaScript | by Ravidu Perera
This article will discuss the concepts relevant to time zones and the methods to handle them using JavaScript. Time Zones GMT, Offset, UTC....
Read more >
How to Handle Time Zones using DateTime and Luxon
The best option for this is using a representation that meets the ISO 8601 standard. As an example of this, we can set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found