Skip to content

Commit

Permalink
UIDEXP-175: Fix date and time display in Safary (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
YevheniiMaltsev authored Oct 12, 2020
1 parent 82bd57c commit f59821e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Add `OverlayView` component and extend JobLogs API. UIDEXP-18.
* Extend `SortAndSearchPane` to accept `excludedSortColumns` and `shouldSetInitialSortOnMount` prop. UIDEXP-142.
* Update `react-intl` to v5.7.0. STDTC-15.
* Fix date and time display in Safari. UIDEXP-175.

## [2.0.1](https://github.com/folio-org/stripes-data-transfer-components/tree/v2.0.1) (2020-07-09)
[Full Changelog](https://github.com/folio-org/stripes-data-transfer-components/tree/v2.0.0...v2.0.1)
Expand Down
10 changes: 5 additions & 5 deletions lib/JobLogs/useJobLogsListFormatter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useIntl } from 'react-intl';
import { useListFormatter } from '../ListFormatter';
import { useTimeFormatter } from '../utils';

const runBy = record => {
if (!record.runBy) {
Expand Down Expand Up @@ -32,11 +32,11 @@ const totalRecords = record => {
const fileName = record => record.fileName;
const hrId = record => record.hrId;

const getCompletedDateFormatter = intl => {
const getCompletedDateFormatter = formatTime => {
return record => {
const { completedDate } = record;

return intl.formatTime(
return formatTime(
completedDate,
{
day: 'numeric',
Expand All @@ -48,15 +48,15 @@ const getCompletedDateFormatter = intl => {
};

export const useJobLogsListFormatter = (customFormatters = {}) => {
const intl = useIntl();
const formatTime = useTimeFormatter();

const jobLogsFormatters = {
runBy,
jobProfileName,
totalRecords,
fileName,
hrId,
completedDate: getCompletedDateFormatter(intl),
completedDate: getCompletedDateFormatter(formatTime),
};

return useListFormatter({
Expand Down
6 changes: 3 additions & 3 deletions lib/ListFormatter/useListFormatter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useIntl } from 'react-intl';
import { useDateFormatter } from '../utils';

export const useListFormatter = (customFormatters = {}) => {
const intl = useIntl();
const formatDate = useDateFormatter();

return {
name: record => record.name,
updated: record => {
const { metadata: { updatedDate } } = record;

return intl.formatDate(updatedDate);
return formatDate(updatedDate);
},
updatedBy: record => {
if (!record.userInfo) {
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export * from './constants';
export * from './folioRecordTypes';
export * from './useFormattedMCLProps';
export * from './formatTranslationChunks';
export * from './useTimeFormatter';
export * from './useDateFormatter';
18 changes: 18 additions & 0 deletions lib/utils/iso8601Timestamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
This is temp solution because stripes-components was released.
TODO: Update solution during the next release: Move useDateFormatter
and useTimeFormatter to stripes-components and remove them here.
*/
export const iso8601Timestamp = value => {
let tweakedValue = value;

if (typeof value !== 'string') {
return tweakedValue;
}

if (value.length === 28 && (value[23] === '+' || value[23] === '-')) {
tweakedValue = `${value.substring(0, 26)}:${value.substring(26, 28)}`;
}

return tweakedValue;
};
9 changes: 9 additions & 0 deletions lib/utils/useDateFormatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useIntl } from 'react-intl';

import { iso8601Timestamp } from './iso8601Timestamp';

export const useDateFormatter = () => {
const intl = useIntl();

return date => intl.formatDate(iso8601Timestamp(date));
};
9 changes: 9 additions & 0 deletions lib/utils/useTimeFormatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useIntl } from 'react-intl';

import { iso8601Timestamp } from './iso8601Timestamp';

export const useTimeFormatter = () => {
const intl = useIntl();

return (time, options) => intl.formatTime(iso8601Timestamp(time), options);
};

0 comments on commit f59821e

Please sign in to comment.