@blazedpath/commons 0.0.4
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/README.md +3 -0
- package/blz-base/health/index.js +215 -0
- package/blz-base/index.js +1466 -0
- package/blz-cache/LruCache.js +44 -0
- package/blz-cache/index.js +29 -0
- package/blz-config/index.js +434 -0
- package/blz-core/index.js +364 -0
- package/blz-cryptography/index.js +54 -0
- package/blz-datetimes/index.js +356 -0
- package/blz-file/example.dat +2545 -0
- package/blz-file/fileService.js +205 -0
- package/blz-file/index.js +94 -0
- package/blz-file/index.test.js +31 -0
- package/blz-file/lab.js +33 -0
- package/blz-hazelcast/index.js +189 -0
- package/blz-hazelcast/lib/credentials.js +25 -0
- package/blz-hazelcast/lib/credentialsFactory.js +12 -0
- package/blz-hazelcast/lib/hazelcastCache.js +234 -0
- package/blz-iterable/index.js +446 -0
- package/blz-json-schema/index.js +11 -0
- package/blz-jwt/index.js +121 -0
- package/blz-kafka/index.js +522 -0
- package/blz-math/index.js +131 -0
- package/blz-mongodb/index.js +326 -0
- package/blz-rds/__test__/scape.test.js +58 -0
- package/blz-rds/blz-rds-executor.js +578 -0
- package/blz-rds/blz-rds-helper.js +310 -0
- package/blz-rds/commands/core/add.js +13 -0
- package/blz-rds/commands/core/and.js +18 -0
- package/blz-rds/commands/core/asc.js +10 -0
- package/blz-rds/commands/core/avg.js +10 -0
- package/blz-rds/commands/core/column-ref.js +8 -0
- package/blz-rds/commands/core/count-distinct.js +10 -0
- package/blz-rds/commands/core/count.js +10 -0
- package/blz-rds/commands/core/decimal.js +8 -0
- package/blz-rds/commands/core/desc.js +10 -0
- package/blz-rds/commands/core/distinct.js +10 -0
- package/blz-rds/commands/core/divide.js +11 -0
- package/blz-rds/commands/core/embedded-exists.js +17 -0
- package/blz-rds/commands/core/embedded-select.js +17 -0
- package/blz-rds/commands/core/equals.js +9 -0
- package/blz-rds/commands/core/false.js +8 -0
- package/blz-rds/commands/core/greater-or-equal.js +9 -0
- package/blz-rds/commands/core/greater.js +9 -0
- package/blz-rds/commands/core/in.js +9 -0
- package/blz-rds/commands/core/integer.js +8 -0
- package/blz-rds/commands/core/is-not-null.js +11 -0
- package/blz-rds/commands/core/is-null-or-value.js +10 -0
- package/blz-rds/commands/core/is-null.js +11 -0
- package/blz-rds/commands/core/less-or-equal.js +9 -0
- package/blz-rds/commands/core/less-unary.js +12 -0
- package/blz-rds/commands/core/less.js +9 -0
- package/blz-rds/commands/core/like.js +12 -0
- package/blz-rds/commands/core/max.js +10 -0
- package/blz-rds/commands/core/min.js +10 -0
- package/blz-rds/commands/core/multiply.js +13 -0
- package/blz-rds/commands/core/not-equals.js +9 -0
- package/blz-rds/commands/core/not-in.js +9 -0
- package/blz-rds/commands/core/not.js +13 -0
- package/blz-rds/commands/core/null.js +8 -0
- package/blz-rds/commands/core/nvl.js +11 -0
- package/blz-rds/commands/core/or.js +13 -0
- package/blz-rds/commands/core/parameter.js +34 -0
- package/blz-rds/commands/core/remainder.js +16 -0
- package/blz-rds/commands/core/string.js +8 -0
- package/blz-rds/commands/core/subtract.js +13 -0
- package/blz-rds/commands/core/sum.js +10 -0
- package/blz-rds/commands/core/true.js +8 -0
- package/blz-rds/commands/core/tuple.js +13 -0
- package/blz-rds/commands/datetimes/add-days.js +11 -0
- package/blz-rds/commands/datetimes/add-hours.js +11 -0
- package/blz-rds/commands/datetimes/add-milliseconds.js +11 -0
- package/blz-rds/commands/datetimes/add-minutes.js +11 -0
- package/blz-rds/commands/datetimes/add-months.js +11 -0
- package/blz-rds/commands/datetimes/add-seconds.js +11 -0
- package/blz-rds/commands/datetimes/add-years.js +11 -0
- package/blz-rds/commands/datetimes/date-diff.js +11 -0
- package/blz-rds/commands/datetimes/date.js +12 -0
- package/blz-rds/commands/datetimes/datetime-diff.js +11 -0
- package/blz-rds/commands/datetimes/datetime.js +15 -0
- package/blz-rds/commands/datetimes/day.js +10 -0
- package/blz-rds/commands/datetimes/hour.js +10 -0
- package/blz-rds/commands/datetimes/millisecond.js +10 -0
- package/blz-rds/commands/datetimes/minute.js +10 -0
- package/blz-rds/commands/datetimes/month-text.js +10 -0
- package/blz-rds/commands/datetimes/month.js +10 -0
- package/blz-rds/commands/datetimes/now.js +9 -0
- package/blz-rds/commands/datetimes/second.js +10 -0
- package/blz-rds/commands/datetimes/subtract-days.js +11 -0
- package/blz-rds/commands/datetimes/subtract-hours.js +11 -0
- package/blz-rds/commands/datetimes/subtract-milliseconds.js +11 -0
- package/blz-rds/commands/datetimes/subtract-minutes.js +11 -0
- package/blz-rds/commands/datetimes/subtract-seconds.js +11 -0
- package/blz-rds/commands/datetimes/time-diff.js +11 -0
- package/blz-rds/commands/datetimes/time.js +13 -0
- package/blz-rds/commands/datetimes/today.js +9 -0
- package/blz-rds/commands/datetimes/week-day-text.js +10 -0
- package/blz-rds/commands/datetimes/week-day.js +10 -0
- package/blz-rds/commands/datetimes/week.js +10 -0
- package/blz-rds/commands/datetimes/year.js +10 -0
- package/blz-rds/commands/math/abs.js +10 -0
- package/blz-rds/commands/math/acos.js +10 -0
- package/blz-rds/commands/math/asin.js +10 -0
- package/blz-rds/commands/math/atan.js +10 -0
- package/blz-rds/commands/math/atan2.js +11 -0
- package/blz-rds/commands/math/ceil.js +10 -0
- package/blz-rds/commands/math/cos.js +10 -0
- package/blz-rds/commands/math/cosh.js +10 -0
- package/blz-rds/commands/math/exp.js +10 -0
- package/blz-rds/commands/math/floor.js +10 -0
- package/blz-rds/commands/math/log.js +18 -0
- package/blz-rds/commands/math/log10.js +10 -0
- package/blz-rds/commands/math/pow.js +11 -0
- package/blz-rds/commands/math/random.js +9 -0
- package/blz-rds/commands/math/round.js +18 -0
- package/blz-rds/commands/math/sign.js +10 -0
- package/blz-rds/commands/math/sin.js +10 -0
- package/blz-rds/commands/math/sinh.js +10 -0
- package/blz-rds/commands/math/sqrt.js +10 -0
- package/blz-rds/commands/math/tan.js +10 -0
- package/blz-rds/commands/math/tanh.js +10 -0
- package/blz-rds/commands/math/trunc.js +18 -0
- package/blz-rds/commands/strings/concat.js +20 -0
- package/blz-rds/commands/strings/contains.js +12 -0
- package/blz-rds/commands/strings/ends-with.js +12 -0
- package/blz-rds/commands/strings/index-of.js +11 -0
- package/blz-rds/commands/strings/is-null-or-empty.js +11 -0
- package/blz-rds/commands/strings/is-null-or-white-space.js +11 -0
- package/blz-rds/commands/strings/join.js +22 -0
- package/blz-rds/commands/strings/last-index-of.js +11 -0
- package/blz-rds/commands/strings/length.js +10 -0
- package/blz-rds/commands/strings/pad-left.js +20 -0
- package/blz-rds/commands/strings/pad-right.js +20 -0
- package/blz-rds/commands/strings/replace.js +12 -0
- package/blz-rds/commands/strings/starts-with.js +12 -0
- package/blz-rds/commands/strings/substring.js +12 -0
- package/blz-rds/commands/strings/to-lower.js +10 -0
- package/blz-rds/commands/strings/to-upper.js +10 -0
- package/blz-rds/commands/strings/trim-end.js +10 -0
- package/blz-rds/commands/strings/trim-start.js +10 -0
- package/blz-rds/commands/strings/trim.js +10 -0
- package/blz-rds/index.js +744 -0
- package/blz-rds-mysql/base.js +857 -0
- package/blz-rds-mysql/connection-manager.js +129 -0
- package/blz-rds-mysql/execute-bulk-insert.js +35 -0
- package/blz-rds-mysql/execute-bulk-merge.js +45 -0
- package/blz-rds-mysql/execute-non-query.js +34 -0
- package/blz-rds-mysql/execute-query.js +50 -0
- package/blz-rds-mysql/index.js +41 -0
- package/blz-rds-mysql/stored-procedure.js +207 -0
- package/blz-rds-mysql/syntaxis.json +114 -0
- package/blz-rds-mysqlx/base.js +846 -0
- package/blz-rds-mysqlx/connection-manager.js +141 -0
- package/blz-rds-mysqlx/execute-bulk-insert.js +35 -0
- package/blz-rds-mysqlx/execute-bulk-merge.js +45 -0
- package/blz-rds-mysqlx/execute-non-query.js +29 -0
- package/blz-rds-mysqlx/execute-query.js +39 -0
- package/blz-rds-mysqlx/index.js +41 -0
- package/blz-rds-mysqlx/stored-procedure.js +179 -0
- package/blz-rds-mysqlx/syntaxis.json +105 -0
- package/blz-rds-oracle/index.js +540 -0
- package/blz-rds-oracle/syntaxis.json +112 -0
- package/blz-rds-postgres/base.js +861 -0
- package/blz-rds-postgres/connection-manager.js +225 -0
- package/blz-rds-postgres/execute-bulk-insert.js +81 -0
- package/blz-rds-postgres/execute-bulk-merge.js +93 -0
- package/blz-rds-postgres/execute-non-query.js +23 -0
- package/blz-rds-postgres/execute-query.js +37 -0
- package/blz-rds-postgres/index.js +41 -0
- package/blz-rds-postgres/result-set.js +51 -0
- package/blz-rds-postgres/stored-procedure.js +116 -0
- package/blz-rds-postgres/syntaxis.json +114 -0
- package/blz-redis/index.js +217 -0
- package/blz-redis/lib/redisCache.js +265 -0
- package/blz-regex/index.js +25 -0
- package/blz-security/.eslintrc.js +15 -0
- package/blz-security/__test__/AuthorizationKpn.yaml +1043 -0
- package/blz-security/__test__/FinancingSetting.yaml +177 -0
- package/blz-security/__test__/KpnConfigPortal.yaml +330 -0
- package/blz-security/__test__/OrderManagement.yaml +5190 -0
- package/blz-security/__test__/Security.yaml +128 -0
- package/blz-security/__test__/autorization.test.js +105 -0
- package/blz-security/__test__/orderManagement.test.js +26 -0
- package/blz-security/__test__/secureUrl.test.js +79 -0
- package/blz-security/__test__/solveMergeRule.test.js +109 -0
- package/blz-security/__test__/sqlInjectionGuard.test.js +203 -0
- package/blz-security/__test__/xssGuard.test.js +204 -0
- package/blz-security/authorizationService.js +536 -0
- package/blz-security/config/global.js +8 -0
- package/blz-security/config/welcome +8 -0
- package/blz-security/doc/README.md +75 -0
- package/blz-security/filescanner/index.js +46 -0
- package/blz-security/helpers/consts.js +229 -0
- package/blz-security/helpers/utils.js +267 -0
- package/blz-security/implementations/cache.js +90 -0
- package/blz-security/implementations/oidc.js +404 -0
- package/blz-security/implementations/pkceCacheStore.js +23 -0
- package/blz-security/implementations/saml.js +10 -0
- package/blz-security/implementations/uma.js +63 -0
- package/blz-security/implementations/webAuthn.js +9 -0
- package/blz-security/implementations/wstg.js +72 -0
- package/blz-security/index.js +77 -0
- package/blz-security/lab/index.js +27 -0
- package/blz-security/middleware/HapiServerAzureAd.js +641 -0
- package/blz-security/middleware/HapiServerKeycloak.js +840 -0
- package/blz-security/middleware/HapiServerSimToken.js +247 -0
- package/blz-security/middleware/hapi.js +515 -0
- package/blz-security/middleware/hapiServer.js +974 -0
- package/blz-security/navigationMemoryRepository.js +15 -0
- package/blz-security/navigationMongoDbRepository.js +73 -0
- package/blz-security/secureUrlService.js +47 -0
- package/blz-security/securityService.js +409 -0
- package/blz-security/sqlInjectionGuard.js +162 -0
- package/blz-security/templates/forbidden.html +0 -0
- package/blz-security/templates/session-iframe-azure-ad.html +7 -0
- package/blz-security/templates/session-iframe.html +73 -0
- package/blz-security/templates/unauthorized.html +1 -0
- package/blz-security/xssGuard.js +87 -0
- package/blz-strings/index.js +167 -0
- package/blz-uuid/index.js +7 -0
- package/blz-yaml/index.js +19 -0
- package/index.js +84 -0
- package/package.json +97 -0
- package/process-managers/index.js +422 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
convertMilliseconds: function(strMilliseconds) {
|
|
3
|
+
if (strMilliseconds) {
|
|
4
|
+
if (strMilliseconds.length < 3)
|
|
5
|
+
strMilliseconds = strMilliseconds.padEnd(3, '0');
|
|
6
|
+
if (strMilliseconds.length > 3)
|
|
7
|
+
strMilliseconds = strMilliseconds.substr(0, 3);
|
|
8
|
+
return Number(strMilliseconds);
|
|
9
|
+
}
|
|
10
|
+
else
|
|
11
|
+
return 0;
|
|
12
|
+
},
|
|
13
|
+
tryDatetime: function (value) {
|
|
14
|
+
let strType = toString.call(value);
|
|
15
|
+
if (strType === '[object Date]') {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
else if (strType === '[object String]') {
|
|
19
|
+
let matchDatetimeUtc = /^(\d{4})-(\d{1,2})-(\d{1,2})[T,\s](\d{1,2})\:(\d{1,2})\:(\d{1,2})\.?(\d+)?Z?$/.exec(value);
|
|
20
|
+
if (matchDatetimeUtc && matchDatetimeUtc[7] !== undefined) {
|
|
21
|
+
return new Date(Date.UTC(Number(matchDatetimeUtc[1]), Number(matchDatetimeUtc[2]) - 1, Number(matchDatetimeUtc[3]), Number(matchDatetimeUtc[4]), Number(matchDatetimeUtc[5]), Number(matchDatetimeUtc[6] || 0), this.convertMilliseconds(matchDatetimeUtc[7])));
|
|
22
|
+
}
|
|
23
|
+
let matchDatetimeZone = /^(\d{4})-(\d{1,2})-(\d{1,2})[T\s](\d{1,2}):(\d{1,2}):(\d{1,2})(?:\.(\d+))?([+-]\d{2}:\d{2})?$/.exec(value);
|
|
24
|
+
if (matchDatetimeZone) { // timezone
|
|
25
|
+
let year = Number(matchDatetimeZone[1]);
|
|
26
|
+
let month = Number(matchDatetimeZone[2]) - 1; // Month is zero-based in JavaScript Date
|
|
27
|
+
let day = Number(matchDatetimeZone[3]);
|
|
28
|
+
let hour = Number(matchDatetimeZone[4]);
|
|
29
|
+
let minute = Number(matchDatetimeZone[5]);
|
|
30
|
+
let second = Number(matchDatetimeZone[6] || 0);
|
|
31
|
+
let millisecond = this.convertMilliseconds(matchDatetimeZone[7]);
|
|
32
|
+
let timezoneOffset = matchDatetimeZone[8];
|
|
33
|
+
if (timezoneOffset) {
|
|
34
|
+
let offsetSign = timezoneOffset[0] === "+" ? 1 : -1;
|
|
35
|
+
let [offsetHour, offsetMinute] = timezoneOffset.slice(1).split(":").map(Number);
|
|
36
|
+
hour -= offsetSign * offsetHour;
|
|
37
|
+
minute -= offsetSign * offsetMinute;
|
|
38
|
+
}
|
|
39
|
+
return new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const probableDate = new Date(value)
|
|
43
|
+
if (probableDate.toString() !== 'Invalid Date') {
|
|
44
|
+
return probableDate
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
let err = new Error();
|
|
49
|
+
err.code = 'InvalidDatetime';
|
|
50
|
+
err.data = { value: value };
|
|
51
|
+
throw err;
|
|
52
|
+
},
|
|
53
|
+
tryDate: function (value) {
|
|
54
|
+
let strType = toString.call(value);
|
|
55
|
+
if (strType === '[object Date]') {
|
|
56
|
+
return new Date(Date.UTC(value.getUTCFullYear(), value.getUTCMonth(), value.getUTCDate(), 0, 0, 0, 0));
|
|
57
|
+
}
|
|
58
|
+
else if (strType === '[object String]') {
|
|
59
|
+
let match = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(value);
|
|
60
|
+
if (match)
|
|
61
|
+
return new Date(Date.UTC(Number(match[1]), Number(match[2]) - 1, Number(match[3]), 0, 0, 0, 0));
|
|
62
|
+
}
|
|
63
|
+
let err = new Error();
|
|
64
|
+
err.code = 'InvalidDate';
|
|
65
|
+
err.data = { value: value };
|
|
66
|
+
throw err;
|
|
67
|
+
},
|
|
68
|
+
tryTime: function (value) {
|
|
69
|
+
let strType = toString.call(value);
|
|
70
|
+
if (strType === '[object Date]') {
|
|
71
|
+
return new Date(Date.UTC(1970, 0, 1, value.getUTCHours(), value.getUTCMinutes(), value.getUTCSeconds(), value.getUTCMilliseconds()));
|
|
72
|
+
}
|
|
73
|
+
else if (strType === '[object String]') {
|
|
74
|
+
let match = /^(\d{1,2})\:(\d{1,2})\:(\d{1,2})\.?(\d+)?$/.exec(value);
|
|
75
|
+
if (match)
|
|
76
|
+
return new Date(Date.UTC(1970, 0, 1, Number(match[1]), Number(match[2]), Number(match[3]), this.convertMilliseconds(match[4])));
|
|
77
|
+
}
|
|
78
|
+
let err = new Error();
|
|
79
|
+
err.code = 'InvalidTime';
|
|
80
|
+
err.data = { value: value };
|
|
81
|
+
throw err;
|
|
82
|
+
},
|
|
83
|
+
addDays: function (value, days) {
|
|
84
|
+
if (value === null || value === undefined)
|
|
85
|
+
return null;
|
|
86
|
+
if (days === null || days === undefined)
|
|
87
|
+
return value;
|
|
88
|
+
let datetime = this.tryDatetime(value);
|
|
89
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate() + days, datetime.getUTCHours(), datetime.getUTCMinutes(), datetime.getUTCSeconds(), datetime.getUTCMilliseconds()));
|
|
90
|
+
},
|
|
91
|
+
addHours: function (value, hours) {
|
|
92
|
+
if (value === null || value === undefined)
|
|
93
|
+
return null;
|
|
94
|
+
if (hours === null || hours === undefined)
|
|
95
|
+
return value;
|
|
96
|
+
let datetime = this.tryDatetime(value);
|
|
97
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate(), datetime.getUTCHours() + hours, datetime.getUTCMinutes(), datetime.getUTCSeconds(), datetime.getUTCMilliseconds()));
|
|
98
|
+
},
|
|
99
|
+
addMilliseconds: function (value, milliseconds) {
|
|
100
|
+
if (value === null || value === undefined)
|
|
101
|
+
return null;
|
|
102
|
+
if (milliseconds === null || milliseconds === undefined)
|
|
103
|
+
return value;
|
|
104
|
+
let datetime = this.tryDatetime(value);
|
|
105
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate(), datetime.getUTCHours(), datetime.getUTCMinutes(), datetime.getUTCSeconds(), datetime.getUTCMilliseconds() + milliseconds));
|
|
106
|
+
},
|
|
107
|
+
addMinutes: function (value, minutes) {
|
|
108
|
+
if (value === null || value === undefined)
|
|
109
|
+
return null;
|
|
110
|
+
if (minutes === null || minutes === undefined)
|
|
111
|
+
return value;
|
|
112
|
+
let datetime = this.tryDatetime(value);
|
|
113
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate(), datetime.getUTCHours(), datetime.getUTCMinutes() + minutes, datetime.getUTCSeconds(), datetime.getUTCMilliseconds()));
|
|
114
|
+
},
|
|
115
|
+
addMonths: function (value, months) {
|
|
116
|
+
if (value === null || value === undefined)
|
|
117
|
+
return null;
|
|
118
|
+
if (months === null || months === undefined)
|
|
119
|
+
return value;
|
|
120
|
+
let datetime = this.tryDatetime(value);
|
|
121
|
+
let year = datetime.getUTCFullYear();
|
|
122
|
+
let month = datetime.getUTCMonth() + months;
|
|
123
|
+
let day = datetime.getUTCDate();
|
|
124
|
+
let hour = datetime.getUTCHours();
|
|
125
|
+
let minute = datetime.getUTCMinutes();
|
|
126
|
+
let second = datetime.getUTCSeconds();
|
|
127
|
+
let millisecond = datetime.getUTCMilliseconds();
|
|
128
|
+
let targetDatetime = new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
|
|
129
|
+
while (day > targetDatetime.getUTCDate()) {
|
|
130
|
+
day--;
|
|
131
|
+
targetDatetime = new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
|
|
132
|
+
}
|
|
133
|
+
return targetDatetime;
|
|
134
|
+
},
|
|
135
|
+
addSeconds: function (value, seconds) {
|
|
136
|
+
if (value === null || value === undefined)
|
|
137
|
+
return null;
|
|
138
|
+
if (seconds === null || seconds === undefined)
|
|
139
|
+
return value;
|
|
140
|
+
let datetime = this.tryDatetime(value);
|
|
141
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate(), datetime.getUTCHours(), datetime.getUTCMinutes(), datetime.getUTCSeconds() + seconds, datetime.getUTCMilliseconds()));
|
|
142
|
+
},
|
|
143
|
+
addYears: function (value, years) {
|
|
144
|
+
if (value === null || value === undefined)
|
|
145
|
+
return null;
|
|
146
|
+
if (years === null || years === undefined)
|
|
147
|
+
return value;
|
|
148
|
+
let datetime = this.tryDatetime(value);
|
|
149
|
+
let year = datetime.getUTCFullYear() + years;
|
|
150
|
+
let month = datetime.getUTCMonth();
|
|
151
|
+
let day = datetime.getUTCDate();
|
|
152
|
+
let hour = datetime.getUTCHours();
|
|
153
|
+
let minute = datetime.getUTCMinutes();
|
|
154
|
+
let second = datetime.getUTCSeconds();
|
|
155
|
+
let millisecond = datetime.getUTCMilliseconds();
|
|
156
|
+
let targetDatetime = new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
|
|
157
|
+
while (day > targetDatetime.getUTCDate()) {
|
|
158
|
+
day--;
|
|
159
|
+
targetDatetime = new Date(Date.UTC(year, month, day, hour, minute, second, millisecond));
|
|
160
|
+
}
|
|
161
|
+
return targetDatetime;
|
|
162
|
+
},
|
|
163
|
+
date: function (year, month, day) {
|
|
164
|
+
if (year === null || year === undefined)
|
|
165
|
+
return null;
|
|
166
|
+
if (month === null ||month === undefined)
|
|
167
|
+
return null;
|
|
168
|
+
if (day === null || day === undefined)
|
|
169
|
+
return null;
|
|
170
|
+
return new Date(Date.UTC(year, month - 1, day));
|
|
171
|
+
},
|
|
172
|
+
dateDiff: function (date1, date2) {
|
|
173
|
+
if (date1 === null || date1 === undefined)
|
|
174
|
+
return null;
|
|
175
|
+
if (date2 === null || date2 === undefined)
|
|
176
|
+
return date1;
|
|
177
|
+
return (this.tryDate(date1) - this.tryDate(date2)) / 86400000;
|
|
178
|
+
},
|
|
179
|
+
datetime: function (year, month, day, hour, minute, second, milliseconds) {
|
|
180
|
+
if (year === null || year === undefined)
|
|
181
|
+
return null;
|
|
182
|
+
if (month === null ||month === undefined)
|
|
183
|
+
return null;
|
|
184
|
+
if (day === null || day === undefined)
|
|
185
|
+
return null;
|
|
186
|
+
if (hour === null || hour === undefined)
|
|
187
|
+
return null;
|
|
188
|
+
if (minute === null || minute === undefined)
|
|
189
|
+
return null;
|
|
190
|
+
if (second === null || second === undefined)
|
|
191
|
+
return null;
|
|
192
|
+
return new Date(Date.UTC(year, month - 1, day, hour, minute, second, 0));
|
|
193
|
+
},
|
|
194
|
+
datetimeDiff: function (datetime1, datetime2) {
|
|
195
|
+
if (datetime1 === null || datetime1 === undefined)
|
|
196
|
+
return null;
|
|
197
|
+
if (datetime2 === null || datetime2 === undefined)
|
|
198
|
+
return datetime1;
|
|
199
|
+
return this.tryDatetime(datetime1) - this.tryDatetime(datetime2);
|
|
200
|
+
},
|
|
201
|
+
day: function (value) {
|
|
202
|
+
if (value === null || value === undefined)
|
|
203
|
+
return null;
|
|
204
|
+
let datetime = this.tryDatetime(value);
|
|
205
|
+
return datetime.getUTCDate();
|
|
206
|
+
},
|
|
207
|
+
hour: function (value) {
|
|
208
|
+
if (value === null || value === undefined)
|
|
209
|
+
return null;
|
|
210
|
+
let datetime = this.tryDatetime(value);
|
|
211
|
+
return datetime.getUTCHours();
|
|
212
|
+
},
|
|
213
|
+
millisecond: function (value) {
|
|
214
|
+
if (value === null || value === undefined)
|
|
215
|
+
return null;
|
|
216
|
+
let datetime = this.tryDatetime(value);
|
|
217
|
+
return datetime.getUTCMilliseconds();
|
|
218
|
+
},
|
|
219
|
+
minute: function (value) {
|
|
220
|
+
if (value === null || value === undefined)
|
|
221
|
+
return null;
|
|
222
|
+
let datetime = this.tryDatetime(value);
|
|
223
|
+
return datetime.getUTCMinutes();
|
|
224
|
+
},
|
|
225
|
+
month: function (value) {
|
|
226
|
+
if (value === null || value === undefined)
|
|
227
|
+
return null;
|
|
228
|
+
let datetime = this.tryDatetime(value);
|
|
229
|
+
return datetime.getUTCMonth() + 1;
|
|
230
|
+
},
|
|
231
|
+
monthText: function (value) {
|
|
232
|
+
if (value === null || value === undefined)
|
|
233
|
+
return null;
|
|
234
|
+
let datetime = this.tryDatetime(value);
|
|
235
|
+
switch (datetime.getUTCMonth()) {
|
|
236
|
+
case 0: return 'January';
|
|
237
|
+
case 1: return 'February';
|
|
238
|
+
case 2: return 'March';
|
|
239
|
+
case 3: return 'April';
|
|
240
|
+
case 4: return 'May';
|
|
241
|
+
case 5: return 'June';
|
|
242
|
+
case 6: return 'July';
|
|
243
|
+
case 7: return 'August';
|
|
244
|
+
case 8: return 'September';
|
|
245
|
+
case 9: return 'October';
|
|
246
|
+
case 10: return 'November';
|
|
247
|
+
case 11: return 'December';
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
now: function () {
|
|
251
|
+
let now = new Date(Date.now());
|
|
252
|
+
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds()));
|
|
253
|
+
},
|
|
254
|
+
second: function (value) {
|
|
255
|
+
if (value === null || value === undefined)
|
|
256
|
+
return null;
|
|
257
|
+
let datetime = this.tryDatetime(value);
|
|
258
|
+
return datetime.getUTCSeconds();
|
|
259
|
+
},
|
|
260
|
+
subtractDays: function (value, days) {
|
|
261
|
+
if (value === null || value === undefined)
|
|
262
|
+
return null;
|
|
263
|
+
if (days === null || days === undefined)
|
|
264
|
+
return value;
|
|
265
|
+
let datetime = this.tryDatetime(value);
|
|
266
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate() - days, datetime.getUTCHours(), datetime.getUTCMinutes(), datetime.getUTCSeconds(), datetime.getUTCMilliseconds()));
|
|
267
|
+
},
|
|
268
|
+
subtractHours: function (value, hours) {
|
|
269
|
+
if (value === null || value === undefined)
|
|
270
|
+
return null;
|
|
271
|
+
if (hours === null || hours === undefined)
|
|
272
|
+
return value;
|
|
273
|
+
let datetime = this.tryDatetime(value);
|
|
274
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate(), datetime.getUTCHours() - hours, datetime.getUTCMinutes(), datetime.getUTCSeconds(), datetime.getUTCMilliseconds()));
|
|
275
|
+
},
|
|
276
|
+
subtractMilliseconds: function (value, milliseconds) {
|
|
277
|
+
if (value === null || value === undefined)
|
|
278
|
+
return null;
|
|
279
|
+
if (milliseconds === null || milliseconds === undefined)
|
|
280
|
+
return value;
|
|
281
|
+
let datetime = this.tryDatetime(value);
|
|
282
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate(), datetime.getUTCHours(), datetime.getUTCMinutes(), datetime.getUTCSeconds(), datetime.getUTCMilliseconds() - milliseconds));
|
|
283
|
+
},
|
|
284
|
+
subtractMinutes: function (value, minutes) {
|
|
285
|
+
if (value === null || value === undefined)
|
|
286
|
+
return null;
|
|
287
|
+
if (minutes === null || minutes === undefined)
|
|
288
|
+
return value;
|
|
289
|
+
let datetime = this.tryDatetime(value);
|
|
290
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate(), datetime.getUTCHours(), datetime.getUTCMinutes() - minutes, datetime.getUTCSeconds(), datetime.getUTCMilliseconds()));
|
|
291
|
+
},
|
|
292
|
+
subtractSeconds: function (value, seconds) {
|
|
293
|
+
if (value === null || value === undefined)
|
|
294
|
+
return null;
|
|
295
|
+
if (seconds === null || seconds === undefined)
|
|
296
|
+
return value;
|
|
297
|
+
let datetime = this.tryDatetime(value);
|
|
298
|
+
return new Date(Date.UTC(datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate(), datetime.getUTCHours(), datetime.getUTCMinutes(), datetime.getUTCSeconds() - seconds, datetime.getUTCMilliseconds()));
|
|
299
|
+
},
|
|
300
|
+
time: function (hour, minute, second, milliseconds) {
|
|
301
|
+
if (hour === null || hour === undefined)
|
|
302
|
+
return null;
|
|
303
|
+
if (minute === null || minute === undefined)
|
|
304
|
+
return null;
|
|
305
|
+
if (second === null || second === undefined)
|
|
306
|
+
return null;
|
|
307
|
+
return new Date(Date.UTC(1970, 0, 1, hour, minute, second, 0));
|
|
308
|
+
},
|
|
309
|
+
timeDiff: function (time1, time2) {
|
|
310
|
+
if (time1 === null || time1 === undefined)
|
|
311
|
+
return null;
|
|
312
|
+
if (time2 === null || time2 === undefined)
|
|
313
|
+
return time1;
|
|
314
|
+
return this.tryTime(time1) - this.tryTime(time2);
|
|
315
|
+
},
|
|
316
|
+
today: function () {
|
|
317
|
+
let now = new Date(Date.now());
|
|
318
|
+
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), 0, 0, 0, 0));
|
|
319
|
+
},
|
|
320
|
+
week: function (value) {
|
|
321
|
+
if (value === null || value === undefined)
|
|
322
|
+
return null;
|
|
323
|
+
let datetime = this.tryDatetime(value);
|
|
324
|
+
let d = new Date( Date.UTC( datetime.getUTCFullYear(), datetime.getUTCMonth(), datetime.getUTCDate() ) );
|
|
325
|
+
let dayNum = d.getUTCDay() || 7;
|
|
326
|
+
d.setUTCDate(d.getUTCDate() + 4 - dayNum);
|
|
327
|
+
let yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
|
|
328
|
+
return Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
|
|
329
|
+
},
|
|
330
|
+
weekDay: function (value) {
|
|
331
|
+
if (value === null || value === undefined)
|
|
332
|
+
return null;
|
|
333
|
+
let datetime = this.tryDatetime(value);
|
|
334
|
+
return datetime.getUTCDay();
|
|
335
|
+
},
|
|
336
|
+
weekDayText: function (value) {
|
|
337
|
+
if (value === null || value === undefined)
|
|
338
|
+
return null;
|
|
339
|
+
let datetime = this.tryDatetime(value);
|
|
340
|
+
switch (datetime.getUTCDay()) {
|
|
341
|
+
case 0: return 'Sunday';
|
|
342
|
+
case 1: return 'Monday';
|
|
343
|
+
case 2: return 'Tuesday';
|
|
344
|
+
case 3: return 'Wednesday';
|
|
345
|
+
case 4: return 'Thursday';
|
|
346
|
+
case 5: return 'Friday';
|
|
347
|
+
case 6: return 'Saturday';
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
year: function (value) {
|
|
351
|
+
if (value === null || value === undefined)
|
|
352
|
+
return null;
|
|
353
|
+
let datetime = this.tryDatetime(value);
|
|
354
|
+
return datetime.getUTCFullYear();
|
|
355
|
+
}
|
|
356
|
+
};
|