Browse Source

Fix date parsing issue in Safari

safari-date-fix
Gabbie Burns 1 year ago
parent
commit
7c81d5330e
  1. 3
      package.json
  2. 21
      ui/js/datasheet.jsx
  3. 25
      ui/js/datasheet2020.jsx
  4. 5
      yarn.lock

3
package.json

@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
"@babel/runtime": "^7.7.2",
"aphrodite": "^2.4.0",
"bootstrap": "^4.3.1",
"luxon": "^1.26.0",
"prop-types": "^15.7.2",
"react": "^16.10.2",
"react-bootstrap": "^1.0.0-beta.14",
@ -46,7 +47,7 @@ @@ -46,7 +47,7 @@
"whatwg-fetch": "^3.0.0"
},
"engines": {
"yarn": "1.21.x",
"yarn": "1.22.x",
"node": "12.x"
}
}

21
ui/js/datasheet.jsx

@ -10,6 +10,7 @@ import "whatwg-fetch"; @@ -10,6 +10,7 @@ import "whatwg-fetch";
import Alert from "react-bootstrap/Alert";
import Spinner from "react-bootstrap/Spinner";
import Creatable from "react-select/creatable";
import DateTime from "luxon/src/datetime.js";
import { Cell, HeaderInfoCell } from "./cell.jsx";
import { HepNestRow, validateHepNestRow } from "./hep-nest-row.jsx";
@ -326,9 +327,23 @@ export const Datasheet = (props: Props) => { @@ -326,9 +327,23 @@ export const Datasheet = (props: Props) => {
if (!date) {
errors.date = "Date is required";
} else {
const surveyYear = parseInt(date.substring(0, 4));
if (surveyYear < 2021) {
errors.date = "Cannot use this datasheet version before 2021";
let surveyYear = "";
let tempYear = DateTime.fromFormat(date, "yyyy-MM-dd").year;
if (tempYear) {
surveyYear = tempYear;
} else {
tempYear = DateTime.fromFormat(date, "MM/dd/yy").year;
if (tempYear) {
surveyYear = tempYear;
}
}
if (surveyYear) {
if (surveyYear < 2021) {
errors.date = "Cannot use this datasheet version before 2021";
}
} else {
errors.date = "Date must be formatted MM/dd/yy";
}
}
if (!startTime) {

25
ui/js/datasheet2020.jsx

@ -11,6 +11,7 @@ import "whatwg-fetch"; @@ -11,6 +11,7 @@ import "whatwg-fetch";
import Alert from "react-bootstrap/Alert";
import Spinner from "react-bootstrap/Spinner";
import Creatable from "react-select/creatable";
import DateTime from "luxon/src/datetime.js";
import { Cell, HeaderInfoCell } from "./cell.jsx";
import { HepNestRow, validateHepNestRow } from "./hep-nest-row.jsx";
@ -320,12 +321,26 @@ export const Datasheet2020 = (props: Props) => { @@ -320,12 +321,26 @@ export const Datasheet2020 = (props: Props) => {
if (!date) {
errors.date = "Date is required";
} else {
const surveyYear = parseInt(date.substring(0, 4));
if (surveyYear > 2020) {
errors.date = "Cannot use this datasheet version after 2020";
let surveyYear = "";
let tempYear = DateTime.fromFormat(date, "yyyy-MM-dd").year;
if (tempYear) {
surveyYear = tempYear;
} else {
tempYear = DateTime.fromFormat(date, "MM/dd/yy").year;
if (tempYear) {
surveyYear = tempYear;
}
}
if (surveyYear < 2016) {
oldSheet = true;
if (surveyYear) {
if (surveyYear > 2020) {
errors.date = "Cannot use this datasheet version after 2020";
}
if (surveyYear < 2016) {
oldSheet = true;
}
} else {
errors.date = "Date must be formatted MM/dd/yy";
}
}
if (!startTime) {

5
yarn.lock

@ -4752,6 +4752,11 @@ lowercase-keys@^1.0.0: @@ -4752,6 +4752,11 @@ lowercase-keys@^1.0.0:
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f"
integrity sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==
luxon@^1.26.0:
version "1.26.0"
resolved "https://registry.yarnpkg.com/luxon/-/luxon-1.26.0.tgz#d3692361fda51473948252061d0f8561df02b578"
integrity sha512-+V5QIQ5f6CDXQpWNICELwjwuHdqeJM1UenlZWx5ujcRMc9venvluCjFb4t5NYLhb6IhkbMVOxzVuOqkgMxee2A==
macos-release@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-2.3.0.tgz#eb1930b036c0800adebccd5f17bc4c12de8bb71f"

Loading…
Cancel
Save