Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt getting rid date-fns-tz in prod build #32

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyrene/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyrene/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"babel-plugin-typescript-to-proptypes": "^1.4.1",
"copy-webpack-plugin": "^6.2.0",
"css-loader": "^3.6.0",
"date-fns-tz": "^1.1.4",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.15.5",
"eslint": "^7.10.0",
Expand Down Expand Up @@ -98,7 +99,6 @@
"dependencies": {
"classnames": "^2.2.5",
"date-fns": "^2.16.1",
"date-fns-tz": "^1.1.4",
"prop-types": "^15.6.1",
"react-select": "^3.1.1",
"react-table": "^6.8.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import React from 'react';
import PropTypes from 'prop-types';

import { differenceInMinutes, getTime, format } from 'date-fns';
import { utcToZonedTime } from 'date-fns-tz';
import { differenceInMinutes } from 'date-fns';


import ArrowSelector from './ArrowSelector/ArrowSelector';

const convertTZ = (date, timeZone) => new Date((typeof date === 'string' ? new Date(date) : date).toLocaleString('en-US', { timeZone }));

// format date with such a pattern 'dd.MM.yyyy, HH:mm'
// eslint-disable-next-line prefer-template
const formatDate = (date) => ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear() + ', ' + ('0' + date.getHours()).slice(-2) + ':' + ('0' + date.getMinutes()).slice(-2);

const TimeRangeNavigationBar = (props) => {
// We should not check for milliseconds but minutes changes
const backInactive = differenceInMinutes(props.from, props.lowerBound) <= 0;
Expand All @@ -28,11 +33,13 @@ const TimeRangeNavigationBar = (props) => {
};

TimeRangeNavigationBar.renderCurrentTimeRange = (from, to, timezone) => {
const localFrom = getTime(utcToZonedTime(new Date(from), timezone));
const localTo = getTime(utcToZonedTime(new Date(to), timezone));
const pattern = 'dd.MM.yyyy, HH:mm';
const localFrom = convertTZ(new Date(from), timezone);
const localFromFormatted = formatDate(localFrom);

const localTo = convertTZ(new Date(to), timezone);
const localToFormatted = formatDate(localTo);

return `${format(localFrom, pattern)} - ${format(localTo, pattern)}`;
return `${localFromFormatted} - ${localToFormatted}`;
};

TimeRangeNavigationBar.defaultProps = {
Expand Down