Skip to content

Commit 795bb29

Browse files
committed
elements: add relative time util
1 parent c11dea2 commit 795bb29

File tree

8 files changed

+697
-598
lines changed

8 files changed

+697
-598
lines changed

package-lock.json

Lines changed: 675 additions & 597 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"react": "^16.13.0",
3333
"react-dom": "^16.13.0",
3434
"lodash": "^4.17.0",
35+
"luxon": "^1.23.0",
3536
"query-string": "^7.0.0",
3637
"semantic-ui-css": "^2.4.0",
3738
"semantic-ui-react": "^2.1.0",
@@ -61,6 +62,7 @@
6162
"formik": "^2.1.0",
6263
"json": "^9.0.0",
6364
"lodash": "^4.17.0",
65+
"luxon": "^1.23.0",
6466
"query-string": "^7.0.0",
6567
"react": "^16.13.0",
6668
"react-dom": "^16.13.0",

src/lib/api/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
// under the terms of the MIT License; see LICENSE file for more details.
66

77
export { http } from "./connector";
8+
export { withCancel } from "./withCancel";
File renamed without changes.

src/lib/elements/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
* This folder contains general purpose reusable components.
99
*/
1010
export { Image } from "./Image";
11-
export { withCancel } from "./withCancel";
1211
export { GridResponsiveSidebarColumn } from "./GridResponsiveSidebarColumn";

src/lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
export * from "./elements";
99
export * from "./forms";
1010
export * from "./api";
11+
export * from "./locale";

src/lib/locale/RelativeTime.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file is part of React-Invenio-Forms
2+
// Copyright (C) 2023 CERN.
3+
//
4+
// React-Invenio-Forms is free software; you can redistribute it and/or modify it
5+
// under the terms of the MIT License; see LICENSE file for more details.
6+
7+
import { DateTime } from "luxon";
8+
9+
/**
10+
* Make relative date for a given timestamp
11+
*
12+
* @param timestamp string ISO timestamp
13+
* @returns {string} relative date in a given language, f.e. 3 days ago
14+
*/
15+
export const toRelativeTime = (timestamp, language = "en") => {
16+
return DateTime.fromISO(timestamp).setLocale(language).toRelative();
17+
};

src/lib/locale/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { toRelativeTime } from "./RelativeTime";

0 commit comments

Comments
 (0)