mat-date 1.3.77 → 1.3.81

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/dist/DateUtil.js CHANGED
@@ -1,258 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MDateUtil = void 0;
4
- const padItem = (value, len = 2) => value.toString().padStart(len, '0');
5
- class MDateUtil {
6
- val = new Date();
7
- static glCode = undefined;
8
- code = undefined;
9
- get localCode() {
10
- return this.code;
11
- }
12
- static new() {
13
- return new MDateUtil().setCode(MDateUtil.glCode);
14
- }
15
- static setCode(code) {
16
- MDateUtil.glCode = code;
17
- return this;
18
- }
19
- static seperator() {
20
- return new Date().toLocaleDateString(MDateUtil.glCode).replace(/\d/g, "").split('')[0];
21
- }
22
- copy() {
23
- return MDateUtil.new().setTime(this.toTime());
24
- }
25
- setCode(code) {
26
- this.code = code;
27
- return this;
28
- }
29
- seperator() {
30
- return new Date().toLocaleDateString(this.code).replace(/\d/g, "").split('')[0];
31
- }
32
- year() {
33
- return this.val.getFullYear();
34
- }
35
- month() {
36
- return this.val.getMonth() + 1;
37
- }
38
- monthUtc() {
39
- return this.val.getMonth();
40
- }
41
- day() {
42
- return this.val.getDate();
43
- }
44
- hours() {
45
- return this.val.getHours();
46
- }
47
- min() {
48
- return this.val.getMinutes();
49
- }
50
- sec() {
51
- return this.val.getSeconds();
52
- }
53
- dayOfWeek() {
54
- const value = this.val.getDay();
55
- return value ? value : 7;
56
- }
57
- dayOfWeekUtc() {
58
- return this.val.getDay();
59
- }
60
- setYear(value) {
61
- this.val.setFullYear(value);
62
- return this;
63
- }
64
- setMonth(value) {
65
- this.val.setMonth(value - 1);
66
- return this;
67
- }
68
- setMonthUtc(value) {
69
- this.val.setMonth(value);
70
- return this;
71
- }
72
- setDay(value) {
73
- this.val.setDate(value);
74
- return this;
75
- }
76
- setHour(value) {
77
- this.val.setHours(value);
78
- return this;
79
- }
80
- setMin(value) {
81
- this.val.setMinutes(value);
82
- return this;
83
- }
84
- setSeconds(value) {
85
- this.val.setSeconds(value);
86
- return this;
87
- }
88
- setMilliseconds(value) {
89
- this.val.setMilliseconds(value);
90
- return this;
91
- }
92
- setIsoDate(value) {
93
- this.val = new Date(value);
94
- return this;
95
- }
96
- setTime(value) {
97
- this.val = new Date(value);
98
- return this;
99
- }
100
- setDate(value) {
101
- this.val = new Date(value);
102
- return this;
103
- }
104
- setDateInputValue(value) {
105
- this.val = new Date(value);
106
- return this;
107
- }
108
- toIsoDate() {
109
- return this.val.toISOString();
110
- }
111
- toTime() {
112
- return this.val.getTime();
113
- }
114
- toDate() {
115
- return this.val;
116
- }
117
- toDateMounthInput() {
118
- return `${this.year()}-${padItem(this.month())}`;
119
- }
120
- toDateInput() {
121
- return `${this.year()}-${padItem(this.month())}-${padItem(this.day())}`;
122
- }
123
- toTimeInput() {
124
- return this.strTime();
125
- }
126
- toDateTimeInput() {
127
- return `${this.toDateInput()} ${this.toTimeInput()}`;
128
- }
129
- strDate() {
130
- return this.val.toLocaleDateString(this.code, { month: '2-digit', day: '2-digit', year: 'numeric' });
131
- }
132
- strDateLocal(options) {
133
- return this.val.toLocaleDateString(this.code, options);
134
- }
135
- strTime() {
136
- return `${padItem(this.hours())}:${padItem(this.min())}:${padItem(this.sec())}`;
137
- }
138
- strTimeLocale(options) {
139
- return this.val.toLocaleTimeString(this.code, options);
140
- }
141
- strHHmm() {
142
- return `${padItem(this.hours())}:${padItem(this.min())}`;
143
- }
144
- str() {
145
- return `${this.strDate()} ${this.strTime()}`;
146
- }
147
- strLocal(options) {
148
- return this.val.toLocaleString(this.code, options);
149
- }
150
- addDay(value) {
151
- this.val = new Date(this.val.setHours(this.val.getHours() + value * 24));
152
- return this;
153
- }
154
- addHours(value) {
155
- this.val = new Date(this.val.setHours(this.val.getHours() + value));
156
- return this;
157
- }
158
- addMins(value) {
159
- this.val = new Date(this.val.setMinutes(this.val.getMinutes() + value));
160
- return this;
161
- }
162
- startOfDay() {
163
- this.setHour(0);
164
- this.setMin(0);
165
- this.setSeconds(0);
166
- this.setMilliseconds(0);
167
- return this;
168
- }
169
- copyByStartOfDay() {
170
- return this.copy().startOfDay();
171
- }
172
- endOfDay() {
173
- this.setHour(23);
174
- this.setMin(59);
175
- this.setSeconds(59);
176
- this.setMilliseconds(999);
177
- return this;
178
- }
179
- copyByEndOfDay() {
180
- return this.copy().endOfDay();
181
- }
182
- startOfMonth() {
183
- this.setDay(1);
184
- this.startOfDay();
185
- return this;
186
- }
187
- copyByStartOfMonth() {
188
- return this.copy().startOfMonth();
189
- }
190
- endOfMonth() {
191
- this.setDate(this.val).startOfMonth().setMonth(this.month() + 1).startOfMonth().addDay(-1).endOfDay();
192
- return this;
193
- }
194
- copyByEndOfMonth() {
195
- return this.copy().endOfMonth();
196
- }
197
- static diffDays(before, after) {
198
- try {
199
- const beforeVal = parse(before);
200
- const afterVal = parse(after);
201
- return (Math.abs(beforeVal - afterVal) / 36e5) / 24;
202
- }
203
- catch (error) {
204
- throw new Error('UNKNOWN');
205
- }
206
- }
207
- static diffHours(before, after) {
208
- try {
209
- const beforeVal = parse(before);
210
- const afterVal = parse(after);
211
- return Math.abs(beforeVal - afterVal) / 36e5;
212
- }
213
- catch (error) {
214
- throw new Error('UNKNOWN');
215
- }
216
- }
217
- static diffMins(before, after) {
218
- try {
219
- const beforeVal = parse(before);
220
- const afterVal = parse(after);
221
- return (Math.abs(beforeVal - afterVal) / 1000) / 60;
222
- }
223
- catch (error) {
224
- throw new Error('UNKNOWN');
225
- }
226
- }
227
- static diffSecs(before, after) {
228
- try {
229
- const beforeVal = parse(before);
230
- const afterVal = parse(after);
231
- return (Math.abs(beforeVal - afterVal) / 1000);
232
- }
233
- catch (error) {
234
- throw new Error('UNKNOWN');
235
- }
236
- }
237
- }
238
- exports.MDateUtil = MDateUtil;
239
- function parse(before) {
240
- try {
241
- if (before instanceof MDateUtil) {
242
- return before.toTime();
243
- }
244
- if (before instanceof Date) {
245
- return before.getTime();
246
- }
247
- if (typeof before === 'number') {
248
- return before;
249
- }
250
- if (typeof before === 'string') {
251
- return new Date(before).getTime();
252
- }
253
- return 0;
254
- }
255
- catch (error) {
256
- throw new Error('ERROR');
257
- }
258
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.MDateUtil=void 0;const padItem=(value,len=2)=>value.toString().padStart(len,"0");class MDateUtil{val=new Date;static glCode=void 0;code=void 0;get localCode(){return this.code}static new(){return(new MDateUtil).setCode(MDateUtil.glCode)}static setCode(code){return MDateUtil.glCode=code,this}static seperator(){return(new Date).toLocaleDateString(MDateUtil.glCode).replace(/\d/g,"").split("")[0]}copy(){return MDateUtil.new().setTime(this.toTime())}setCode(code){return this.code=code,this}seperator(){return(new Date).toLocaleDateString(this.code).replace(/\d/g,"").split("")[0]}year(){return this.val.getFullYear()}month(){return this.val.getMonth()+1}monthUtc(){return this.val.getMonth()}day(){return this.val.getDate()}hours(){return this.val.getHours()}min(){return this.val.getMinutes()}sec(){return this.val.getSeconds()}dayOfWeek(){var value=this.val.getDay();return value||7}dayOfWeekUtc(){return this.val.getDay()}setYear(value){return this.val.setFullYear(value),this}setMonth(value){return this.val.setMonth(value-1),this}setMonthUtc(value){return this.val.setMonth(value),this}setDay(value){return this.val.setDate(value),this}setHour(value){return this.val.setHours(value),this}setMin(value){return this.val.setMinutes(value),this}setSeconds(value){return this.val.setSeconds(value),this}setMilliseconds(value){return this.val.setMilliseconds(value),this}setIsoDate(value){return this.val=new Date(value),this}setTime(value){return this.val=new Date(value),this}setDate(value){return this.val=new Date(value),this}setDateInputValue(value){return this.val=new Date(value),this}toIsoDate(){return this.val.toISOString()}toTime(){return this.val.getTime()}toDate(){return this.val}toDateMounthInput(){return this.year()+"-"+padItem(this.month())}toDateInput(){return`${this.year()}-${padItem(this.month())}-`+padItem(this.day())}toTimeInput(){return this.strTime()}toDateTimeInput(){return this.toDateInput()+" "+this.toTimeInput()}strDate(){return this.val.toLocaleDateString(this.code,{month:"2-digit",day:"2-digit",year:"numeric"})}strDateLocal(options){return this.val.toLocaleDateString(this.code,options)}strTime(){return`${padItem(this.hours())}:${padItem(this.min())}:`+padItem(this.sec())}strTimeLocale(options){return this.val.toLocaleTimeString(this.code,options)}strHHmm(){return padItem(this.hours())+":"+padItem(this.min())}str(){return this.strDate()+" "+this.strTime()}strLocal(options){return this.val.toLocaleString(this.code,options)}addDay(value){return this.val=new Date(this.val.setHours(this.val.getHours()+24*value)),this}addHours(value){return this.val=new Date(this.val.setHours(this.val.getHours()+value)),this}addMins(value){return this.val=new Date(this.val.setMinutes(this.val.getMinutes()+value)),this}startOfDay(){return this.setHour(0),this.setMin(0),this.setSeconds(0),this.setMilliseconds(0),this}copyByStartOfDay(){return this.copy().startOfDay()}endOfDay(){return this.setHour(23),this.setMin(59),this.setSeconds(59),this.setMilliseconds(999),this}copyByEndOfDay(){return this.copy().endOfDay()}startOfMonth(){return this.setDay(1),this.startOfDay(),this}copyByStartOfMonth(){return this.copy().startOfMonth()}endOfMonth(){return this.setDate(this.val).startOfMonth().setMonth(this.month()+1).startOfMonth().addDay(-1).endOfDay(),this}copyByEndOfMonth(){return this.copy().endOfMonth()}static diffDays(before,after){try{var beforeVal=parse(before),afterVal=parse(after);return Math.abs(beforeVal-afterVal)/36e5/24}catch(error){throw new Error("UNKNOWN")}}static diffHours(before,after){try{var beforeVal=parse(before),afterVal=parse(after);return Math.abs(beforeVal-afterVal)/36e5}catch(error){throw new Error("UNKNOWN")}}static diffMins(before,after){try{var beforeVal=parse(before),afterVal=parse(after);return Math.abs(beforeVal-afterVal)/1e3/60}catch(error){throw new Error("UNKNOWN")}}static diffSecs(before,after){try{var beforeVal=parse(before),afterVal=parse(after);return Math.abs(beforeVal-afterVal)/1e3}catch(error){throw new Error("UNKNOWN")}}}function parse(before){try{return before instanceof MDateUtil?before.toTime():before instanceof Date?before.getTime():"number"==typeof before?before:"string"==typeof before?new Date(before).getTime():0}catch(error){throw new Error("ERROR")}}exports.MDateUtil=MDateUtil;
package/dist/index.js CHANGED
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./DateUtil"), exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(o,m,k,k2){void 0===k2&&(k2=k);var desc=Object.getOwnPropertyDescriptor(m,k);desc&&("get"in desc?m.__esModule:!desc.writable&&!desc.configurable)||(desc={enumerable:!0,get:function(){return m[k]}}),Object.defineProperty(o,k2,desc)}:function(o,m,k,k2){o[k2=void 0===k2?k:k2]=m[k]}),__exportStar=this&&this.__exportStar||function(m,exports){for(var p in m)"default"===p||Object.prototype.hasOwnProperty.call(exports,p)||__createBinding(exports,m,p)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./DateUtil"),exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mat-date",
3
- "version": "1.3.77",
3
+ "version": "1.3.81",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",