Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
πŸ› fix date with seconds (#753)
Browse files Browse the repository at this point in the history
closes #8603

- see TryGhost/Ghost#8603 (comment)
- see comment in code base
  • Loading branch information
kirrg001 authored and aileen committed Jun 20, 2017
1 parent 2a73c79 commit 68ffa29
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
});

0 comments on commit 68ffa29

Please sign in to comment.