Skip to content

Commit

Permalink
using edtf parser library
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducica committed Mar 1, 2024
1 parent bac143c commit 18d986b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { useState, useEffect } from "react";
import { registerLocale } from "react-datepicker";
import { parse } from "edtf";
import _trim from "lodash/trim";

export const useInitialDateEdtfFormat = (fieldValue) => {
let dateEdtfFormat;
if (fieldValue) {
const value = fieldValue.includes("/")
? fieldValue.split("/")[0]
: fieldValue;
if (value.length === 4) {
if (parse(_trim(value)).values.length === 1) {
dateEdtfFormat = "yyyy";
} else if (value.length === 7) {
} else if (parse(_trim(value)).values.length === 2) {
dateEdtfFormat = "yyyy-mm";
} else {
dateEdtfFormat = "yyyy-mm-dd";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import _padStart from "lodash/padStart";
import { i18next } from "@translations/oarepo_ui/i18next";



export const edtfDateFormatOptions = [
{ value: "yyyy", text: i18next.t("Year") },
{ value: "yyyy-mm", text: i18next.t("Year and month") },
Expand Down
2 changes: 2 additions & 0 deletions oarepo_ui/theme/webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"lodash": "^4.17.0",
"react-text-truncate": "^0.19.0",
"react-datepicker": "^4.21.0",
"edtf": "^4.0.0",
}
aliases = {
"../../theme.config$": "less/theme.config",
Expand All @@ -56,6 +57,7 @@
# those used in our own components here
dependencies = {
"react-datepicker": "^4.21.0",
"edtf": "^4.0.0",
}
aliases = {}

Expand Down

0 comments on commit 18d986b

Please sign in to comment.