investira.sdk 2.2.9 → 2.2.12
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 +12 -0
- package/lib/tests/test_dates.js +35 -0
- package/lib/utils/arrays.js +4 -3
- package/lib/utils/dates.js +48 -0
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -425,3 +425,15 @@ O contrutor para a criação das mensagem foi alterado.
|
|
|
425
425
|
|
|
426
426
|
- [moment] Atualização da versão "2.24.0" versão para "2.29.3"
|
|
427
427
|
- [tape] Atualização da versão "4.15.0" versão para "4.15.1"
|
|
428
|
+
|
|
429
|
+
# 2.2.10
|
|
430
|
+
|
|
431
|
+
- [moment] Atualização da versão "2.24.0" versão para "2.29.4"
|
|
432
|
+
|
|
433
|
+
# 2.2.11
|
|
434
|
+
|
|
435
|
+
- [investira.data] Atualização
|
|
436
|
+
|
|
437
|
+
# 2.2.12
|
|
438
|
+
|
|
439
|
+
- [investira.data] Atualização
|
package/lib/tests/test_dates.js
CHANGED
|
@@ -230,3 +230,38 @@ test('\ndates getWeekends', t => {
|
|
|
230
230
|
t.equal(dates.weekends(dates.toDate('2019-05-05'), dates.toDate('2019-05-08')), 0, '2019-05-05 2019-05-08');
|
|
231
231
|
t.end();
|
|
232
232
|
});
|
|
233
|
+
|
|
234
|
+
test('\ndates weekOfMonth (absolute)', t => {
|
|
235
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-01'), true), 1);
|
|
236
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-08'), true), 2);
|
|
237
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-15'), true), 3);
|
|
238
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-22'), true), 4);
|
|
239
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-25'), true), 5);
|
|
240
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-31'), true), 6);
|
|
241
|
+
t.end();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('\ndates weekOfMonth', t => {
|
|
245
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-01')), 1);
|
|
246
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-08')), 2);
|
|
247
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-15')), 3);
|
|
248
|
+
t.equal(dates.weekOfMonth(dates.toDate('2022-01-25')), 4);
|
|
249
|
+
t.end();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test('\ndates weekOfYear', t => {
|
|
253
|
+
t.equal(dates.weekOfYear(dates.toDate('2022-01-01')), 1);
|
|
254
|
+
t.equal(dates.weekOfYear(dates.toDate('2022-01-08')), 2);
|
|
255
|
+
t.equal(dates.weekOfYear(dates.toDate('2022-01-15')), 3);
|
|
256
|
+
t.equal(dates.weekOfYear(dates.toDate('2022-01-22')), 4);
|
|
257
|
+
t.equal(dates.weekOfYear(dates.toDate('2022-01-24')), 5);
|
|
258
|
+
t.end();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test('\ndates weekOf "month"', t => {
|
|
262
|
+
t.deepEqual(dates.weekOf(dates.toDate('2022-01-01')), { month: 1, year: 1 });
|
|
263
|
+
t.deepEqual(dates.weekOf(dates.toDate('2022-01-08')), { month: 2, year: 2 });
|
|
264
|
+
t.deepEqual(dates.weekOf(dates.toDate('2022-01-15')), { month: 3, year: 3 });
|
|
265
|
+
t.deepEqual(dates.weekOf(dates.toDate('2022-01-25')), { month: 4, year: 5 });
|
|
266
|
+
t.end();
|
|
267
|
+
});
|
package/lib/utils/arrays.js
CHANGED
|
@@ -160,15 +160,15 @@ const arrays = {
|
|
|
160
160
|
};
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
|
-
*
|
|
164
|
-
* Atenção: Lista precisar estar em
|
|
163
|
+
* Pesquisa binária para retorna o index da lista mais próximo ao valor alvo
|
|
164
|
+
* Atenção: Lista precisar estar em ordem crescente
|
|
165
165
|
* @param {array} pSourceArray Array com os itens a serem pesquisados
|
|
166
166
|
* @param {object} pTargetValue Valor alvo
|
|
167
167
|
* @param {boolean} [pGreater=null] Proximidade do valor alvo:
|
|
168
168
|
* - true: item mais próximo superior
|
|
169
169
|
* - false: item mais próximo anterior
|
|
170
170
|
* - null: mais próximo numericamente
|
|
171
|
-
* @param {function} pConvertFunction Função para converte
|
|
171
|
+
* @param {function} pConvertFunction Função para converte o valor do array em conformidade com o tipo do valor alvo, caso necessário
|
|
172
172
|
* @param {object} pControl
|
|
173
173
|
* @returns {object}
|
|
174
174
|
*/
|
|
@@ -248,6 +248,7 @@ const pvSeek = (
|
|
|
248
248
|
if (xI != pControl.maxIndex && xI !== pControl.minIndex) {
|
|
249
249
|
throw new Error('Comparison error');
|
|
250
250
|
}
|
|
251
|
+
//Chamada recursiva até finalizar a busca
|
|
251
252
|
return pvSeek(pSourceArray, pTargetValue, pGreater, pConvertFunction, {
|
|
252
253
|
minIndex: pControl.minIndex,
|
|
253
254
|
maxIndex: pControl.maxIndex
|
package/lib/utils/dates.js
CHANGED
|
@@ -870,6 +870,54 @@ const dates = {
|
|
|
870
870
|
xNextDate = dates.addWorkingDays(xNextDate, 0);
|
|
871
871
|
}
|
|
872
872
|
return xNextDate;
|
|
873
|
+
},
|
|
874
|
+
/**
|
|
875
|
+
* Retorna inteiro relativo a semana do mês
|
|
876
|
+
* @param {Date} pDate
|
|
877
|
+
* @returns
|
|
878
|
+
*/
|
|
879
|
+
weekOfMonth: (pDate, pAbsolute = false) => {
|
|
880
|
+
if (isNull(pDate)) {
|
|
881
|
+
return 0;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
if (pAbsolute) {
|
|
885
|
+
return moment(pDate).week() - moment(pDate).startOf('month').week() + 1;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
const xDay = moment(pDate).date();
|
|
889
|
+
const xWeek = Math.ceil(xDay / 7);
|
|
890
|
+
return xWeek;
|
|
891
|
+
},
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Retorna inteiro relativo a semana do ano
|
|
895
|
+
* @param {Date} pDate
|
|
896
|
+
* @returns
|
|
897
|
+
*/
|
|
898
|
+
weekOfYear: pDate => {
|
|
899
|
+
if (isNull(pDate)) {
|
|
900
|
+
return 0;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
return moment(pDate).week();
|
|
904
|
+
},
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* Retorna objeto com os inteiros referentes a semana do mês ou do ano.
|
|
908
|
+
* @param {Date} pDate Data
|
|
909
|
+
* @returns {Object} Semana do mês ou do ano
|
|
910
|
+
* @example
|
|
911
|
+
* dates.weekOf(new Date(2020, 1, 1)); // 1
|
|
912
|
+
* dates.weekOf(new Date(2020, 1, 8)); // 2
|
|
913
|
+
**/
|
|
914
|
+
weekOf: (pDate, pAbsolute = false) => {
|
|
915
|
+
if (isNull(pDate)) {
|
|
916
|
+
return {};
|
|
917
|
+
}
|
|
918
|
+
const xResult = { month: dates.weekOfMonth(pDate, pAbsolute), year: dates.weekOfYear(pDate) };
|
|
919
|
+
|
|
920
|
+
return xResult;
|
|
873
921
|
}
|
|
874
922
|
};
|
|
875
923
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "investira.sdk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.12",
|
|
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.2.
|
|
9
|
+
"raw": "investira.sdk@2.2.12",
|
|
10
10
|
"escapedName": "investira.sdk",
|
|
11
|
-
"rawSpec": "2.2.
|
|
11
|
+
"rawSpec": "2.2.12",
|
|
12
12
|
"saveSpec": null,
|
|
13
|
-
"fetchSpec": "2.2.
|
|
13
|
+
"fetchSpec": "2.2.12",
|
|
14
14
|
"homepage": "https://investira.com.br/",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=11.11.0 <=14.17.5",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"axios": "0.25.0",
|
|
38
38
|
"deep-diff": "1.0.2",
|
|
39
39
|
"flatted": "3.2.2",
|
|
40
|
-
"investira.data": "^1.1.
|
|
41
|
-
"moment": "^2.29.
|
|
40
|
+
"investira.data": "^1.1.15",
|
|
41
|
+
"moment": "^2.29.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tape": "^4.15.1"
|