namirasoft-core 1.5.2 → 1.5.3

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.
Files changed (57) hide show
  1. package/SKILL.md +223 -223
  2. package/dist/TimeOperation.d.ts +1 -0
  3. package/dist/TimeOperation.js +4 -0
  4. package/dist/TimeOperation.js.map +1 -1
  5. package/package.json +26 -26
  6. package/src/BaseDatabaseRow.ts +6 -6
  7. package/src/BaseLogger.ts +24 -24
  8. package/src/BaseMetaColumn.ts +17 -17
  9. package/src/BaseMetaDatabase.ts +30 -30
  10. package/src/BaseMetaTable.ts +40 -40
  11. package/src/BaseServer.ts +150 -150
  12. package/src/BaseUUID.ts +76 -76
  13. package/src/ByteOperation.ts +57 -57
  14. package/src/CacheService.ts +76 -76
  15. package/src/ColorOperation.ts +153 -153
  16. package/src/ConsoleOperation.ts +68 -68
  17. package/src/ConvertService.ts +123 -123
  18. package/src/CookieService.ts +33 -33
  19. package/src/Countries.ts +486 -486
  20. package/src/Country.ts +21 -21
  21. package/src/CountryOperation.ts +98 -98
  22. package/src/CronOperation.ts +121 -121
  23. package/src/EncodingOperation.ts +46 -46
  24. package/src/EnvService.ts +28 -28
  25. package/src/ErrorOperation.ts +13 -13
  26. package/src/FileOperation.ts +60 -60
  27. package/src/FilterItem.ts +117 -117
  28. package/src/FilterItemColumnType.ts +9 -9
  29. package/src/FilterItemOperator.ts +52 -52
  30. package/src/GeoOperation.ts +18 -18
  31. package/src/HTTPError.ts +8 -8
  32. package/src/HTTPMethod.ts +7 -7
  33. package/src/HashOperation.ts +24 -24
  34. package/src/ILogger.ts +17 -17
  35. package/src/IStorage.ts +5 -5
  36. package/src/IStorageCookie.ts +52 -52
  37. package/src/IStorageJsonFile.ts +45 -45
  38. package/src/IStorageLocal.ts +16 -16
  39. package/src/IStorageMemoryDedicated.ts +17 -17
  40. package/src/IStorageMemoryShared.ts +21 -21
  41. package/src/IStorageSession.ts +16 -16
  42. package/src/LogLevel.ts +11 -11
  43. package/src/NamingConvention.ts +199 -199
  44. package/src/ObjectService.ts +27 -27
  45. package/src/PackageService.ts +76 -76
  46. package/src/PasswordOperation.ts +12 -12
  47. package/src/PhoneOperation.ts +8 -8
  48. package/src/PriceOperation.ts +20 -20
  49. package/src/SearchOperation.ts +31 -31
  50. package/src/SetTimeouService.ts +32 -32
  51. package/src/SortItem.ts +88 -88
  52. package/src/StringOperation.ts +22 -22
  53. package/src/TimeOperation.ts +303 -299
  54. package/src/TimeUnitOperation.ts +82 -82
  55. package/src/URLOperation.ts +66 -66
  56. package/src/VersionOperation.ts +46 -46
  57. package/src/index.ts +52 -52
