From 0922ee21a775b5a30cb565a8156582a6ec75c130 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 17 Jan 2018 12:01:58 +0100 Subject: [PATCH] fixes first element in global activities logs[fixes SCI-1866] --- .../components/ActivityDateElement.jsx | 7 +++-- .../components/GlobalActivitiesModal.jsx | 28 +++++++++++-------- app/views/activities/_list.html.erb | 2 +- package.json | 1 + yarn.lock | 10 +++++++ 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/javascript/src/components/Navigation/components/ActivityDateElement.jsx b/app/javascript/src/components/Navigation/components/ActivityDateElement.jsx index 0dad1bf50..1ba29f0b7 100644 --- a/app/javascript/src/components/Navigation/components/ActivityDateElement.jsx +++ b/app/javascript/src/components/Navigation/components/ActivityDateElement.jsx @@ -1,7 +1,7 @@ // @flow import React from "react"; -import Moment from "react-moment"; +import moment from 'moment-timezone'; import { FormattedMessage } from "react-intl"; import styled from "styled-components"; @@ -23,11 +23,12 @@ const StyledSpan = styled.span` border-radius: 0.25em; `; -const ActivityDateElement = (props: { date: Date }) => { +const ActivityDateElement = (props: { date: Date, timezone: string }) => { + const massageDate = moment(props.date).tz(props.timezone).format("DD.MM.YYYY") const label = isToday(props.date) ? ( ) : ( - {props.date} + {massageDate} ); return ( diff --git a/app/javascript/src/components/Navigation/components/GlobalActivitiesModal.jsx b/app/javascript/src/components/Navigation/components/GlobalActivitiesModal.jsx index e5bd8cd4a..90c834123 100644 --- a/app/javascript/src/components/Navigation/components/GlobalActivitiesModal.jsx +++ b/app/javascript/src/components/Navigation/components/GlobalActivitiesModal.jsx @@ -6,6 +6,7 @@ import { FormattedMessage } from "react-intl"; import { Button, Modal } from "react-bootstrap"; import _ from "lodash"; import styled from "styled-components"; +import moment from "moment-timezone"; import { getActivities } from "../../../services/api/activities_api"; import ActivityElement from "./ActivityElement"; @@ -64,7 +65,11 @@ class GlobalActivitiesModal extends Component { date: Date ): Node { return [ - , + , ]; } @@ -99,22 +104,23 @@ class GlobalActivitiesModal extends Component { (activity: Activity, i: number, arr: Array<*>) => { const newDate = new Date(activity.createdAt); // returns a label with "today" if the date of the activity is today - if (i === 0 && newDate.toDateString() === new Date().toDateString()) { + if (i === 0) { return GlobalActivitiesModal.renderActivityDateElement( activity.id, activity, newDate ); } - // else checks if the previous activity is newer than current - // and displays a label with the date - const prevDate = - i !== 0 ? new Date(arr[i - 1].createdAt) : new Date(1901, 1, 1); - // filter only date from createdAt without minutes and seconds - // used to compare dates - const parsePrevDate = new Date(prevDate.toDateString()); - const parseNewDate = new Date(newDate.toDateString()); - if (parsePrevDate.getTime() > parseNewDate.getTime()) { + // check dates based on user timezone value + const parsePrevDate = moment(arr[i - 1].createdAt) + .tz(activity.timezone) + .format( "DD/MM/YYYY") + .valueOf('day'); + const parseNewDate = moment(activity.createdAt) + .tz(activity.timezone) + .format( "DD/MM/YYYY") + .valueOf(); + if (parsePrevDate > parseNewDate) { return GlobalActivitiesModal.renderActivityDateElement( activity.id, activity, diff --git a/app/views/activities/_list.html.erb b/app/views/activities/_list.html.erb index 5a660d354..2a8740869 100644 --- a/app/views/activities/_list.html.erb +++ b/app/views/activities/_list.html.erb @@ -8,7 +8,7 @@ <% else %>
  • - <%= activity-first.created_at.strftime('%d.%m.%Y') %> + <%= activities.first.created_at.strftime('%d.%m.%Y') %>
  • <% end %> diff --git a/package.json b/package.json index 586867b0f..f473318e0 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "js-yaml": "^3.9.0", "lodash": "^4.17.4", "moment": "^2.18.1", + "moment-timezone": "^0.5.14", "node-sass": "^4.5.3", "path-complete-extname": "^0.1.0", "postcss-loader": "^2.0.6", diff --git a/yarn.lock b/yarn.lock index b1e95f4ae..73334a95f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3946,6 +3946,16 @@ mkdirp@0.5, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp dependencies: minimist "0.0.8" +moment-timezone@^0.5.14: + version "0.5.14" + resolved "https://registry.yarnpkg.com/moment-timezone/-/moment-timezone-0.5.14.tgz#4eb38ff9538b80108ba467a458f3ed4268ccfcb1" + dependencies: + moment ">= 2.9.0" + +"moment@>= 2.9.0": + version "2.20.1" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.20.1.tgz#d6eb1a46cbcc14a2b2f9434112c1ff8907f313fd" + moment@^2.18.1: version "2.18.1" resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f"