investira.sdk 2.3.21 → 2.3.23
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/CHANGELOG.md +8 -0
- package/lib/hofs/tasks.js +1 -1
- package/lib/utils/dates.js +106 -83
- package/lib/utils/formats.js +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -537,3 +537,11 @@ O contrutor para a criação das mensagem foi alterado.
|
|
|
537
537
|
# 2.3.20
|
|
538
538
|
|
|
539
539
|
- [tasks] Substituido this por self
|
|
540
|
+
|
|
541
|
+
# 2.3.22
|
|
542
|
+
|
|
543
|
+
- [dates] scheduleToDate com seleção do dia da semana, no tipo 'M' e 'Y'.
|
|
544
|
+
|
|
545
|
+
# 2.3.23
|
|
546
|
+
|
|
547
|
+
- [dates] scheduleToDate correção para dia da semana '0' .
|
package/lib/hofs/tasks.js
CHANGED
|
@@ -27,7 +27,7 @@ function task(pOptions, pSource = {}) {
|
|
|
27
27
|
{
|
|
28
28
|
type: null, //'D'-Dia, 'W'-Semana, 'M'-Mês, 'Y'-Ano
|
|
29
29
|
time: null, //'hh:mm' Hora da execução
|
|
30
|
-
weekday: null, //Número da semana quando type for 'W', 0-Domingo até 6-sábado.
|
|
30
|
+
weekday: null, //Número da semana quando type for 'W','M' ou 'Y' , 0-Domingo até 6-sábado.
|
|
31
31
|
day: null, //Dia do mês quando type for 'M'
|
|
32
32
|
month: null, //Número do mês quando type for 'Y'
|
|
33
33
|
workingDay: null //Boolean indicando se cálculo será em dias úteis.
|
package/lib/utils/dates.js
CHANGED
|
@@ -769,8 +769,12 @@ const dates = {
|
|
|
769
769
|
//Ajusta datafim: Se dia inicial for maior que dia final,
|
|
770
770
|
//indica que próximo tem um total de dias menor que o atual.
|
|
771
771
|
//Adiciona 1 dia para considerar integralmente próximo mês.
|
|
772
|
-
|
|
773
|
-
|
|
772
|
+
try {
|
|
773
|
+
if (pDate.getUTCDate() > xDataFim.getUTCDate()) {
|
|
774
|
+
xDataFim = dates.addDays(xDataFim, 1);
|
|
775
|
+
}
|
|
776
|
+
} catch (rErr) {
|
|
777
|
+
// console.log(rErr);
|
|
774
778
|
}
|
|
775
779
|
return xDataFim;
|
|
776
780
|
},
|
|
@@ -874,7 +878,7 @@ const dates = {
|
|
|
874
878
|
*/
|
|
875
879
|
dateToObject: pDate => {
|
|
876
880
|
if (!isDate(pDate)) {
|
|
877
|
-
throw Error(
|
|
881
|
+
throw Error(`dateToObject: invalid date ${pDate}`);
|
|
878
882
|
}
|
|
879
883
|
return {
|
|
880
884
|
year: String(pDate.getFullYear()),
|
|
@@ -923,95 +927,114 @@ const dates = {
|
|
|
923
927
|
* @returns {Date} Próxima Data
|
|
924
928
|
*/
|
|
925
929
|
scheduleToDate: (pSchedule, pBaseDate = null) => {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
const xCurrentDate = pBaseDate || dates.toDate();
|
|
936
|
-
const xNow = dates.dateToObject(xCurrentDate);
|
|
937
|
-
|
|
938
|
-
let xNextDate = null;
|
|
939
|
-
pSchedule.type = pSchedule.type.toUpperCase();
|
|
940
|
-
if (pSchedule.type === 'D') {
|
|
941
|
-
xNextDate = dates.toDate(`${xNow.year}${xNow.month}${xNow.day}${pSchedule.time}`, SCHEDULE_FORMAT);
|
|
942
|
-
if (xNextDate < xCurrentDate) {
|
|
943
|
-
//Incrementa um dia
|
|
944
|
-
xNextDate = dates.addDays(xNextDate, 1);
|
|
930
|
+
try {
|
|
931
|
+
if (
|
|
932
|
+
!pSchedule ||
|
|
933
|
+
!pSchedule.type ||
|
|
934
|
+
!pSchedule.time ||
|
|
935
|
+
!dates.SCHEDULE_TYPE.includes(pSchedule.type) ||
|
|
936
|
+
!dates.isTime(pSchedule.time)
|
|
937
|
+
) {
|
|
938
|
+
throw Error('scheduleToDate: parameters not informed');
|
|
945
939
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
940
|
+
const xCurrentDate = pBaseDate || dates.toDate();
|
|
941
|
+
const xNow = dates.dateToObject(xCurrentDate);
|
|
942
|
+
|
|
943
|
+
let xNextDate = null;
|
|
944
|
+
pSchedule.type = pSchedule.type.toUpperCase();
|
|
945
|
+
if (pSchedule.type === 'D') {
|
|
946
|
+
xNextDate = dates.toDate(`${xNow.year}${xNow.month}${xNow.day}${pSchedule.time}`, SCHEDULE_FORMAT);
|
|
947
|
+
if (!xNextDate) {
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
if (xNextDate < xCurrentDate) {
|
|
951
|
+
//Incrementa um dia
|
|
952
|
+
xNextDate = dates.addDays(xNextDate, 1);
|
|
953
|
+
}
|
|
954
|
+
} else if (pSchedule.type === 'W') {
|
|
955
|
+
const xWeekday = numbers.toNumber(pSchedule.weekday || pSchedule.weekDay || 0);
|
|
951
956
|
if (xWeekday === null || xWeekday < 0 || xWeekday > 6) {
|
|
952
|
-
throw Error(
|
|
957
|
+
throw Error(`scheduleToDate: invalid weekday ${pSchedule.weekday || pSchedule.weekDay}`);
|
|
958
|
+
}
|
|
959
|
+
let xDif = xWeekday - xCurrentDate.getDay();
|
|
960
|
+
//Adiciona os dias até ser o dia da semana desejado
|
|
961
|
+
if (xDif < 0) {
|
|
962
|
+
xDif = 7 - Math.abs(xDif);
|
|
963
|
+
}
|
|
964
|
+
xNextDate = dates.addDays(xCurrentDate, xDif);
|
|
965
|
+
if (!xNextDate) {
|
|
966
|
+
return null;
|
|
953
967
|
}
|
|
954
|
-
}
|
|
955
|
-
let xDif = pSchedule.weekday - xCurrentDate.getDay();
|
|
956
|
-
//Adiciona os dias até ser o dia da semana desejado
|
|
957
|
-
if (xDif < 0) {
|
|
958
|
-
xDif = 7 - Math.abs(xDif);
|
|
959
|
-
}
|
|
960
|
-
xNextDate = dates.addDays(xCurrentDate, xDif);
|
|
961
|
-
// const xNextDataObject = dates.dateToObject(new Date(xNextDate.tl()));
|
|
962
|
-
xNextDate = dates.toDate(
|
|
963
|
-
`${xNextDate.getFullYear()}${String(xNextDate.getMonth() + 1).padStart(2, '0')}${String(
|
|
964
|
-
xNextDate.getDate()
|
|
965
|
-
).padStart(2, '0')}${pSchedule.time}`,
|
|
966
|
-
SCHEDULE_FORMAT
|
|
967
|
-
);
|
|
968
|
-
//Adiciona uma semana se data já tiver passado
|
|
969
|
-
if (xNextDate < xCurrentDate) {
|
|
970
|
-
//Incrementa uma semana
|
|
971
|
-
xNextDate = dates.addDays(xNextDate, 7);
|
|
972
|
-
}
|
|
973
|
-
} else if (pSchedule.type === 'M') {
|
|
974
|
-
if (!pSchedule.day) {
|
|
975
|
-
pSchedule.day = 1;
|
|
976
|
-
}
|
|
977
|
-
let xNextDay = numbers.toNumber(pSchedule.day);
|
|
978
|
-
if (xNextDay === null || xNextDay < 0 || (xNextDay > 31 && xNextDay !== 99)) {
|
|
979
|
-
throw Error('scheduleToDate: invalid day');
|
|
980
|
-
}
|
|
981
|
-
xNextDay = ('0' + xNextDay).slice(-2);
|
|
982
|
-
xNextDate = dates.toDate(`${xNow.year}${xNow.month}${xNextDay}${pSchedule.time}`, SCHEDULE_FORMAT);
|
|
983
|
-
// @ts-ignore
|
|
984
|
-
if (xNextDay === 99 || isNaN(xNextDate)) {
|
|
985
|
-
const xTmpDate = dates.dateToObject(dates.endOf('month', xCurrentDate));
|
|
986
968
|
xNextDate = dates.toDate(
|
|
987
|
-
`${
|
|
969
|
+
`${xNextDate.getFullYear()}${String(xNextDate.getMonth() + 1).padStart(2, '0')}${String(
|
|
970
|
+
xNextDate.getDate()
|
|
971
|
+
).padStart(2, '0')}${pSchedule.time}`,
|
|
988
972
|
SCHEDULE_FORMAT
|
|
989
973
|
);
|
|
974
|
+
//Adiciona uma semana se data já tiver passado
|
|
975
|
+
if (xNextDate < xCurrentDate) {
|
|
976
|
+
//Incrementa uma semana
|
|
977
|
+
xNextDate = dates.addDays(xNextDate, 7);
|
|
978
|
+
}
|
|
979
|
+
} else if (pSchedule.type === 'M') {
|
|
980
|
+
if (!pSchedule.day) {
|
|
981
|
+
pSchedule.day = 1;
|
|
982
|
+
}
|
|
983
|
+
let xNextDay = numbers.toNumber(pSchedule.day);
|
|
984
|
+
if (xNextDay === null || xNextDay < 0 || (xNextDay > 31 && xNextDay !== 99)) {
|
|
985
|
+
throw Error('scheduleToDate: invalid day');
|
|
986
|
+
}
|
|
987
|
+
xNextDay = ('0' + xNextDay).slice(-2);
|
|
988
|
+
xNextDate = dates.toDate(`${xNow.year}${xNow.month}${xNextDay}${pSchedule.time}`, SCHEDULE_FORMAT);
|
|
989
|
+
if (!xNextDate) {
|
|
990
|
+
return null;
|
|
991
|
+
}
|
|
992
|
+
// @ts-ignore
|
|
993
|
+
if (xNextDay === 99 || isNaN(xNextDate)) {
|
|
994
|
+
const xTmpDate = dates.dateToObject(dates.endOf('month', xCurrentDate));
|
|
995
|
+
xNextDate = dates.toDate(
|
|
996
|
+
`${xTmpDate.year}${xTmpDate.month}${xTmpDate.day}${pSchedule.time}`,
|
|
997
|
+
SCHEDULE_FORMAT
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
if (xNextDate < xCurrentDate) {
|
|
1001
|
+
//Incrementa um mês
|
|
1002
|
+
xNextDate = dates.nextMonthAnniversary(xNextDate);
|
|
1003
|
+
}
|
|
1004
|
+
//Se dia da semana estive configurado, ajusta data para o dia da semana informado
|
|
1005
|
+
if (pSchedule?.weekday >= 0 || pSchedule?.weekDay >= 0) {
|
|
1006
|
+
xNextDate = dates.scheduleToDate({ ...pSchedule, type: 'W' }, xNextDate);
|
|
1007
|
+
}
|
|
1008
|
+
} else if (pSchedule.type === 'Y') {
|
|
1009
|
+
if (!pSchedule.month) {
|
|
1010
|
+
pSchedule.month = 1;
|
|
1011
|
+
}
|
|
1012
|
+
let xNextMonth = numbers.toNumber(pSchedule.month);
|
|
1013
|
+
if (xNextMonth === null || xNextMonth < 0 || xNextMonth > 12) {
|
|
1014
|
+
throw Error('scheduleToDate: invalid month');
|
|
1015
|
+
}
|
|
1016
|
+
xNextMonth = ('0' + xNextMonth).slice(-2);
|
|
1017
|
+
//Calcula data do primeiro dia no mês/ano selecionado
|
|
1018
|
+
xNextDate = dates.toDate(`${xNow.year}${xNextMonth}${'01'}${pSchedule.time}`, SCHEDULE_FORMAT);
|
|
1019
|
+
if (!xNextDate) {
|
|
1020
|
+
return null;
|
|
1021
|
+
}
|
|
1022
|
+
if (xNextDate < xCurrentDate) {
|
|
1023
|
+
//Incrementa um ano
|
|
1024
|
+
xNextDate = dates.addYears(xNextDate, 1);
|
|
1025
|
+
}
|
|
1026
|
+
//Se dia da semana estive configurado, ajusta data para o dia da semana informado
|
|
1027
|
+
if (pSchedule?.weekday >= 0 || pSchedule?.weekDay >= 0) {
|
|
1028
|
+
xNextDate = dates.scheduleToDate({ ...pSchedule, type: 'W' }, xNextDate);
|
|
1029
|
+
}
|
|
990
1030
|
}
|
|
991
|
-
if (
|
|
992
|
-
|
|
993
|
-
xNextDate = dates.nextMonthAnniversary(xNextDate);
|
|
994
|
-
}
|
|
995
|
-
} else if (pSchedule.type === 'Y') {
|
|
996
|
-
if (!pSchedule.month) {
|
|
997
|
-
pSchedule.month = 1;
|
|
998
|
-
}
|
|
999
|
-
let xNextMonth = numbers.toNumber(pSchedule.month);
|
|
1000
|
-
if (xNextMonth === null || xNextMonth < 0 || xNextMonth > 12) {
|
|
1001
|
-
throw Error('scheduleToDate: invalid month');
|
|
1002
|
-
}
|
|
1003
|
-
xNextMonth = ('0' + xNextMonth).slice(-2);
|
|
1004
|
-
//Calcula data do primeiro dia no mês/ano selecionado
|
|
1005
|
-
xNextDate = dates.toDate(`${xNow.year}${xNextMonth}${'01'}${pSchedule.time}`, SCHEDULE_FORMAT);
|
|
1006
|
-
if (xNextDate < xCurrentDate) {
|
|
1007
|
-
//Incrementa um ano
|
|
1008
|
-
xNextDate = dates.addYears(xNextDate, 1);
|
|
1031
|
+
if (pSchedule.workingDay) {
|
|
1032
|
+
xNextDate = dates.addWorkingDays(xNextDate, 0);
|
|
1009
1033
|
}
|
|
1034
|
+
return xNextDate;
|
|
1035
|
+
} catch (rErr) {
|
|
1036
|
+
console.log(rErr);
|
|
1010
1037
|
}
|
|
1011
|
-
if (pSchedule.workingDay) {
|
|
1012
|
-
xNextDate = dates.addWorkingDays(xNextDate, 0);
|
|
1013
|
-
}
|
|
1014
|
-
return xNextDate;
|
|
1015
1038
|
},
|
|
1016
1039
|
/**
|
|
1017
1040
|
* Retorna inteiro relativo a semana do mês
|
package/lib/utils/formats.js
CHANGED
|
@@ -63,7 +63,7 @@ const formats = {
|
|
|
63
63
|
* @param {number} pValue Elemento a ser verificado
|
|
64
64
|
* @param {number} [pDecimalPlaces=0] Quantidade de casas decimais
|
|
65
65
|
* @param {boolean} [pShowCurrency=false] Se exibe o símbolo da moeda do país definido em formats.CURRENCY.
|
|
66
|
-
* @param {string} [pBase=null] Base
|
|
66
|
+
* @param {string} [pBase=null] Base. Fixa a base 'mil', 'mi', 'bi', 'tri', 'quatri', 'quint', 'sext'
|
|
67
67
|
* @return {string} Número formatado
|
|
68
68
|
*/
|
|
69
69
|
friendlyNumber: (pValue, pDecimalPlaces = 0, pShowCurrency = false, pBase = null) => {
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "investira.sdk",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.23",
|
|
4
4
|
"author": "Investira",
|
|
5
5
|
"description": "Investira SDK",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"registry": true,
|
|
9
|
-
"raw": "investira.sdk@2.3.
|
|
9
|
+
"raw": "investira.sdk@2.3.23",
|
|
10
10
|
"escapedName": "investira.sdk",
|
|
11
|
-
"rawSpec": "2.3.
|
|
11
|
+
"rawSpec": "2.3.23",
|
|
12
12
|
"saveSpec": null,
|
|
13
|
-
"fetchSpec": "2.3.
|
|
13
|
+
"fetchSpec": "2.3.23",
|
|
14
14
|
"homepage": "https://investira.com.br/",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=11.11.0 <=18.12",
|