Skip to content

Commit

Permalink
Don't create real Date objects when getting just date from an ISO dat…
Browse files Browse the repository at this point in the history
…e-time, as it will cause the timezone to affect the results.
  • Loading branch information
Dan Searle committed Nov 6, 2018
1 parent b8e9124 commit 1dda585
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions components/x-timeline-feed/src/lib/transform.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {
formatToDateOnly,
getLocalisedISODate,
getTitleForArticleDateGroup,
splitLatestEarlier
} from './date';

export const getDateOnly = date => date.substr(0, 10);

export const groupArticlesByLocalisedDate = (articles, timezoneOffset) => {
const articlesByLocalisedDate = {};

articles.forEach((article, index) => {
const localDateTime = getLocalisedISODate(article.publishedDate, timezoneOffset);
const localDate = formatToDateOnly(localDateTime);
const localDate = getDateOnly(localDateTime);

if (!articlesByLocalisedDate.hasOwnProperty(localDate)) {
articlesByLocalisedDate[localDate] = [];
Expand All @@ -28,7 +29,7 @@ export const groupArticlesByLocalisedDate = (articles, timezoneOffset) => {

export const splitTodaysArticles = (articleGroups, localTodayDate, latestArticlesTime) => {
const firstGroupIsToday = articleGroups[0].date === localTodayDate;
const latestTimeIsToday = formatToDateOnly(latestArticlesTime) === localTodayDate;
const latestTimeIsToday = getDateOnly(latestArticlesTime) === localTodayDate;

if (!firstGroupIsToday || !latestTimeIsToday) {
return articleGroups;
Expand Down Expand Up @@ -64,7 +65,7 @@ export const getArticleGroups = props => {
const {
articles,
timezoneOffset = now.getTimezoneOffset(),
localTodayDate = formatToDateOnly(now),
localTodayDate = getDateOnly(now.toISOString()),
latestArticlesTime
} = props;

Expand Down

0 comments on commit 1dda585

Please sign in to comment.