From 69b82b9207ef7d893eae6bc34bd48a3e9c09a9c3 Mon Sep 17 00:00:00 2001 From: Katharina Irrgang Date: Tue, 20 Jun 2017 10:12:57 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20fix=20date=20with=20seconds?= =?UTF-8?q?=20(#753)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #8603 - see https://github.com/TryGhost/Ghost/issues/8603#issuecomment-309538395 - see comment in code base --- ghost/admin/app/models/post.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ghost/admin/app/models/post.js b/ghost/admin/app/models/post.js index 57f9e9bd0e..a074976158 100644 --- a/ghost/admin/app/models/post.js +++ b/ghost/admin/app/models/post.js @@ -179,6 +179,24 @@ export default Model.extend(Comparable, ValidationEngine, { if (publishedAtBlogDate && publishedAtBlogTime) { let publishedAtBlog = moment.tz(`${publishedAtBlogDate} ${publishedAtBlogTime}`, blogTimezone); + + /** + * Note: + * If you create a post and publish it, we send seconds to the database. + * If you edit the post afterwards, ember would send the date without seconds, because + * the `publishedAtUTC` is based on `publishedAtBlogTime`, which is only in seconds. + * The date time picker doesn't use seconds. + * + * This condition prevents the case: + * - you edit a post, but you don't change the published_at time + * - we keep the original date with seconds + * + * See https://github.com/TryGhost/Ghost/issues/8603#issuecomment-309538395. + */ + if (publishedAtBlog.diff(publishedAtUTC.clone().startOf('minutes')) === 0) { + return publishedAtUTC; + } + return publishedAtBlog; } else { return moment.tz(this.get('publishedAtUTC'), blogTimezone); @@ -272,7 +290,6 @@ export default Model.extend(Comparable, ValidationEngine, { beforeSave() { let publishedAtBlogTZ = this.get('publishedAtBlogTZ'); let publishedAtUTC = publishedAtBlogTZ ? publishedAtBlogTZ.utc() : null; - this.set('publishedAtUTC', publishedAtUTC); } });