Skip to content

Commit

Permalink
Merge pull request #1619 from ral-facilities/feature/simpler-icat-tim…
Browse files Browse the repository at this point in the history
…estamps

simpler icat timestamps
  • Loading branch information
kaperoo authored Feb 6, 2024
2 parents fe23ff5 + 3bc9a31 commit 3b59bb8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ yarn-error.log*
**/public/*settings*.json
!**/public/*settings.example.json

.vscode/
16 changes: 16 additions & 0 deletions packages/datagateway-common/src/card/cardView.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ const CardView = (props: CardViewProps): React.ReactElement => {
sort,
} = props;

// Format dates to be more readable
// Format only if the date has a time component
// (to avoid formatting dates like 2020-01-01)
React.useEffect(() => {
data.forEach((entity) => {
['createTime', 'modTime', 'startDate', 'endDate'].forEach((key) => {
if (entity[key] && /\d{2}:\d{2}:\d{2}/.test(entity[key])) {
entity[key] = new Date(entity[key])
.toISOString()
.replace('T', ' ')
.split(/[.+]/)[0];
}
});
});
}, [data]);

const [shiftDown, setShiftDown] = React.useState(false);
// add event listener to listen for shift key being pressed
React.useEffect(() => {
Expand Down
16 changes: 16 additions & 0 deletions packages/datagateway-common/src/table/table.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ const VirtualizedTable = React.memo(
disableSelectAll,
} = props;

// Format dates to be more readable
// Format only if the date has a time component
// (to avoid formatting dates like 2020-01-01)
React.useEffect(() => {
data.forEach((entity) => {
['createTime', 'modTime', 'startDate', 'endDate'].forEach((key) => {
if (entity[key] && /\d{2}:\d{2}:\d{2}/.test(entity[key])) {
entity[key] = new Date(entity[key])
.toISOString()
.replace('T', ' ')
.split(/[.+]/)[0];
}
});
});
}, [data]);

const [shiftDown, setShiftDown] = React.useState(false);
// add event listener to listen for shift key being pressed
React.useEffect(() => {
Expand Down

0 comments on commit 3b59bb8

Please sign in to comment.