Skip to content

Commit

Permalink
Merge pull request #250 from kbss-cvut/time-parameterization
Browse files Browse the repository at this point in the history
Date and time is now parameterizable for each question
  • Loading branch information
blcham authored Jan 9, 2024
2 parents ae53faa + fa6732d commit 099f09b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/constants/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export default class Constants {
static HAS_AUTHOR = "http://onto.fel.cvut.cz/ontologies/form/has-author";
static HAS_TIMESTAMP =
"http://onto.fel.cvut.cz/ontologies/form/has-timestamp";
static TIME_FORMAT = "http://onto.fel.cvut.cz/ontologies/form/time-format";
static DATE_FORMAT = "http://onto.fel.cvut.cz/ontologies/form/date-format";
static DATETIME_FORMAT =
"http://onto.fel.cvut.cz/ontologies/form/datetime-format";

static NOT_ANSWERED_QUESTION =
"http://onto.fel.cvut.cz/ontologies/form/not-answered-question";
Expand Down
16 changes: 14 additions & 2 deletions src/stories/assets/form/form1.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@
},
"has_data_value": {
"@id": "http://onto.fel.cvut.cz/ontologies/documentation/has_data_value"
},
"time-format": {
"@id": "http://onto.fel.cvut.cz/ontologies/form/time-format"
},
"date-format": {
"@id": "http://onto.fel.cvut.cz/ontologies/form/date-format"
},
"datetime-format": {
"@id": "http://onto.fel.cvut.cz/ontologies/form/datetime-format"
}
},
"@graph": [
Expand Down Expand Up @@ -2442,19 +2451,22 @@
"@id": "http://vfn.cz/ontologies/fss-form/primary-treatment--c--neoadjuvant--no-of-cycles-q",
"has-layout-class": ["section", "answerable", "datetime"],
"@type": "doc:question",
"label": "Date and time"
"label": "Date and time",
"datetime-format": "yyyy-MM-dd HH:mm"
},
{
"label": "Time",
"@type": "doc:question",
"has-layout-class": ["section", "answerable", "time"],
"time-format": "HH:mm",
"@id": "http://vfn.cz/ontologies/fss-form/primary-treatment--c--neoadjuvant--no-of-cycles-q1"
},
{
"label": "Date",
"has-layout-class": ["section", "answerable", "date"],
"@id": "http://vfn.cz/ontologies/fss-form/primary-treatment--c--neoadjuvant--no-of-cycles-q2",
"@type": "doc:question"
"@type": "doc:question",
"date-format": "yyyy-MM-dd HH:mm"
},
{
"label": "Timestamp in db",
Expand Down
22 changes: 15 additions & 7 deletions src/util/FormUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,23 @@ export default class FormUtils {
* @return {*} Format from Configuration
*/
static resolveDateTimeFormat(question, originalValue, options) {
if (typeof originalValue === "number") {
const isNumber = typeof originalValue === "number";
const isDate = FormUtils.isDate(question);
const isTime = FormUtils.isTime(question);
const isDatetime = FormUtils.isDateTime(question);

if (isNumber) {
return Constants.DATETIME_NUMBER_FORMAT;
}

if (FormUtils.isDate(question)) {
return options.dateFormat;
} else if (FormUtils.isTime(question)) {
return options.timeFormat;
if (isDate) {
return question[Constants.DATE_FORMAT] || options.dateFormat;
}
if (isTime) {
return question[Constants.TIME_FORMAT] || options.timeFormat;
}
return options.dateTimeFormat;
if (isDatetime) {
return question[Constants.DATETIME_FORMAT] || options.dateTimeFormat;
}
return null;
}
}

0 comments on commit 099f09b

Please sign in to comment.