@dxtmisha/functional-basic 0.1.0 → 0.1.1
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/package.json +5 -3
- package/src/classes/Api.ts +407 -0
- package/src/classes/ApiDefault.ts +83 -0
- package/src/classes/ApiHeaders.ts +52 -0
- package/src/classes/ApiPreparation.ts +114 -0
- package/src/classes/ApiResponse.ts +293 -0
- package/src/classes/ApiStatus.ts +173 -0
- package/src/classes/BroadcastMessage.ts +73 -0
- package/src/classes/Cache.ts +60 -0
- package/src/classes/CacheItem.ts +95 -0
- package/src/classes/CacheStatic.ts +30 -0
- package/src/classes/Cookie.ts +135 -0
- package/src/classes/CookieBlock.ts +31 -0
- package/src/classes/DataStorage.ts +194 -0
- package/src/classes/Datetime.ts +891 -0
- package/src/classes/EventItem.ts +373 -0
- package/src/classes/Geo.ts +320 -0
- package/src/classes/GeoFlag.ts +386 -0
- package/src/classes/GeoIntl.ts +839 -0
- package/src/classes/GeoPhone.ts +272 -0
- package/src/classes/Global.ts +32 -0
- package/src/classes/Hash.ts +142 -0
- package/src/classes/Icons.ts +165 -0
- package/src/classes/Loading.ts +90 -0
- package/src/classes/Meta.ts +284 -0
- package/src/classes/MetaManager.ts +200 -0
- package/src/classes/MetaOg.ts +147 -0
- package/src/classes/MetaTwitter.ts +154 -0
- package/src/classes/ScrollbarWidth.ts +86 -0
- package/src/classes/Translate.ts +293 -0
- package/src/classes/__tests__/Api.test.ts +728 -0
- package/src/classes/__tests__/ApiDefault.test.ts +222 -0
- package/src/classes/__tests__/ApiHeaders.test.ts +447 -0
- package/src/classes/__tests__/ApiPreparation.test.ts +257 -0
- package/src/classes/__tests__/ApiResponse.test.ts +547 -0
- package/src/classes/__tests__/ApiStatus.test.ts +403 -0
- package/src/classes/__tests__/Meta.test.ts +629 -0
- package/src/classes/__tests__/MetaManager.test.ts +836 -0
- package/src/classes/__tests__/MetaOg.test.ts +677 -0
- package/src/classes/__tests__/MetaTwitter.test.ts +423 -0
- package/src/functions/anyToString.ts +36 -0
- package/src/functions/applyTemplate.ts +63 -0
- package/src/functions/arrFill.ts +10 -0
- package/src/functions/copyObject.ts +10 -0
- package/src/functions/createElement.ts +40 -0
- package/src/functions/domQuerySelector.ts +15 -0
- package/src/functions/domQuerySelectorAll.ts +15 -0
- package/src/functions/encodeAttribute.ts +15 -0
- package/src/functions/eventStopPropagation.ts +10 -0
- package/src/functions/executeFunction.ts +13 -0
- package/src/functions/executePromise.ts +19 -0
- package/src/functions/forEach.ts +39 -0
- package/src/functions/frame.ts +38 -0
- package/src/functions/getAttributes.ts +27 -0
- package/src/functions/getClipboardData.ts +13 -0
- package/src/functions/getColumn.ts +18 -0
- package/src/functions/getElement.ts +35 -0
- package/src/functions/getElementId.ts +39 -0
- package/src/functions/getElementItem.ts +27 -0
- package/src/functions/getElementOrWindow.ts +23 -0
- package/src/functions/getExp.ts +21 -0
- package/src/functions/getItemByPath.ts +24 -0
- package/src/functions/getKey.ts +9 -0
- package/src/functions/getLengthOfAllArray.ts +13 -0
- package/src/functions/getMaxLengthAllArray.ts +13 -0
- package/src/functions/getMinLengthAllArray.ts +13 -0
- package/src/functions/getMouseClient.ts +17 -0
- package/src/functions/getMouseClientX.ts +9 -0
- package/src/functions/getMouseClientY.ts +9 -0
- package/src/functions/getObjectByKeys.ts +24 -0
- package/src/functions/getObjectNoUndefined.ts +23 -0
- package/src/functions/getObjectOrNone.ts +11 -0
- package/src/functions/getRandomText.ts +29 -0
- package/src/functions/getRequestString.ts +21 -0
- package/src/functions/getStepPercent.ts +19 -0
- package/src/functions/getStepValue.ts +19 -0
- package/src/functions/goScroll.ts +40 -0
- package/src/functions/inArray.ts +10 -0
- package/src/functions/initScrollbarOffset.ts +14 -0
- package/src/functions/intersectKey.ts +34 -0
- package/src/functions/isArray.ts +9 -0
- package/src/functions/isDifferent.ts +27 -0
- package/src/functions/isDomRuntime.ts +12 -0
- package/src/functions/isFilled.ts +49 -0
- package/src/functions/isFloat.ts +16 -0
- package/src/functions/isFunction.ts +11 -0
- package/src/functions/isInDom.ts +15 -0
- package/src/functions/isIntegerBetween.ts +11 -0
- package/src/functions/isNull.ts +11 -0
- package/src/functions/isNumber.ts +16 -0
- package/src/functions/isObject.ts +9 -0
- package/src/functions/isObjectNotArray.ts +11 -0
- package/src/functions/isSelected.ts +32 -0
- package/src/functions/isSelectedByList.ts +19 -0
- package/src/functions/isString.ts +9 -0
- package/src/functions/isWindow.ts +11 -0
- package/src/functions/random.ts +10 -0
- package/src/functions/replaceRecursive.ts +60 -0
- package/src/functions/replaceTemplate.ts +22 -0
- package/src/functions/secondToTime.ts +20 -0
- package/src/functions/setElementItem.ts +56 -0
- package/src/functions/setValues.ts +59 -0
- package/src/functions/splice.ts +59 -0
- package/src/functions/strFill.ts +12 -0
- package/src/functions/toArray.ts +19 -0
- package/src/functions/toCamelCase.ts +16 -0
- package/src/functions/toCamelCaseFirst.ts +12 -0
- package/src/functions/toDate.ts +44 -0
- package/src/functions/toKebabCase.ts +25 -0
- package/src/functions/toNumber.ts +35 -0
- package/src/functions/toNumberByMax.ts +33 -0
- package/src/functions/toPercent.ts +10 -0
- package/src/functions/toPercentBy100.ts +12 -0
- package/src/functions/transformation.ts +59 -0
- package/src/functions/uniqueArray.ts +9 -0
- package/src/functions/writeClipboardData.ts +17 -0
- package/src/library.ts +116 -0
- package/src/types/apiTypes.ts +143 -0
- package/src/types/basicTypes.ts +155 -0
- package/src/types/geoTypes.ts +109 -0
- package/src/types/metaTypes.ts +764 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,891 @@
|
|
|
1
|
+
import { toDate } from '../functions/toDate'
|
|
2
|
+
|
|
3
|
+
import { Geo } from './Geo'
|
|
4
|
+
import { GeoIntl } from './GeoIntl'
|
|
5
|
+
|
|
6
|
+
import { type NumberOrStringOrDate } from '../types/basicTypes'
|
|
7
|
+
import {
|
|
8
|
+
type GeoDate,
|
|
9
|
+
type GeoFirstDay,
|
|
10
|
+
type GeoHours,
|
|
11
|
+
type GeoTimeZoneStyle
|
|
12
|
+
} from '../types/geoTypes'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A class for working with dates.
|
|
16
|
+
*
|
|
17
|
+
* Класс для работы с датами.
|
|
18
|
+
*/
|
|
19
|
+
export class Datetime {
|
|
20
|
+
protected date: Date
|
|
21
|
+
protected hour24 = false
|
|
22
|
+
protected watch?: (date: Date, type: GeoDate, hour24: boolean) => void
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Constructor
|
|
26
|
+
* @param date date for processing/ дата для обработки
|
|
27
|
+
* @param type type of date format for output/ тип формата даты вывода
|
|
28
|
+
* @param code country and language code/ код страны и языка
|
|
29
|
+
*/
|
|
30
|
+
constructor(
|
|
31
|
+
date?: NumberOrStringOrDate,
|
|
32
|
+
protected type: GeoDate = 'date',
|
|
33
|
+
protected code: string = Geo.getLocation()
|
|
34
|
+
) {
|
|
35
|
+
this.date = toDate(date)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns an object for working with formatting.
|
|
40
|
+
*
|
|
41
|
+
* Возвращает объект для работы с форматированием.
|
|
42
|
+
*/
|
|
43
|
+
getIntl(): GeoIntl {
|
|
44
|
+
return new GeoIntl(this.code)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns a Date object.
|
|
49
|
+
*
|
|
50
|
+
* Возвращает объект Date.
|
|
51
|
+
*/
|
|
52
|
+
getDate(): Date {
|
|
53
|
+
return this.date
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the type of data output.
|
|
58
|
+
*
|
|
59
|
+
* Возвращает тип вывода данных.
|
|
60
|
+
*/
|
|
61
|
+
getType(): string {
|
|
62
|
+
return this.type
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Returns the format of hours.
|
|
67
|
+
*
|
|
68
|
+
* Возвращает формат часов.
|
|
69
|
+
*/
|
|
70
|
+
getHoursType(): GeoHours {
|
|
71
|
+
const date = this.clone()
|
|
72
|
+
date.setHours(23)
|
|
73
|
+
|
|
74
|
+
return date.toLocaleTimeString(this.getIntl().getLocation(), { hour: '2-digit' })
|
|
75
|
+
.match(/23/ig)
|
|
76
|
+
? '24'
|
|
77
|
+
: '12'
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Whether to use 12-hour time.
|
|
82
|
+
*
|
|
83
|
+
* Использовать ли 12-часовой формат времени.
|
|
84
|
+
*/
|
|
85
|
+
getHour24(): boolean {
|
|
86
|
+
return this.hour24
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The method returns the difference, in minutes, between
|
|
91
|
+
* a date as evaluated in the UTC time zone, and the same date as evaluated
|
|
92
|
+
* in the local time zone.
|
|
93
|
+
*
|
|
94
|
+
* Метод возвращает смещение часового пояса относительно часового пояса UTC
|
|
95
|
+
* в минутах для текущей локали.
|
|
96
|
+
*/
|
|
97
|
+
getTimeZoneOffset(): number {
|
|
98
|
+
return this.date.getTimezoneOffset()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Returns the time zone as a string.
|
|
103
|
+
*
|
|
104
|
+
* Возвращает временную зону в виде строки.
|
|
105
|
+
* @param style the style of the returned data/ стиль возвращаемых данных
|
|
106
|
+
*/
|
|
107
|
+
getTimeZone(style?: GeoTimeZoneStyle): string {
|
|
108
|
+
const offset = this.getTimeZoneOffset()
|
|
109
|
+
|
|
110
|
+
if (style === 'minute') {
|
|
111
|
+
return offset.toString()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const hour = offset / 60 * -1
|
|
115
|
+
|
|
116
|
+
if (style === 'hour') {
|
|
117
|
+
return this.getIntl()
|
|
118
|
+
.number(Math.trunc(hour), { signDisplay: 'always' })
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const numberHour = this.getIntl()
|
|
122
|
+
.number(Math.trunc(hour), {
|
|
123
|
+
signDisplay: 'always',
|
|
124
|
+
minimumIntegerDigits: 2
|
|
125
|
+
})
|
|
126
|
+
const numberMinute = hour.toString().match(/.\d+/) ? '30' : '00'
|
|
127
|
+
|
|
128
|
+
if (style === 'RFC') {
|
|
129
|
+
return `${numberHour}${numberMinute}`
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return `${numberHour}:${numberMinute}`
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Returns the code of the first day of the week.
|
|
137
|
+
*
|
|
138
|
+
* Возвращает код первого дня недели.
|
|
139
|
+
*/
|
|
140
|
+
getFirstDayCode(): GeoFirstDay {
|
|
141
|
+
const value = this.getIntl().getFirstDay()
|
|
142
|
+
|
|
143
|
+
if (value === 'Sa') {
|
|
144
|
+
return 6
|
|
145
|
+
} else if (value === 'Su') {
|
|
146
|
+
return 0
|
|
147
|
+
} else {
|
|
148
|
+
return 1
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The method returns the year of the specified date according to local time.
|
|
154
|
+
*
|
|
155
|
+
* Метод возвращает год указанной даты по местному времени.
|
|
156
|
+
*/
|
|
157
|
+
getYear(): number {
|
|
158
|
+
return this.date.getFullYear()
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The method returns the month in the specified date according to local time,
|
|
163
|
+
* as a zero-based value.
|
|
164
|
+
*
|
|
165
|
+
* Метод возвращает месяц указанной даты по местному времени, нумерация
|
|
166
|
+
* месяцев начинается с нуля для первого месяца в году.
|
|
167
|
+
*/
|
|
168
|
+
getMonth(): number {
|
|
169
|
+
return this.date.getMonth() + 1
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The method returns the day of the month for the specified date according to local time.
|
|
174
|
+
*
|
|
175
|
+
* Метод возвращает день месяца указанной даты по местному времени
|
|
176
|
+
*/
|
|
177
|
+
getDay(): number {
|
|
178
|
+
return this.date.getDate()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The method returns the hour for the specified date, according to local time.
|
|
183
|
+
*
|
|
184
|
+
* Метод возвращает часы указанной даты по местному времени.
|
|
185
|
+
*/
|
|
186
|
+
getHour(): number {
|
|
187
|
+
return this.date.getHours()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* The method returns the minutes in the specified date according to local time.
|
|
192
|
+
*
|
|
193
|
+
* Метод возвращает минуты указанной даты по местному времени.
|
|
194
|
+
*/
|
|
195
|
+
getMinute(): number {
|
|
196
|
+
return this.date.getMinutes()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The method returns the seconds in the specified date according to local time.
|
|
201
|
+
*
|
|
202
|
+
* Метод возвращает секунды указанной даты по местному времени.
|
|
203
|
+
*/
|
|
204
|
+
getSecond(): number {
|
|
205
|
+
return this.date.getSeconds()
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Returns the last day of the week.
|
|
210
|
+
*
|
|
211
|
+
* Возвращает последний день недели.
|
|
212
|
+
*/
|
|
213
|
+
getMaxDay(): number {
|
|
214
|
+
return this.getMonth() > 0 ? this.cloneDayLast().getDay() : 0
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Enables language-sensitive date and time formatting.
|
|
219
|
+
*
|
|
220
|
+
* Конструктором объектов, включающих языка-зависимое форматирование даты и времени.
|
|
221
|
+
* @param type type of date format for output/ тип формата даты вывода
|
|
222
|
+
* @param styleOptions the representation of the month/ представление месяца
|
|
223
|
+
*/
|
|
224
|
+
locale(
|
|
225
|
+
type: GeoDate = this.type,
|
|
226
|
+
styleOptions?: Intl.DateTimeFormatOptions['month'] | Intl.DateTimeFormatOptions
|
|
227
|
+
): string {
|
|
228
|
+
return this.getIntl().date(
|
|
229
|
+
this.date,
|
|
230
|
+
type,
|
|
231
|
+
styleOptions,
|
|
232
|
+
this.hour24
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Returns the formatted year.
|
|
238
|
+
*
|
|
239
|
+
* Возвращает отформатированный год.
|
|
240
|
+
* @param style the representation of the month/ представление месяца
|
|
241
|
+
*/
|
|
242
|
+
localeYear(
|
|
243
|
+
style: Intl.DateTimeFormatOptions['year'] = 'numeric'
|
|
244
|
+
): string {
|
|
245
|
+
return this.locale('year', { year: style })
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Returns the formatted month.
|
|
250
|
+
*
|
|
251
|
+
* Возвращает отформатированный месяц.
|
|
252
|
+
* @param style the representation of the month/ представление месяца
|
|
253
|
+
*/
|
|
254
|
+
localeMonth(
|
|
255
|
+
style: Intl.DateTimeFormatOptions['month'] = 'long'
|
|
256
|
+
): string {
|
|
257
|
+
return this.locale('month', { month: style })
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Returns the formatted day.
|
|
262
|
+
*
|
|
263
|
+
* Возвращает отформатированный день.
|
|
264
|
+
* @param style the representation of the month/ представление месяца
|
|
265
|
+
*/
|
|
266
|
+
localeDay(
|
|
267
|
+
style: Intl.DateTimeFormatOptions['day'] = 'numeric'
|
|
268
|
+
): string {
|
|
269
|
+
return this.locale('day', { day: style })
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Returns the formatted hour.
|
|
274
|
+
*
|
|
275
|
+
* Возвращает отформатированный час.
|
|
276
|
+
* @param style the representation of the month/ представление месяца
|
|
277
|
+
*/
|
|
278
|
+
localeHour(
|
|
279
|
+
style: Intl.DateTimeFormatOptions['hour'] = 'numeric'
|
|
280
|
+
): string {
|
|
281
|
+
return this.locale('hour', { hour: style })
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Returns the formatted minute.
|
|
286
|
+
*
|
|
287
|
+
* Возвращает отформатированную минуту.
|
|
288
|
+
* @param style the representation of the month/ представление месяца
|
|
289
|
+
*/
|
|
290
|
+
localeMinute(
|
|
291
|
+
style: Intl.DateTimeFormatOptions['minute'] = 'numeric'
|
|
292
|
+
): string {
|
|
293
|
+
return this.locale('minute', { minute: style })
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Returns the formatted second.
|
|
298
|
+
*
|
|
299
|
+
* Возвращает отформатированную секунду.
|
|
300
|
+
* @param style the representation of the month/ представление месяца
|
|
301
|
+
*/
|
|
302
|
+
localeSecond(
|
|
303
|
+
style: Intl.DateTimeFormatOptions['second'] = 'numeric'
|
|
304
|
+
): string {
|
|
305
|
+
return this.locale('second', { second: style })
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Output of standard data.
|
|
310
|
+
*
|
|
311
|
+
* Вывод стандартных данных.
|
|
312
|
+
* @param timeZone add time zone/ добавить временную зону
|
|
313
|
+
*/
|
|
314
|
+
standard(timeZone = true as boolean): string {
|
|
315
|
+
const geo = new Datetime(this.date, this.type, 'en-GB')
|
|
316
|
+
const date: string[] = []
|
|
317
|
+
let time: string | undefined
|
|
318
|
+
|
|
319
|
+
geo.setHour24(true)
|
|
320
|
+
|
|
321
|
+
if (this.type === 'hour-minute') {
|
|
322
|
+
time = geo.locale(this.type, {
|
|
323
|
+
year: 'numeric',
|
|
324
|
+
month: '2-digit',
|
|
325
|
+
hour12: false
|
|
326
|
+
})
|
|
327
|
+
} else {
|
|
328
|
+
if (['full', 'datetime', 'date', 'year-month', 'year', 'month', 'day'].indexOf(this.type) !== -1) {
|
|
329
|
+
date.push(geo.localeYear())
|
|
330
|
+
date.push(geo.localeMonth('2-digit'))
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (['full', 'datetime', 'date', 'year', 'month', 'day'].indexOf(this.type) !== -1) {
|
|
334
|
+
date.push(geo.localeDay('2-digit'))
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (['full', 'datetime', 'time', 'hour', 'minute', 'second'].indexOf(this.type) !== -1) {
|
|
338
|
+
time = geo.locale('time')
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return `${date.join('-')}${time ? `T${time}${timeZone ? geo.getTimeZone() : ''}` : ''}`
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Change the date completely.
|
|
347
|
+
*
|
|
348
|
+
* Изменять полностью дату.
|
|
349
|
+
* @param value an integer value representing the number/
|
|
350
|
+
* целочисленное значение, представляющее число
|
|
351
|
+
*/
|
|
352
|
+
setDate(value: NumberOrStringOrDate): this {
|
|
353
|
+
this.date = toDate(value)
|
|
354
|
+
this.update()
|
|
355
|
+
|
|
356
|
+
return this
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Change the type of data output.
|
|
361
|
+
*
|
|
362
|
+
* Изменить тип вывода данных.
|
|
363
|
+
* @param value type of output/ тип вывод
|
|
364
|
+
*/
|
|
365
|
+
setType(value: GeoDate): this {
|
|
366
|
+
this.type = value
|
|
367
|
+
this.update()
|
|
368
|
+
|
|
369
|
+
return this
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Whether to use 12-hour time.
|
|
374
|
+
*
|
|
375
|
+
* Использовать ли 12-часовой формат времени.
|
|
376
|
+
* @param value If true, output the 12-hour time format/
|
|
377
|
+
* если true, выводить 12-часовой формат времени
|
|
378
|
+
*/
|
|
379
|
+
setHour24(value: boolean): this {
|
|
380
|
+
this.hour24 = value
|
|
381
|
+
this.update()
|
|
382
|
+
|
|
383
|
+
return this
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* To change the location.
|
|
388
|
+
*
|
|
389
|
+
* Изменить местоположение.
|
|
390
|
+
* @param code country and language code/ код страны и языка
|
|
391
|
+
*/
|
|
392
|
+
setCode(code: string): this {
|
|
393
|
+
this.code = code
|
|
394
|
+
return this
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* The function is called when the data is updated.
|
|
399
|
+
*
|
|
400
|
+
* Функция вызывается при обновлении данных.
|
|
401
|
+
* @param watch the function calls/ функция вызывает
|
|
402
|
+
*/
|
|
403
|
+
setWatch(watch: (date: Date, type: GeoDate, hour24: boolean) => void): this {
|
|
404
|
+
this.watch = watch
|
|
405
|
+
return this
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* The method sets the full year for a specified date according to local time.
|
|
410
|
+
*
|
|
411
|
+
* Метод устанавливает полный год указанной даты по местному времени.
|
|
412
|
+
* @param value value/ значения
|
|
413
|
+
*/
|
|
414
|
+
setYear(value: number): this {
|
|
415
|
+
this.date.setFullYear(value)
|
|
416
|
+
this.update()
|
|
417
|
+
|
|
418
|
+
return this
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* The method sets the month for a specified date according to the currently set year.
|
|
423
|
+
*
|
|
424
|
+
* Метод устанавливает месяц указанной даты по местному времени.
|
|
425
|
+
* @param value value/ значения
|
|
426
|
+
*/
|
|
427
|
+
setMonth(value: number): this {
|
|
428
|
+
this.date.setMonth(value - 1)
|
|
429
|
+
this.update()
|
|
430
|
+
|
|
431
|
+
return this
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* The method changes the day of the month of a given Date instance, based on local time.
|
|
436
|
+
*
|
|
437
|
+
* Метод устанавливает день месяца указанной даты по местному времени.
|
|
438
|
+
* @param value value/ значения
|
|
439
|
+
*/
|
|
440
|
+
setDay(value: number): this {
|
|
441
|
+
this.date.setDate(value)
|
|
442
|
+
this.update()
|
|
443
|
+
|
|
444
|
+
return this
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* The method sets the hours for a specified date according to local time.
|
|
449
|
+
*
|
|
450
|
+
* Метод устанавливает часы указанной даты по местному времени.
|
|
451
|
+
* @param value value/ значения
|
|
452
|
+
*/
|
|
453
|
+
setHour(value: number): this {
|
|
454
|
+
this.date.setHours(value)
|
|
455
|
+
this.update()
|
|
456
|
+
|
|
457
|
+
return this
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* The method sets the minutes for a specified date according to local time
|
|
462
|
+
*
|
|
463
|
+
* Метод устанавливает минуты указанной даты по местному времени
|
|
464
|
+
* @param value value / значения
|
|
465
|
+
*/
|
|
466
|
+
setMinute(value: number): this {
|
|
467
|
+
this.date.setMinutes(value)
|
|
468
|
+
this.update()
|
|
469
|
+
|
|
470
|
+
return this
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* The method sets the seconds for a specified date according to local time.
|
|
475
|
+
*
|
|
476
|
+
* Метод устанавливает секунды указанной даты по местному времени.
|
|
477
|
+
* @param value value/ значения
|
|
478
|
+
*/
|
|
479
|
+
setSecond(value: number): this {
|
|
480
|
+
this.date.setSeconds(value)
|
|
481
|
+
this.update()
|
|
482
|
+
|
|
483
|
+
return this
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Shift the date by a given value in years.
|
|
488
|
+
*
|
|
489
|
+
* Сдвинуть дату на заданное значение в годах.
|
|
490
|
+
* @param value values for moving/ значения для перемещения
|
|
491
|
+
*/
|
|
492
|
+
moveByYear(value: number): this {
|
|
493
|
+
this.setYear(this.date.getFullYear() + value)
|
|
494
|
+
return this
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Shift the date by a given value in months.
|
|
499
|
+
*
|
|
500
|
+
* Сдвинуть дату на заданное значение в месяцах.
|
|
501
|
+
* @param value values for moving/ значения для перемещения
|
|
502
|
+
*/
|
|
503
|
+
moveByMonth(value: number): this {
|
|
504
|
+
this.setMonth(this.date.getMonth() + 1 + value)
|
|
505
|
+
return this
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Shift the date by a given value in days.
|
|
510
|
+
*
|
|
511
|
+
* Сдвинуть дату на заданное значение в днях.
|
|
512
|
+
* @param value values for moving/ значения для перемещения
|
|
513
|
+
*/
|
|
514
|
+
moveByDay(value: number): this {
|
|
515
|
+
this.setDay(this.date.getDate() + value)
|
|
516
|
+
return this
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Shift the date by a given value in hours.
|
|
521
|
+
*
|
|
522
|
+
* Сдвинуть дату на заданное значение в часах.
|
|
523
|
+
* @param value values for moving/ значения для перемещения
|
|
524
|
+
*/
|
|
525
|
+
moveByHour(value: number): this {
|
|
526
|
+
this.setHour(this.date.getHours() + value)
|
|
527
|
+
return this
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Shift the date by a given value in minutes.
|
|
532
|
+
*
|
|
533
|
+
* Сдвинуть дату на заданное значение в минутах.
|
|
534
|
+
* @param value values for moving/ значения для перемещения
|
|
535
|
+
*/
|
|
536
|
+
moveByMinute(value: number): this {
|
|
537
|
+
this.setMinute(this.date.getMinutes() + value)
|
|
538
|
+
return this
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Shift the date by a given value in seconds.
|
|
543
|
+
*
|
|
544
|
+
* Сдвинуть дату на заданное значение в секундах.
|
|
545
|
+
* @param value values for moving/ значения для перемещения
|
|
546
|
+
*/
|
|
547
|
+
moveBySecond(value: number): this {
|
|
548
|
+
this.setSecond(this.date.getSeconds() + value)
|
|
549
|
+
return this
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Translate to the first month.
|
|
554
|
+
*
|
|
555
|
+
* Переводить на первый месяц.
|
|
556
|
+
*/
|
|
557
|
+
moveMonthFirst(): this {
|
|
558
|
+
this.setMonth(1)
|
|
559
|
+
return this
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Translate to the first month.
|
|
564
|
+
*
|
|
565
|
+
* Переводить на первый месяц.
|
|
566
|
+
*/
|
|
567
|
+
moveMonthLast(): this {
|
|
568
|
+
this.setMonth(12)
|
|
569
|
+
return this
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Translate to the first day of the next month.
|
|
574
|
+
*
|
|
575
|
+
* Переводить на первый день следующего месяца.
|
|
576
|
+
*/
|
|
577
|
+
moveMonthNext(): this {
|
|
578
|
+
this.setDay(1)
|
|
579
|
+
.moveByMonth(+1)
|
|
580
|
+
|
|
581
|
+
return this
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Translate to the first day of the previous month.
|
|
586
|
+
*
|
|
587
|
+
* Переводить на первый день предыдущего месяца.
|
|
588
|
+
*/
|
|
589
|
+
moveMonthPrevious(): this {
|
|
590
|
+
this.setDay(1)
|
|
591
|
+
.moveByMonth(-1)
|
|
592
|
+
|
|
593
|
+
return this
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Translate to the first day of the week.
|
|
598
|
+
*
|
|
599
|
+
* Переводить на первый день недели.
|
|
600
|
+
*/
|
|
601
|
+
moveWeekdayFirst(): this {
|
|
602
|
+
const weekday = this.date.getDay()
|
|
603
|
+
const weekdayFirst = this.getFirstDayCode()
|
|
604
|
+
|
|
605
|
+
this.moveByDay(
|
|
606
|
+
(weekdayFirst === 6 ? -1 : weekdayFirst) - weekday
|
|
607
|
+
)
|
|
608
|
+
|
|
609
|
+
return this
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Translate to the last day of the week.
|
|
614
|
+
*
|
|
615
|
+
* Переводить на последний день недели.
|
|
616
|
+
*/
|
|
617
|
+
moveWeekdayLast(): this {
|
|
618
|
+
this.moveWeekdayFirst()
|
|
619
|
+
.moveByDay(6)
|
|
620
|
+
|
|
621
|
+
return this
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Translate to the first day of the first week of the month.
|
|
626
|
+
*
|
|
627
|
+
* Переводить на первый день первой недели месяца.
|
|
628
|
+
*/
|
|
629
|
+
moveWeekdayFirstByMonth(): this {
|
|
630
|
+
this.moveDayFirst()
|
|
631
|
+
.moveWeekdayFirst()
|
|
632
|
+
|
|
633
|
+
return this
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Translate to the first day of the first full week of the following month.
|
|
638
|
+
*
|
|
639
|
+
* Переводить на первый день первой полной недели следующего месяца.
|
|
640
|
+
*/
|
|
641
|
+
moveWeekdayLastByMonth(): this {
|
|
642
|
+
this.moveDayLast()
|
|
643
|
+
.moveWeekdayLast()
|
|
644
|
+
|
|
645
|
+
return this
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Translate to the next week.
|
|
650
|
+
*
|
|
651
|
+
* Переводить на следующую неделю.
|
|
652
|
+
*/
|
|
653
|
+
moveWeekdayNext(): this {
|
|
654
|
+
this.moveWeekdayFirst()
|
|
655
|
+
.moveByDay(7)
|
|
656
|
+
|
|
657
|
+
return this
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Translate to the previous week.
|
|
662
|
+
*
|
|
663
|
+
* Переводить на предыдущую неделю.
|
|
664
|
+
*/
|
|
665
|
+
moveWeekdayPrevious(): this {
|
|
666
|
+
this.moveWeekdayFirst()
|
|
667
|
+
.moveByDay(-7)
|
|
668
|
+
|
|
669
|
+
return this
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Translate to the first day of the month.
|
|
674
|
+
*
|
|
675
|
+
* Переводить на первый день месяца.
|
|
676
|
+
*/
|
|
677
|
+
moveDayFirst(): this {
|
|
678
|
+
this.setDay(1)
|
|
679
|
+
return this
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Translate to the last day of the month.
|
|
684
|
+
*
|
|
685
|
+
* Переводить на последний день месяца.
|
|
686
|
+
*/
|
|
687
|
+
moveDayLast(): this {
|
|
688
|
+
this.setDay(1)
|
|
689
|
+
.moveByMonth(1)
|
|
690
|
+
.moveByDay(-1)
|
|
691
|
+
|
|
692
|
+
return this
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Translate to the next day.
|
|
697
|
+
*
|
|
698
|
+
* Переводить на следующий день.
|
|
699
|
+
*/
|
|
700
|
+
moveDayNext(): this {
|
|
701
|
+
this.moveByDay(+1)
|
|
702
|
+
return this
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/**
|
|
706
|
+
* Translate to the previous day.
|
|
707
|
+
*
|
|
708
|
+
* Переводить на предыдущий день.
|
|
709
|
+
*/
|
|
710
|
+
moveDayPrevious(): this {
|
|
711
|
+
this.moveByDay(-1)
|
|
712
|
+
return this
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Clone the Date object.
|
|
717
|
+
*
|
|
718
|
+
* Клонировать объект Date.
|
|
719
|
+
*/
|
|
720
|
+
clone(): Date {
|
|
721
|
+
return new Date(this.date)
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Clone the GeoDate object.
|
|
726
|
+
*
|
|
727
|
+
* Клонировать объект GeoDate.
|
|
728
|
+
*/
|
|
729
|
+
cloneClass(): Datetime {
|
|
730
|
+
return new (this.constructor as typeof Datetime)(
|
|
731
|
+
this.clone(),
|
|
732
|
+
this.type,
|
|
733
|
+
this.code
|
|
734
|
+
)
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Clone the GeoDate object and set the month to January.
|
|
739
|
+
*
|
|
740
|
+
* Клонировать объект GeoDate и установить месяц на январь.
|
|
741
|
+
*/
|
|
742
|
+
cloneMonthFirst(): Datetime {
|
|
743
|
+
return this.cloneClass()
|
|
744
|
+
.moveMonthFirst()
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Clone the GeoDate object and move the month to the end of the year.
|
|
749
|
+
*
|
|
750
|
+
* Клонировать объект GeoDate и перевести месяц на конец года.
|
|
751
|
+
*/
|
|
752
|
+
cloneMonthLast(): Datetime {
|
|
753
|
+
return this.cloneClass()
|
|
754
|
+
.moveMonthLast()
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Clone the GeoDate object and transfer it one month ahead.
|
|
759
|
+
*
|
|
760
|
+
* Клонировать объект GeoDate и перевести на 1 месяц вперед.
|
|
761
|
+
*/
|
|
762
|
+
cloneMonthNext(): Datetime {
|
|
763
|
+
return this.cloneClass()
|
|
764
|
+
.moveMonthNext()
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Clone the GeoDate object and transfer it one month back.
|
|
769
|
+
*
|
|
770
|
+
* Клонировать объект GeoDate и перевести на 1 месяц назад.
|
|
771
|
+
*/
|
|
772
|
+
cloneMonthPrevious(): Datetime {
|
|
773
|
+
return this.cloneClass()
|
|
774
|
+
.moveMonthPrevious()
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Returns the first day of the week according to the current date.
|
|
779
|
+
*
|
|
780
|
+
* Возвращает первый день недели по текущей дате.
|
|
781
|
+
*/
|
|
782
|
+
cloneWeekdayFirst(): Datetime {
|
|
783
|
+
return this.cloneClass()
|
|
784
|
+
.moveWeekdayFirst()
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Returns the last day of the week according to the current date.
|
|
789
|
+
*
|
|
790
|
+
* Возвращает последний день недели по текущей дате.
|
|
791
|
+
*/
|
|
792
|
+
cloneWeekdayLast(): Datetime {
|
|
793
|
+
return this.cloneClass()
|
|
794
|
+
.moveWeekdayLast()
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Returns the first day of the week according to the current month.
|
|
799
|
+
*
|
|
800
|
+
* Возвращает первый день недели по текущему месяцу.
|
|
801
|
+
*/
|
|
802
|
+
cloneWeekdayFirstByMonth(): Datetime {
|
|
803
|
+
return this.cloneClass()
|
|
804
|
+
.moveWeekdayFirstByMonth()
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* Returns the last day of the week according to the current month.
|
|
809
|
+
*
|
|
810
|
+
* Возвращает последний день недели по текущему месяцу.
|
|
811
|
+
*/
|
|
812
|
+
cloneWeekdayLastByMonth(): Datetime {
|
|
813
|
+
return this.cloneClass()
|
|
814
|
+
.moveWeekdayLastByMonth()
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Returns the next week according to the current date.
|
|
819
|
+
*
|
|
820
|
+
* Возвращает следующую неделю по текущей дате.
|
|
821
|
+
*/
|
|
822
|
+
cloneWeekdayNext(): Datetime {
|
|
823
|
+
return this.cloneClass()
|
|
824
|
+
.moveWeekdayNext()
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Returns the previous week according to the current date.
|
|
829
|
+
*
|
|
830
|
+
* Возвращает предыдущую неделю по текущей дате.
|
|
831
|
+
*/
|
|
832
|
+
cloneWeekdayPrevious(): Datetime {
|
|
833
|
+
return this.cloneClass()
|
|
834
|
+
.moveWeekdayPrevious()
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Clone the GeoDate object and move the day to the beginning of the month.
|
|
839
|
+
*
|
|
840
|
+
* Клонировать объект GeoDate и перевести день на начало месяца.
|
|
841
|
+
*/
|
|
842
|
+
cloneDayFirst(): Datetime {
|
|
843
|
+
return this.cloneClass()
|
|
844
|
+
.moveDayFirst()
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Clone the GeoDate object and move the day to the end of the month.
|
|
849
|
+
*
|
|
850
|
+
* Клонировать объект GeoDate и перевести день на конец месяца.
|
|
851
|
+
*/
|
|
852
|
+
cloneDayLast(): Datetime {
|
|
853
|
+
return this.cloneClass()
|
|
854
|
+
.moveDayLast()
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Clone the GeoDate object and move by 1 day.
|
|
859
|
+
*
|
|
860
|
+
* Клонировать объект GeoDate и перевести на 1 день.
|
|
861
|
+
*/
|
|
862
|
+
cloneDayNext(): Datetime {
|
|
863
|
+
return this.cloneClass()
|
|
864
|
+
.moveDayNext()
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* Clone the GeoDate object and go back by 1 day.
|
|
869
|
+
*
|
|
870
|
+
* Клонировать объект GeoDate и вернуться на 1 день.
|
|
871
|
+
*/
|
|
872
|
+
cloneDayPrevious(): Datetime {
|
|
873
|
+
return this.cloneClass()
|
|
874
|
+
.moveDayPrevious()
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Updating all values.
|
|
879
|
+
*
|
|
880
|
+
* Обновление всех значений.
|
|
881
|
+
*/
|
|
882
|
+
protected update(): this {
|
|
883
|
+
this.watch?.(
|
|
884
|
+
this.date,
|
|
885
|
+
this.type,
|
|
886
|
+
this.hour24
|
|
887
|
+
)
|
|
888
|
+
|
|
889
|
+
return this
|
|
890
|
+
}
|
|
891
|
+
}
|