@farm-investimentos/front-mfe-components 15.3.1 → 15.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm-investimentos/front-mfe-components",
3
- "version": "15.3.1",
3
+ "version": "15.3.2",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -44,7 +44,7 @@
44
44
  :readonly="readonly"
45
45
  :mask="`${readonly ? '' : '##/##/####'}`"
46
46
  :id="inputId"
47
- :rules="[checkMax, checkMin, checkRequire]"
47
+ :rules="[checkDateValid, checkMax, checkMin, checkRequire]"
48
48
  @keyup="keyUpInput"
49
49
  />
50
50
  </template>
@@ -53,7 +53,7 @@
53
53
  <script lang="ts">
54
54
  import { defineComponent } from 'vue';
55
55
  import { VDatePicker } from 'vuetify/lib/components/VDatePicker';
56
- import { defaultFormat as dateDefaultFormatter, convertDate } from '../../helpers/date';
56
+ import { defaultFormat as dateDefaultFormatter, convertDate, checkDateValid } from '../../helpers/date';
57
57
  import { formatDatePickerHeader } from '../../helpers';
58
58
  /**
59
59
  * Componente de input com datepicker para data
@@ -110,6 +110,13 @@ export default defineComponent({
110
110
  menuField: false,
111
111
  dateField: this.value,
112
112
  fieldRange: s,
113
+ checkDateValid: value => {
114
+ if(value.length > 0) {
115
+ const isValid = checkDateValid(value);
116
+ return isValid ? true : 'Data inválida';
117
+ }
118
+ return true;
119
+ },
113
120
  checkRequire: value => {
114
121
  return this.required ? !!value || value != '' || 'Campo obrigatório' : true;
115
122
  },
@@ -119,28 +126,15 @@ export default defineComponent({
119
126
  : true;
120
127
  },
121
128
  checkMin: value => {
122
- const selectedDateUTCString = new Date(convertDate(value))
123
- .toUTCString()
124
- .slice(0, -4);
125
-
126
- const selectedDate = new Date(selectedDateUTCString);
127
- selectedDate.setDate(selectedDate.getDate() + 1);
128
-
129
- const locatedSelectedDate = new Date(selectedDate.toUTCString()).toLocaleString(
130
- 'pt-BR',
131
- {
132
- timeZone: 'America/Sao_Paulo',
129
+ if(this.min) {
130
+ const dateSelected = new Date(convertDate(value));
131
+ const dateMin = new Date(convertDate(this.min));
132
+ if(dateSelected.getTime() >= dateMin.getTime()){
133
+ return true;
133
134
  }
134
- );
135
- const locatedMinDate = new Date(this.min).toLocaleString('pt-BR', {
136
- timeZone: 'America/Sao_Paulo',
137
- });
138
-
139
- return this.min &&
140
- this.getUniversalDate(locatedSelectedDate) <
141
- this.getUniversalDate(locatedMinDate)
142
- ? 'A data está fora do período permitido'
143
- : true;
135
+ return 'A data está fora do período permitido';
136
+ }
137
+ return true;
144
138
  },
145
139
  };
146
140
  },
@@ -12,3 +12,75 @@ export const convertDate = (data) => {
12
12
  let newdate = data.split("/").reverse().join("-");
13
13
  return newdate;
14
14
  };
15
+
16
+
17
+ const checkLength = (value, length) => {
18
+ return parseInt(value.length, 10) === length;
19
+ };
20
+
21
+ const dateFormatting = (date) => {
22
+ if(date.includes('/')){
23
+ let dateSplit = date.split('/');
24
+ return {
25
+ day: dateSplit[0],
26
+ month: dateSplit[1],
27
+ year: dateSplit[2]
28
+ };
29
+ }
30
+ let dateSplit = date.split('-');
31
+ return {
32
+ day: dateSplit[2],
33
+ month: dateSplit[1],
34
+ year: dateSplit[0]
35
+ };
36
+ };
37
+
38
+ const checkLeapYear = (year) => {
39
+ if (parseInt(year, 10) % 400 === 0){
40
+ return true;
41
+ }
42
+ if(parseInt(year, 10) % 4 === 0 && parseInt(year, 10) % 100 !== 0) {
43
+ return true;
44
+ }else{
45
+ return false;
46
+ }
47
+ };
48
+
49
+ const getTotalDays = (month, isLeapYear) => {
50
+ const numberMonth = parseInt(month, 10);
51
+ if(numberMonth === 2) {
52
+ return isLeapYear ? 29 : 28;
53
+ }
54
+ const monthsWith31Days = [1, 3, 5, 7, 8, 10, 12];
55
+ return monthsWith31Days.includes(numberMonth) ? 31 : 30;
56
+ };
57
+
58
+ const checkDay = (day, totalDays) => {
59
+ if(parseInt(day, 10) > 0 && parseInt(day, 10) <= totalDays) {
60
+ return true;
61
+ }
62
+ return false;
63
+ };
64
+
65
+ const checkMonth = (month) => {
66
+ if(parseInt(month, 10) > 0 && parseInt(month, 10) <= 12) {
67
+ return true;
68
+ }
69
+ return false;
70
+ };
71
+
72
+ export const checkDateValid = (date) => {
73
+ if(!checkLength(date, 10)){
74
+ return false;
75
+ }
76
+ const {day, month, year} = dateFormatting(date);
77
+ if(!checkMonth(month)){
78
+ return false;
79
+ }
80
+ const isLeapYear = checkLeapYear(year);
81
+ const totalDays = getTotalDays(month, isLeapYear);
82
+ if(!checkDay(day, totalDays)){
83
+ return false;
84
+ }
85
+ return true;
86
+ };