Skip to content

Commit 7f34909

Browse files
authored
First Phase of Luxon migration (#2521)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent a42eef3 commit 7f34909

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

portal-ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"kbar": "^0.1.0-beta.39",
3030
"local-storage-fallback": "^4.1.1",
3131
"lodash": "^4.17.21",
32+
"luxon": "^3.1.1",
3233
"mds": "https://github.com/minio/mds.git#v0.0.8",
3334
"minio": "^7.0.32",
3435
"moment": "^2.29.4",
@@ -73,6 +74,7 @@
7374
},
7475
"proxy": "http://localhost:9090/",
7576
"devDependencies": {
77+
"@types/luxon": "^3.1.0",
7678
"@types/react-window": "^1.8.5",
7779
"@types/react-window-infinite-loader": "^1.0.6",
7880
"@types/recharts": "^1.8.24",

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjects.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { useLocation, useNavigate, useParams } from "react-router-dom";
2727
import { useDropzone } from "react-dropzone";
2828
import { Theme } from "@mui/material/styles";
2929
import { Button } from "mds";
30+
import { DateTime } from "luxon";
3031
import createStyles from "@mui/styles/createStyles";
3132
import Grid from "@mui/material/Grid";
3233
import get from "lodash/get";
@@ -750,6 +751,12 @@ const ListObjects = () => {
750751
dispatch(setDownloadRenameModal(null));
751752
};
752753

754+
let createdTime = DateTime.now();
755+
756+
if (bucketInfo?.creation_date) {
757+
createdTime = DateTime.fromISO(bucketInfo.creation_date);
758+
}
759+
753760
const multiActionButtons = [
754761
{
755762
action: () => {
@@ -867,9 +874,13 @@ const ListObjects = () => {
867874
<Fragment>
868875
<Grid item xs={12} className={classes.bucketDetails}>
869876
<span className={classes.detailsSpacer}>
870-
Created:&nbsp;&nbsp;&nbsp;
877+
Created on:&nbsp;&nbsp;
871878
<strong>
872-
{new Date(bucketInfo?.creation_date || "").toString()}
879+
{bucketInfo?.creation_date
880+
? createdTime.toFormat(
881+
"ccc, LLL dd yyyy HH:mm:ss (ZZZZ)"
882+
)
883+
: ""}
873884
</strong>
874885
</span>
875886
<span className={classes.detailsSpacer}>

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjectsHelpers.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import React from "react";
18-
import * as reactMoment from "react-moment";
17+
import { DateTime } from "luxon";
1918
import { BucketObjectItem } from "./types";
2019
import { niceBytes } from "../../../../../../common/utils";
2120
import { displayFileIconName } from "./utils";
@@ -26,11 +25,20 @@ export const displayParsedDate = (object: BucketObjectItem) => {
2625
if (object.name.endsWith("/")) {
2726
return "";
2827
}
29-
return (
30-
<reactMoment.default>
31-
{new Date(object.last_modified).toString()}
32-
</reactMoment.default>
33-
);
28+
29+
const currTime = DateTime.now();
30+
const objectTime = DateTime.fromISO(object.last_modified);
31+
32+
const isToday =
33+
currTime.hasSame(objectTime, "day") &&
34+
currTime.hasSame(objectTime, "month") &&
35+
currTime.hasSame(objectTime, "year");
36+
37+
if (isToday) {
38+
return `Today, ${objectTime.toFormat("HH:mm")}`;
39+
}
40+
41+
return objectTime.toFormat("ccc, LLL dd yyyy HH:mm (ZZZZ)");
3442
};
3543

3644
export const displayNiceBytes = (object: BucketObjectItem) => {

portal-ui/yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,6 +2367,11 @@
23672367
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.184.tgz#23f96cd2a21a28e106dc24d825d4aa966de7a9fe"
23682368
integrity sha512-RoZphVtHbxPZizt4IcILciSWiC6dcn+eZ8oX9IWEYfDMcocdd42f7NPI6fQj+6zI8y4E0L7gu2pcZKLGTRaV9Q==
23692369

2370+
"@types/luxon@^3.1.0":
2371+
version "3.1.0"
2372+
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.1.0.tgz#b9842d233a06b267fe4117f1c224f20b8a149825"
2373+
integrity sha512-gCd/HcCgjqSxfMrgtqxCgYk/22NBQfypwFUG7ZAyG/4pqs51WLTcUzVp1hqTbieDYeHS3WoVEh2Yv/2l+7B0Vg==
2374+
23702375
"@types/mime@*":
23712376
version "3.0.1"
23722377
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10"
@@ -8015,6 +8020,11 @@ lru-cache@^6.0.0:
80158020
dependencies:
80168021
yallist "^4.0.0"
80178022

8023+
luxon@^3.1.1:
8024+
version "3.1.1"
8025+
resolved "https://registry.yarnpkg.com/luxon/-/luxon-3.1.1.tgz#b492c645b2474fb86f3bd3283213846b99c32c1e"
8026+
integrity sha512-Ah6DloGmvseB/pX1cAmjbFvyU/pKuwQMQqz7d0yvuDlVYLTs2WeDHQMpC8tGjm1da+BriHROW/OEIT/KfYg6xw==
8027+
80188028
macos-release@^3.0.1:
80198029
version "3.1.0"
80208030
resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-3.1.0.tgz#6165bb0736ae567ed6649e36ce6a24d87cbb7aca"

0 commit comments

Comments
 (0)