edit-date: construction and validation (fix #671)
Signed-off-by: Varun Patil <radialapps@gmail.com>monorepo
parent
e5e9a08ba8
commit
101b2bbe0d
|
@ -10,6 +10,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="5000"
|
||||||
:value.sync="year"
|
:value.sync="year"
|
||||||
:label="t('memories', 'Year')"
|
:label="t('memories', 'Year')"
|
||||||
:label-visible="true"
|
:label-visible="true"
|
||||||
|
@ -20,6 +22,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="12"
|
||||||
:value.sync="month"
|
:value.sync="month"
|
||||||
:label="t('memories', 'Month')"
|
:label="t('memories', 'Month')"
|
||||||
:label-visible="true"
|
:label-visible="true"
|
||||||
|
@ -30,6 +34,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="31"
|
||||||
:value.sync="day"
|
:value.sync="day"
|
||||||
:label="t('memories', 'Day')"
|
:label="t('memories', 'Day')"
|
||||||
:label-visible="true"
|
:label-visible="true"
|
||||||
|
@ -40,6 +46,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="23"
|
||||||
:value.sync="hour"
|
:value.sync="hour"
|
||||||
:label="t('memories', 'Time')"
|
:label="t('memories', 'Time')"
|
||||||
:label-visible="true"
|
:label-visible="true"
|
||||||
|
@ -50,6 +58,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="59"
|
||||||
:value.sync="minute"
|
:value.sync="minute"
|
||||||
:label="t('memories', 'Minute')"
|
:label="t('memories', 'Minute')"
|
||||||
:placeholder="t('memories', 'Minute')"
|
:placeholder="t('memories', 'Minute')"
|
||||||
|
@ -69,6 +79,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="5000"
|
||||||
:value.sync="yearLast"
|
:value.sync="yearLast"
|
||||||
:label="t('memories', 'Year')"
|
:label="t('memories', 'Year')"
|
||||||
:label-visible="true"
|
:label-visible="true"
|
||||||
|
@ -79,6 +91,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="12"
|
||||||
:value.sync="monthLast"
|
:value.sync="monthLast"
|
||||||
:label="t('memories', 'Month')"
|
:label="t('memories', 'Month')"
|
||||||
:label-visible="true"
|
:label-visible="true"
|
||||||
|
@ -89,6 +103,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="31"
|
||||||
:value.sync="dayLast"
|
:value.sync="dayLast"
|
||||||
:label="t('memories', 'Day')"
|
:label="t('memories', 'Day')"
|
||||||
:label-visible="true"
|
:label-visible="true"
|
||||||
|
@ -99,6 +115,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="23"
|
||||||
:value.sync="hourLast"
|
:value.sync="hourLast"
|
||||||
:label="t('memories', 'Time')"
|
:label="t('memories', 'Time')"
|
||||||
:label-visible="true"
|
:label-visible="true"
|
||||||
|
@ -109,6 +127,8 @@
|
||||||
<NcTextField
|
<NcTextField
|
||||||
class="field"
|
class="field"
|
||||||
type="number"
|
type="number"
|
||||||
|
min="0"
|
||||||
|
max="59"
|
||||||
:value.sync="minuteLast"
|
:value.sync="minuteLast"
|
||||||
:label="t('memories', 'Minute')"
|
:label="t('memories', 'Minute')"
|
||||||
:placeholder="t('memories', 'Minute')"
|
:placeholder="t('memories', 'Minute')"
|
||||||
|
@ -318,13 +338,12 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
makeDate(yearS: string, monthS: string, dayS: string, hourS: string, minuteS: string, secondS: string) {
|
makeDate(yearS: string, monthS: string, dayS: string, hourS: string, minuteS: string, secondS: string) {
|
||||||
const date = new Date();
|
|
||||||
const year = parseInt(yearS, 10);
|
const year = parseInt(yearS, 10);
|
||||||
const month = parseInt(monthS, 10) - 1;
|
const month = parseInt(monthS, 10) - 1;
|
||||||
const day = parseInt(dayS, 10);
|
const day = parseInt(dayS, 10);
|
||||||
const hour = parseInt(hourS, 10);
|
const hour = parseInt(hourS, 10);
|
||||||
const minute = parseInt(minuteS, 10);
|
const minute = parseInt(minuteS, 10);
|
||||||
const second = parseInt(secondS, 10) || 0;
|
let second = parseInt(secondS, 10) || 0; // needs validation
|
||||||
|
|
||||||
if (isNaN(year)) return null;
|
if (isNaN(year)) return null;
|
||||||
if (isNaN(month)) return null;
|
if (isNaN(month)) return null;
|
||||||
|
@ -333,13 +352,20 @@ export default defineComponent({
|
||||||
if (isNaN(minute)) return null;
|
if (isNaN(minute)) return null;
|
||||||
if (isNaN(second)) return null;
|
if (isNaN(second)) return null;
|
||||||
|
|
||||||
date.setUTCFullYear(year);
|
// Validate date
|
||||||
date.setUTCMonth(month);
|
if (year < 0 || year > 5000) return null;
|
||||||
date.setUTCDate(day);
|
if (month < 0 || month > 11) return null;
|
||||||
date.setUTCHours(hour);
|
|
||||||
date.setUTCMinutes(minute);
|
// Number of days in month
|
||||||
date.setUTCSeconds(second);
|
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
||||||
return date;
|
if (day < 1 || day > daysInMonth) return null;
|
||||||
|
|
||||||
|
// Validate time
|
||||||
|
if (hour < 0 || hour > 23) return null;
|
||||||
|
if (minute < 0 || minute > 59) return null;
|
||||||
|
if (second < 0 || second > 59) second = 0;
|
||||||
|
|
||||||
|
return new Date(Date.UTC(year, month, day, hour, minute, second));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue