investira.sdk 2.3.21 → 2.3.22

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 CHANGED
@@ -537,3 +537,7 @@ 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'.
@@ -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
- if (pDate.getUTCDate() > xDataFim.getUTCDate()) {
773
- xDataFim = dates.addDays(xDataFim, 1);
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('dateToObject: invalid date');
881
+ throw Error(`dateToObject: invalid date ${pDate}`);
878
882
  }
879
883
  return {
880
884
  year: String(pDate.getFullYear()),
@@ -923,95 +927,119 @@ const dates = {
923
927
  * @returns {Date} Próxima Data
924
928
  */
925
929
  scheduleToDate: (pSchedule, pBaseDate = null) => {
926
- if (
927
- !pSchedule ||
928
- !pSchedule.type ||
929
- !pSchedule.time ||
930
- !dates.SCHEDULE_TYPE.includes(pSchedule.type) ||
931
- !dates.isTime(pSchedule.time)
932
- ) {
933
- throw Error('scheduleToDate: parameters not informed');
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
- } else if (pSchedule.type === 'W') {
947
- if (!pSchedule.weekday) {
948
- pSchedule.weekday = 0;
949
- } else {
950
- const xWeekday = numbers.toNumber(pSchedule.weekday);
951
- if (xWeekday === null || xWeekday < 0 || xWeekday > 6) {
952
- throw Error('scheduleToDate: invalid weekday');
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;
953
949
  }
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 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));
950
+ if (xNextDate < xCurrentDate) {
951
+ //Incrementa um dia
952
+ xNextDate = dates.addDays(xNextDate, 1);
953
+ }
954
+ } else if (pSchedule.type === 'W') {
955
+ if (!pSchedule.weekday) {
956
+ pSchedule.weekday = 0;
957
+ } else {
958
+ const xWeekday = numbers.toNumber(pSchedule.weekday);
959
+ if (xWeekday === null || xWeekday < 0 || xWeekday > 6) {
960
+ throw Error('scheduleToDate: invalid weekday');
961
+ }
962
+ }
963
+ let xDif = pSchedule.weekday - xCurrentDate.getDay();
964
+ //Adiciona os dias até ser o dia da semana desejado
965
+ if (xDif < 0) {
966
+ xDif = 7 - Math.abs(xDif);
967
+ }
968
+ xNextDate = dates.addDays(xCurrentDate, xDif);
969
+ if (!xNextDate) {
970
+ return null;
971
+ }
972
+ // const xNextDataObject = dates.dateToObject(new Date(xNextDate.tl()));
986
973
  xNextDate = dates.toDate(
987
- `${xTmpDate.year}${xTmpDate.month}${xTmpDate.day}${pSchedule.time}`,
974
+ `${xNextDate.getFullYear()}${String(xNextDate.getMonth() + 1).padStart(2, '0')}${String(
975
+ xNextDate.getDate()
976
+ ).padStart(2, '0')}${pSchedule.time}`,
988
977
  SCHEDULE_FORMAT
989
978
  );
979
+ //Adiciona uma semana se data já tiver passado
980
+ if (xNextDate < xCurrentDate) {
981
+ //Incrementa uma semana
982
+ xNextDate = dates.addDays(xNextDate, 7);
983
+ }
984
+ } else if (pSchedule.type === 'M') {
985
+ if (!pSchedule.day) {
986
+ pSchedule.day = 1;
987
+ }
988
+ let xNextDay = numbers.toNumber(pSchedule.day);
989
+ if (xNextDay === null || xNextDay < 0 || (xNextDay > 31 && xNextDay !== 99)) {
990
+ throw Error('scheduleToDate: invalid day');
991
+ }
992
+ xNextDay = ('0' + xNextDay).slice(-2);
993
+ xNextDate = dates.toDate(`${xNow.year}${xNow.month}${xNextDay}${pSchedule.time}`, SCHEDULE_FORMAT);
994
+ if (!xNextDate) {
995
+ return null;
996
+ }
997
+ // @ts-ignore
998
+ if (xNextDay === 99 || isNaN(xNextDate)) {
999
+ const xTmpDate = dates.dateToObject(dates.endOf('month', xCurrentDate));
1000
+ xNextDate = dates.toDate(
1001
+ `${xTmpDate.year}${xTmpDate.month}${xTmpDate.day}${pSchedule.time}`,
1002
+ SCHEDULE_FORMAT
1003
+ );
1004
+ }
1005
+ if (xNextDate < xCurrentDate) {
1006
+ //Incrementa um mês
1007
+ xNextDate = dates.nextMonthAnniversary(xNextDate);
1008
+ }
1009
+ //Se dia da semana estive configurado, ajusta data para o dia da semana informado
1010
+ if (pSchedule.weekday) {
1011
+ xNextDate = dates.scheduleToDate({ ...pSchedule, type: 'W' }, xNextDate);
1012
+ }
1013
+ } else if (pSchedule.type === 'Y') {
1014
+ if (!pSchedule.month) {
1015
+ pSchedule.month = 1;
1016
+ }
1017
+ let xNextMonth = numbers.toNumber(pSchedule.month);
1018
+ if (xNextMonth === null || xNextMonth < 0 || xNextMonth > 12) {
1019
+ throw Error('scheduleToDate: invalid month');
1020
+ }
1021
+ xNextMonth = ('0' + xNextMonth).slice(-2);
1022
+ //Calcula data do primeiro dia no mês/ano selecionado
1023
+ xNextDate = dates.toDate(`${xNow.year}${xNextMonth}${'01'}${pSchedule.time}`, SCHEDULE_FORMAT);
1024
+ if (!xNextDate) {
1025
+ return null;
1026
+ }
1027
+ if (xNextDate < xCurrentDate) {
1028
+ //Incrementa um ano
1029
+ xNextDate = dates.addYears(xNextDate, 1);
1030
+ }
1031
+ //Se dia da semana estive configurado, ajusta data para o dia da semana informado
1032
+ if (pSchedule.weekday) {
1033
+ xNextDate = dates.scheduleToDate({ ...pSchedule, type: 'W' }, xNextDate);
1034
+ }
990
1035
  }
991
- if (xNextDate < xCurrentDate) {
992
- //Incrementa um mês
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);
1036
+ if (pSchedule.workingDay) {
1037
+ xNextDate = dates.addWorkingDays(xNextDate, 0);
1009
1038
  }
1039
+ return xNextDate;
1040
+ } catch (rErr) {
1041
+ console.log(rErr);
1010
1042
  }
1011
- if (pSchedule.workingDay) {
1012
- xNextDate = dates.addWorkingDays(xNextDate, 0);
1013
- }
1014
- return xNextDate;
1015
1043
  },
1016
1044
  /**
1017
1045
  * Retorna inteiro relativo a semana do mês
@@ -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.21",
3
+ "version": "2.3.22",
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.21",
9
+ "raw": "investira.sdk@2.3.22",
10
10
  "escapedName": "investira.sdk",
11
- "rawSpec": "2.3.21",
11
+ "rawSpec": "2.3.22",
12
12
  "saveSpec": null,
13
- "fetchSpec": "2.3.21",
13
+ "fetchSpec": "2.3.22",
14
14
  "homepage": "https://investira.com.br/",
15
15
  "engines": {
16
16
  "node": ">=11.11.0 <=18.12",