@@ -1,300 +1,304 @@
1
- import moment from "moment";
2
-
3
-
4
- export type YMD = { year: number, month: number, day: number };
5
- export type DateInterval = { start_date: Date, end_date: Date };
6
- export class TimeOperation
7
- {
8
- static toDBFormat(date: Date): string
9
- {
10
- return date.toISOString().
11
- replace(/T/, ' ').
12
- replace(/\..+/, '');
13
- }
14
- static format(date: Date, format: string): string
15
- {
16
- return moment(date).format(format);
17
- }
18
- static toDate(year: number, month: number, day: number): Date
19
- {
20
- return new Date(`${year}/${month}/${day}`);
21
- }
22
- static toDateByWeek(year: number, week: number, firstDay: number): Date
23
- {
24
- if (!firstDay)
25
- firstDay = 0;
26
- let offset = new Date(year, 0, 1).getDay();
27
- return new Date(year, 0, 1 + firstDay - offset + (week - 1) * 7, 0, 0, 0, 0);
28
- }
29
- static fromDate(date: Date): YMD
30
- {
31
- let year = this.yearNumber(date);
32
- let month = this.monthNumber(date);
33
- let day = this.dayNumber(date);
34
- return { year, month, day };
35
- }
36
- static getLARange(date: Date): DateInterval
37
- {
38
- let start_date = this.hoursLater(8, date);
39
- let end_date = this.daysLater(1, start_date);
40
- return {
41
- start_date,
42
- end_date
43
- };
44
- }
45
- static diffInSecond(t1: Date, t2: Date, abs: boolean): number
46
- {
47
- let ans = (t1.getTime() - t2.getTime()) / 1000;
48
- if (abs)
49
- ans = Math.abs(ans);
50
- return ans;
51
- }
52
- static diffInMinute(t1: Date, t2: Date, abs: boolean): number
53
- {
54
- return this.diffInSecond(t1, t2, abs) / 60;
55
- }
56
- //year
57
- static yearNumber(date: Date | null = null): number
58
- {
59
- if (!date)
60
- date = new Date();
61
- return date.getUTCFullYear();
62
- }
63
- static beginningOfYear(date: Date | null = null): Date
64
- {
65
- date = this.beginningOfMonth(date);
66
- date.setUTCMonth(0);
67
- return date;
68
- }
69
- //month
70
- static monthNumber(date: Date | null = null): number
71
- {
72
- if (!date)
73
- date = new Date();
74
- return date.getUTCMonth() + 1;
75
- }
76
- static beginningOfMonth(date: Date | null = null): Date
77
- {
78
- date = this.beginningOfDay(date);
79
- date.setUTCDate(1);
80
- return date;
81
- }
82
- static endOfMonth(date: Date | null = null): Date
83
- {
84
- date = this.beginningOfMonth(date);
85
- date = this.monthsLater(1, date);
86
- date = this.secondsAgo(1, date);
87
- return date;
88
- }
89
- //week
90
- static weekNumber(date: Date | null = null): number
91
- {
92
- if (!date)
93
- date = new Date();
94
- let first = this.beginningOfYear(date);
95
- let secs = this.diffInSecond(date, first, true);
96
- return (secs / 60 / 60 / 24 / 7) + 1;
97
- }
98
- static beginningOfWeek(date: Date | null = null): Date
99
- {
100
- date = this.beginningOfDay(date);
101
- let day = (date.getDay() - 1) % 7;
102
- return this.daysAgo(day, date);
103
- }
104
- static endOfWeek(date: Date | null = null): Date
105
- {
106
- date = this.beginningOfWeek(date);
107
- return this.secondsAgo(1, this.daysLater(7, date));
108
- }
109
- // day
110
- static dayNumber(date: Date | null = null): number
111
- {
112
- if (!date)
113
- date = new Date();
114
- return date.getUTCDate();
115
- }
116
- static beginningOfDay(date: Date | null = null): Date
117
- {
118
- date = this.beginningOfHour(date);
119
- date.setUTCHours(0);
120
- return date;
121
- }
122
- static endOfDay(date: Date | null = null): Date
123
- {
124
- date = this.beginningOfDay(date);
125
- return this.daysLater(1, date);
126
- }
127
- static dayNumberInYear(date: Date | null = null): number
128
- {
129
- if (!date)
130
- date = new Date();
131
- var start = new Date(date.getFullYear(), 0, 0);
132
- var diff = date.getTime() - start.getTime();
133
- var oneDay = 1000 * 60 * 60 * 24;
134
- return Math.floor(diff / oneDay);
135
- }
136
- static addedDaysInMonth(days: number, date: Date): Date
137
- {
138
- date = this.beginningOfMonth(date);
139
- return this.daysLater(days, date);
140
- }
141
- //hour
142
- static hourNumberInWeek(date: Date | null = null): number
143
- {
144
- if (!date)
145
- date = new Date();
146
- let first = this.beginningOfWeek(date);
147
- let secs = this.diffInSecond(date, first, true);
148
- return (secs / 3600);
149
- }
150
- static hourNumberInMonth(date: Date | null = null): number
151
- {
152
- if (!date)
153
- date = new Date();
154
- let first = this.beginningOfMonth(date);
155
- let secs = this.diffInSecond(date, first, true);
156
- return (secs / 3600);
157
- }
158
- static addedHoursInWeek(hours: number, date: Date): Date
159
- {
160
- date = this.beginningOfWeek(date);
161
- return this.hoursLater(hours, date);
162
- }
163
- static beginningOfHour(date: Date | null = null): Date
164
- {
165
- if (!date)
166
- date = new Date();
167
- else
168
- date = new Date(date);
169
- date.setUTCMilliseconds(0);
170
- date.setUTCSeconds(0);
171
- date.setUTCMinutes(0);
172
- return date;
173
- }
174
- // ago
175
- static yearsAgo(years: number, date: Date): Date
176
- {
177
- return this.yearsLater(years * -1, date);
178
- }
179
- static monthsAgo(months: number, date: Date): Date
180
- {
181
- return this.monthsLater(months * -1, date);
182
- }
183
- static weeksAgo(weeks: number, date: Date): Date
184
- {
185
- return this.weeksLater(weeks * -1, date);
186
- }
187
- static daysAgo(days: number, date: Date): Date
188
- {
189
- return this.daysLater(days * -1, date);
190
- }
191
- static hoursAgo(hours: number, date: Date): Date
192
- {
193
- return this.hoursLater(hours * -1, date);
194
- }
195
- static minutesAgo(minutes: number, date: Date): Date
196
- {
197
- return this.minutesLater(minutes * -1, date);
198
- }
199
- static secondsAgo(seconds: number, date: Date): Date
200
- {
201
- return this.secondsLater(seconds * -1, date);
202
- }
203
- static millisecondsAgo(milliseconds: number, date: Date): Date
204
- {
205
- return this.millisecondsLater(milliseconds * -1, date);
206
- }
207
- // later
208
- static later(num: number, type: moment.DurationInputArg2, date: Date | null = null): Date
209
- {
210
- if (!date)
211
- date = new Date();
212
- else
213
- date = new Date(date);
214
- return moment(date).add(num, type).toDate();
215
- }
216
- static yearsLater(years: number, date: Date): Date
217
- {
218
- return this.later(years, 'years', date);
219
- }
220
- static monthsLater(months: number, date: Date): Date
221
- {
222
- return this.later(months, 'months', date);
223
- }
224
- static weeksLater(weeks: number, date: Date): Date
225
- {
226
- return this.later(weeks, 'weeks', date);
227
- }
228
- static daysLater(days: number, date: Date): Date
229
- {
230
- return this.later(days, 'days', date);
231
- }
232
- static hoursLater(hours: number, date: Date): Date
233
- {
234
- return this.later(hours, 'hours', date);
235
- }
236
- static minutesLater(minutes: number, date: Date): Date
237
- {
238
- return this.later(minutes, 'minutes', date);
239
- }
240
- static secondsLater(seconds: number, date: Date): Date
241
- {
242
- return this.later(seconds, 'seconds', date);
243
- }
244
- static millisecondsLater(milliseconds: number, date: Date): Date
245
- {
246
- return this.later(milliseconds, 'milliseconds', date);
247
- }
248
- static getDuration(startDate: Date, endDate: Date, zeroAllOnPassed: boolean = false)
249
- {
250
- if (!endDate)
251
- endDate = new Date();
252
- let s = moment(startDate);
253
- let e = moment(endDate);
254
- let passed = e < s;
255
- let year = e.diff(s, 'years', false);
256
- s.add(year, 'years');
257
- let month = e.diff(s, 'months', false);
258
- s.add(month, 'months');
259
- let day = e.diff(s, 'days', false);
260
- s.add(day, 'days');
261
- let hour = e.diff(s, 'hours', false);
262
- s.add(hour, 'hours');
263
- let minute = e.diff(s, 'minutes', false);
264
- s.add(minute, 'minutes');
265
- let second = e.diff(s, 'seconds', false);
266
- s.add(second, 'seconds');
267
-
268
- if (passed)
269
- if (zeroAllOnPassed)
270
- year = month = day = hour = minute = second = 0;
271
- let total = year * 12 + month;
272
- total = total * 30 + day;
273
- total = total * 24 + hour;
274
- total = total * 60 + minute;
275
- total += second;
276
-
277
- return {
278
- passed, year, month, day, hour, minute, second, total
279
- };
280
- }
281
- static calculateAge(date: Date): number
282
- {
283
- let birthday = new Date(date);
284
- let ageDifMs = Date.now() - birthday.getTime();
285
- var ageDate = new Date(ageDifMs); // miliseconds from epoch
286
- return Math.abs(ageDate.getUTCFullYear() - 1970);
287
- }
288
- static isValidDate(value: string): boolean
289
- {
290
- return moment(value).isValid();
291
- }
292
- static isValidDateTime(value: string): boolean
293
- {
294
- return moment(value).isValid();
295
- }
296
- static isValidTime(value: string): boolean
297
- {
298
- return moment(value).isValid();
299
- }
1
+ import moment from "moment";
2
+
3
+ export type YMD = { year: number, month: number, day: number };
4
+ export type DateInterval = { start_date: Date, end_date: Date };
5
+
6
+ export class TimeOperation
7
+ {
8
+ static MONTH_NAMES = [
9
+ "January", "February", "March", "April", "May", "June",
10
+ "July", "August", "September", "October", "November", "December"
11
+ ];
12
+ static toDBFormat(date: Date): string
13
+ {
14
+ return date.toISOString().
15
+ replace(/T/, ' ').
16
+ replace(/\..+/, '');
17
+ }
18
+ static format(date: Date, format: string): string
19
+ {
20
+ return moment(date).format(format);
21
+ }
22
+ static toDate(year: number, month: number, day: number): Date
23
+ {
24
+ return new Date(`${year}/${month}/${day}`);
25
+ }
26
+ static toDateByWeek(year: number, week: number, firstDay: number): Date
27
+ {
28
+ if (!firstDay)
29
+ firstDay = 0;
30
+ let offset = new Date(year, 0, 1).getDay();
31
+ return new Date(year, 0, 1 + firstDay - offset + (week - 1) * 7, 0, 0, 0, 0);
32
+ }
33
+ static fromDate(date: Date): YMD
34
+ {
35
+ let year = this.yearNumber(date);
36
+ let month = this.monthNumber(date);
37
+ let day = this.dayNumber(date);
38
+ return { year, month, day };
39
+ }
40
+ static getLARange(date: Date): DateInterval
41
+ {
42
+ let start_date = this.hoursLater(8, date);
43
+ let end_date = this.daysLater(1, start_date);
44
+ return {
45
+ start_date,
46
+ end_date
47
+ };
48
+ }
49
+ static diffInSecond(t1: Date, t2: Date, abs: boolean): number
50
+ {
51
+ let ans = (t1.getTime() - t2.getTime()) / 1000;
52
+ if (abs)
53
+ ans = Math.abs(ans);
54
+ return ans;
55
+ }
56
+ static diffInMinute(t1: Date, t2: Date, abs: boolean): number
57
+ {
58
+ return this.diffInSecond(t1, t2, abs) / 60;
59
+ }
60
+ //year
61
+ static yearNumber(date: Date | null = null): number
62
+ {
63
+ if (!date)
64
+ date = new Date();
65
+ return date.getUTCFullYear();
66
+ }
67
+ static beginningOfYear(date: Date | null = null): Date
68
+ {
69
+ date = this.beginningOfMonth(date);
70
+ date.setUTCMonth(0);
71
+ return date;
72
+ }
73
+ //month
74
+ static monthNumber(date: Date | null = null): number
75
+ {
76
+ if (!date)
77
+ date = new Date();
78
+ return date.getUTCMonth() + 1;
79
+ }
80
+ static beginningOfMonth(date: Date | null = null): Date
81
+ {
82
+ date = this.beginningOfDay(date);
83
+ date.setUTCDate(1);
84
+ return date;
85
+ }
86
+ static endOfMonth(date: Date | null = null): Date
87
+ {
88
+ date = this.beginningOfMonth(date);
89
+ date = this.monthsLater(1, date);
90
+ date = this.secondsAgo(1, date);
91
+ return date;
92
+ }
93
+ //week
94
+ static weekNumber(date: Date | null = null): number
95
+ {
96
+ if (!date)
97
+ date = new Date();
98
+ let first = this.beginningOfYear(date);
99
+ let secs = this.diffInSecond(date, first, true);
100
+ return (secs / 60 / 60 / 24 / 7) + 1;
101
+ }
102
+ static beginningOfWeek(date: Date | null = null): Date
103
+ {
104
+ date = this.beginningOfDay(date);
105
+ let day = (date.getDay() - 1) % 7;
106
+ return this.daysAgo(day, date);
107
+ }
108
+ static endOfWeek(date: Date | null = null): Date
109
+ {
110
+ date = this.beginningOfWeek(date);
111
+ return this.secondsAgo(1, this.daysLater(7, date));
112
+ }
113
+ // day
114
+ static dayNumber(date: Date | null = null): number
115
+ {
116
+ if (!date)
117
+ date = new Date();
118
+ return date.getUTCDate();
119
+ }
120
+ static beginningOfDay(date: Date | null = null): Date
121
+ {
122
+ date = this.beginningOfHour(date);
123
+ date.setUTCHours(0);
124
+ return date;
125
+ }
126
+ static endOfDay(date: Date | null = null): Date
127
+ {
128
+ date = this.beginningOfDay(date);
129
+ return this.daysLater(1, date);
130
+ }
131
+ static dayNumberInYear(date: Date | null = null): number
132
+ {
133
+ if (!date)
134
+ date = new Date();
135
+ var start = new Date(date.getFullYear(), 0, 0);
136
+ var diff = date.getTime() - start.getTime();
137
+ var oneDay = 1000 * 60 * 60 * 24;
138
+ return Math.floor(diff / oneDay);
139
+ }
140
+ static addedDaysInMonth(days: number, date: Date): Date
141
+ {
142
+ date = this.beginningOfMonth(date);
143
+ return this.daysLater(days, date);
144
+ }
145
+ //hour
146
+ static hourNumberInWeek(date: Date | null = null): number
147
+ {
148
+ if (!date)
149
+ date = new Date();
150
+ let first = this.beginningOfWeek(date);
151
+ let secs = this.diffInSecond(date, first, true);
152
+ return (secs / 3600);
153
+ }
154
+ static hourNumberInMonth(date: Date | null = null): number
155
+ {
156
+ if (!date)
157
+ date = new Date();
158
+ let first = this.beginningOfMonth(date);
159
+ let secs = this.diffInSecond(date, first, true);
160
+ return (secs / 3600);
161
+ }
162
+ static addedHoursInWeek(hours: number, date: Date): Date
163
+ {
164
+ date = this.beginningOfWeek(date);
165
+ return this.hoursLater(hours, date);
166
+ }
167
+ static beginningOfHour(date: Date | null = null): Date
168
+ {
169
+ if (!date)
170
+ date = new Date();
171
+ else
172
+ date = new Date(date);
173
+ date.setUTCMilliseconds(0);
174
+ date.setUTCSeconds(0);
175
+ date.setUTCMinutes(0);
176
+ return date;
177
+ }
178
+ // ago
179
+ static yearsAgo(years: number, date: Date): Date
180
+ {
181
+ return this.yearsLater(years * -1, date);
182
+ }
183
+ static monthsAgo(months: number, date: Date): Date
184
+ {
185
+ return this.monthsLater(months * -1, date);
186
+ }
187
+ static weeksAgo(weeks: number, date: Date): Date
188
+ {
189
+ return this.weeksLater(weeks * -1, date);
190
+ }
191
+ static daysAgo(days: number, date: Date): Date
192
+ {
193
+ return this.daysLater(days * -1, date);
194
+ }
195
+ static hoursAgo(hours: number, date: Date): Date
196
+ {
197
+ return this.hoursLater(hours * -1, date);
198
+ }
199
+ static minutesAgo(minutes: number, date: Date): Date
200
+ {
201
+ return this.minutesLater(minutes * -1, date);
202
+ }
203
+ static secondsAgo(seconds: number, date: Date): Date
204
+ {
205
+ return this.secondsLater(seconds * -1, date);
206
+ }
207
+ static millisecondsAgo(milliseconds: number, date: Date): Date
208
+ {
209
+ return this.millisecondsLater(milliseconds * -1, date);
210
+ }
211
+ // later
212
+ static later(num: number, type: moment.DurationInputArg2, date: Date | null = null): Date
213
+ {
214
+ if (!date)
215
+ date = new Date();
216
+ else
217
+ date = new Date(date);
218
+ return moment(date).add(num, type).toDate();
219
+ }
220
+ static yearsLater(years: number, date: Date): Date
221
+ {
222
+ return this.later(years, 'years', date);
223
+ }
224
+ static monthsLater(months: number, date: Date): Date
225
+ {
226
+ return this.later(months, 'months', date);
227
+ }
228
+ static weeksLater(weeks: number, date: Date): Date
229
+ {
230
+ return this.later(weeks, 'weeks', date);
231
+ }
232
+ static daysLater(days: number, date: Date): Date
233
+ {
234
+ return this.later(days, 'days', date);
235
+ }
236
+ static hoursLater(hours: number, date: Date): Date
237
+ {
238
+ return this.later(hours, 'hours', date);
239
+ }
240
+ static minutesLater(minutes: number, date: Date): Date
241
+ {
242
+ return this.later(minutes, 'minutes', date);
243
+ }
244
+ static secondsLater(seconds: number, date: Date): Date
245
+ {
246
+ return this.later(seconds, 'seconds', date);
247
+ }
248
+ static millisecondsLater(milliseconds: number, date: Date): Date
249
+ {
250
+ return this.later(milliseconds, 'milliseconds', date);
251
+ }
252
+ static getDuration(startDate: Date, endDate: Date, zeroAllOnPassed: boolean = false)
253
+ {
254
+ if (!endDate)
255
+ endDate = new Date();
256
+ let s = moment(startDate);
257
+ let e = moment(endDate);
258
+ let passed = e < s;
259
+ let year = e.diff(s, 'years', false);
260
+ s.add(year, 'years');
261
+ let month = e.diff(s, 'months', false);
262
+ s.add(month, 'months');
263
+ let day = e.diff(s, 'days', false);
264
+ s.add(day, 'days');
265
+ let hour = e.diff(s, 'hours', false);
266
+ s.add(hour, 'hours');
267
+ let minute = e.diff(s, 'minutes', false);
268
+ s.add(minute, 'minutes');
269
+ let second = e.diff(s, 'seconds', false);
270
+ s.add(second, 'seconds');
271
+
272
+ if (passed)
273
+ if (zeroAllOnPassed)
274
+ year = month = day = hour = minute = second = 0;
275
+ let total = year * 12 + month;
276
+ total = total * 30 + day;
277
+ total = total * 24 + hour;
278
+ total = total * 60 + minute;
279
+ total += second;
280
+
281
+ return {
282
+ passed, year, month, day, hour, minute, second, total
283
+ };
284
+ }
285
+ static calculateAge(date: Date): number
286
+ {
287
+ let birthday = new Date(date);
288
+ let ageDifMs = Date.now() - birthday.getTime();
289
+ var ageDate = new Date(ageDifMs); // miliseconds from epoch
290
+ return Math.abs(ageDate.getUTCFullYear() - 1970);
291
+ }
292
+ static isValidDate(value: string): boolean
293
+ {
294
+ return moment(value).isValid();
295
+ }
296
+ static isValidDateTime(value: string): boolean
297
+ {
298
+ return moment(value).isValid();
299
+ }
300
+ static isValidTime(value: string): boolean
301
+ {
302
+ return moment(value).isValid();
303
+ }
300
304
  }