1this.BX = this.BX || {}; 2(function (exports,main_core) { 3 'use strict'; 4 5 function convertBitrixFormat(format) { 6 if (!main_core.Type.isStringFilled(format)) { 7 return ''; 8 } 9 return format.replace('YYYY', 'Y') // 1999 10 .replace('MMMM', 'F') // January - December 11 .replace('MM', 'm') // 01 - 12 12 .replace('M', 'M') // Jan - Dec 13 .replace('DD', 'd') // 01 - 31 14 .replace('G', 'g') // 1 - 12 15 .replace(/GG/i, 'G') // 0 - 23 16 .replace('H', 'h') // 01 - 12 17 .replace(/HH/i, 'H') // 00 - 24 18 .replace('MI', 'i') // 00 - 59 19 .replace('SS', 's') // 00 - 59 20 .replace('TT', 'A') // AM - PM 21 .replace('T', 'a'); // am - pm 22 } 23 24 const formatsCache = new main_core.Cache.MemoryCache(); 25 26 /** 27 * Returns culture-specific datetime format by code. 28 * The full list with examples can be found in config.php of this extension in ['settings']['formats']. 29 * All formats are compatible with this.format() without any additional transformations. 30 * 31 * @param code 32 * @returns {string|null} 33 */ 34 function getFormat(code) { 35 return formatsCache.remember(`main.date.format.${code}`, () => { 36 let format = main_core.Extension.getSettings('main.date').get(`formats.${code}`); 37 if (main_core.Type.isStringFilled(format) && (code === 'FORMAT_DATE' || code === 'FORMAT_DATETIME')) { 38 format = convertBitrixFormat(format); 39 } 40 return format; 41 }); 42 } 43 44 /** 45 * @memberOf BX.Main 46 * @alias Date 47 */ 48 let DateTimeFormat = /*#__PURE__*/function () { 49 function DateTimeFormat() { 50 babelHelpers.classCallCheck(this, DateTimeFormat); 51 } 52 babelHelpers.createClass(DateTimeFormat, null, [{ 53 key: "isAmPmMode", 54 value: function isAmPmMode(returnConst) { 55 if (returnConst === true) { 56 return this._getMessage('AMPM_MODE'); 57 } 58 return this._getMessage('AMPM_MODE') !== false; 59 } 60 }, { 61 key: "convertToUTC", 62 value: function convertToUTC(date) { 63 if (!main_core.Type.isDate(date)) { 64 return null; 65 } 66 return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds())); 67 } 68 /** 69 * Function creates and returns Javascript Date() object from server timestamp regardless of local browser (system) timezone. 70 * For example can be used to convert timestamp from some exact date on server to the JS Date object with the same value. 71 * 72 * @param timestamp - timestamp in seconds 73 * @returns {Date} 74 */ 75 }, { 76 key: "getNewDate", 77 value: function getNewDate(timestamp) { 78 return new Date(this.getBrowserTimestamp(timestamp)); 79 } 80 /** 81 * Function transforms server timestamp (in sec) to javascript timestamp (calculated depend on local browser timezone offset). Returns timestamp in milliseconds. 82 * Also see BX.Main.Date.getNewDate description. 83 * 84 * @param timestamp - timestamp in seconds 85 * @returns {number} 86 */ 87 }, { 88 key: "getBrowserTimestamp", 89 value: function getBrowserTimestamp(timestamp) { 90 timestamp = parseInt(timestamp, 10); 91 const browserOffset = new Date(timestamp * 1000).getTimezoneOffset() * 60; 92 return (parseInt(timestamp, 10) + parseInt(this._getMessage('SERVER_TZ_OFFSET')) + browserOffset) * 1000; 93 } 94 /** 95 * Function transforms local browser timestamp (in ms) to server timestamp (calculated depend on local browser timezone offset). Returns timestamp in seconds. 96 * 97 * @param timestamp - timestamp in milliseconds 98 * @returns {number} 99 */ 100 }, { 101 key: "getServerTimestamp", 102 value: function getServerTimestamp(timestamp) { 103 timestamp = parseInt(timestamp, 10); 104 const browserOffset = new Date(timestamp).getTimezoneOffset() * 60; 105 return Math.round(timestamp / 1000 - (parseInt(this._getMessage('SERVER_TZ_OFFSET'), 10) + parseInt(browserOffset, 10))); 106 } 107 }, { 108 key: "formatLastActivityDate", 109 value: function formatLastActivityDate(timestamp, now, utc) { 110 const ampm = this.isAmPmMode(true); 111 const timeFormat = ampm === this.AM_PM_MODE.LOWER ? 'g:i a' : ampm === this.AM_PM_MODE.UPPER ? 'g:i A' : 'H:i'; 112 const format = [['tomorrow', '#01#' + timeFormat], ['now', '#02#'], ['todayFuture', '#03#' + timeFormat], ['yesterday', '#04#' + timeFormat], ['-', this.convertBitrixFormat(this._getMessage('FORMAT_DATETIME')).replace(/:s/g, '')], ['
112s60', 'sago'], ['i60', 'iago'], ['H5', 'Hago'], ['H24', '#03#' + timeFormat], ['d31', 'dago'], ['m12>1', 'mago'], ['m12>0', 'dago'], ['', '#05#']]; 113 let formattedDate = this.format(format, timestamp, now, utc); 114 let match = null; 115 if ((match = /^#(\d+)#(.*)/.exec(formattedDate)) != null) { 116 switch (match[1]) { 117 case '01': 118 formattedDate = this._getMessage('FD_LAST_SEEN_TOMORROW').replace('#TIME#', match[2]); 119 break; 120 case '02': 121 formattedDate = this._getMessage('FD_LAST_SEEN_NOW'); 122 break; 123 case '03': 124 formattedDate = this._getMessage('FD_LAST_SEEN_TODAY').replace('#TIME#', match[2]); 125 break; 126 case '04': 127 formattedDate = this._getMessage('FD_LAST_SEEN_YESTERDAY').replace('#TIME#', match[2]); 128 break; 129 case '05': 130 formattedDate = this._getMessage('FD_LAST_SEEN_MORE_YEAR'); 131 break; 132 default: 133 formattedDate = match[2]; 134 break; 135 } 136 } 137 return formattedDate; 138 } 139 /** 140 * The method is designed to replace the localization storage on sites without Bitrix Framework. 141 * It gets overloaded with custom implementation: 142 * 143 * const CustomDate = Object.create(BX.Main.Date); 144 * CustomDate._getMessage = () => ...new implementation...; 145 * 146 * This class should get messages only via this method. 147 * Otherwise, the class won't work on sites without Bitrix Framework. 148 * 149 * @param message 150 * @returns {*} 151 * @private 152 */ 153 }, { 154 key: "_getMessage", 155 value: function _getMessage(message) { 156 return main_core.Loc.getMessage(message); 157 } 158 /** 159 * The method used to parse date from string by given format. 160 * 161 * @param {string} str - date in given format 162 * @param {boolean} isUTC - is date in UTC 163 * @param {string} formatDate - format of the date without time 164 * @param {string} formatDatetime - format of the date with time 165 * @returns {Date|null} - returns Date object if string was parsed or null 166 */ 167 }, { 168 key: "parse", 169 value: function parse(str, isUTC, formatDate, formatDatetime) { 170 if (main_core.Type.isStringFilled(str)) { 171 if (!formatDate) { 172 formatDate = this._getMessage('FORMAT_DATE'); 173 } 174 if (!formatDatetime) { 175 formatDatetime = this._getMessage('FORMAT_DATETIME'); 176 } 177 let regMonths = ''; 178 for (let i = 1; i <= 12; i++) { 179 regMonths = regMonths + '|' + this._getMessage('MON_' + i); 180 }
181 const expr = new RegExp('([0-9]+|[a-z]+' + regMonths + ')', 'ig'); 182 const aDate = str.match(expr); 183 let aFormat = formatDate.match(/(DD|MI|MMMM|MM|M|YYYY)/ig); 184 const aDateArgs = []; 185 const aFormatArgs = []; 186 const aResult = {}; 187 if (!aDate) { 188 return null; 189 } 190 if (aDate.length > aFormat.length) { 191 aFormat = formatDatetime.match(/(DD|MI|MMMM|MM|M|YYYY|HH|H|SS|TT|T|GG|G)/ig); 192 } 193 for (let i = 0, cnt = aDate.length; i < cnt; i++) { 194 if (aDate[i].trim() !== '') { 195 aDateArgs[aDateArgs.length] = aDate[i]; 196 } 197 } 198 for (let i = 0, cnt = aFormat.length; i < cnt; i++) { 199 if (aFormat[i].trim() !== '') { 200 aFormatArgs[aFormatArgs.length] = aFormat[i]; 201 } 202 } 203 let m = aFormatArgs.findIndex(item => item === 'MMMM'); 204 if (m > 0) { 205 aDateArgs[m] = this.getMonthIndex(aDateArgs[m]); 206 aFormatArgs[m] = 'MM'; 207 } else { 208 m = aFormatArgs.findIndex(item => item === 'M'); 209 if (m > 0) { 210 aDateArgs[m] = this.getMonthIndex(aDateArgs[m]); 211 aFormatArgs[m] = 'MM'; 212 } 213 } 214 for (let i = 0, cnt = aFormatArgs.length; i < cnt; i++) { 215 const k = aFormatArgs[i].toUpperCase(); 216 aResult[k] = k === 'T' || k === 'TT' ? aDateArgs[i] : parseInt(aDateArgs[i], 10); 217 } 218 if (aResult['DD'] > 0 && aResult['MM'] > 0 && aResult['YYYY'] > 0) { 219 const d = new Date(); 220 if (isUTC) { 221 d.setUTCDate(1); 222 d.setUTCFullYear(aResult['YYYY']); 223 d.setUTCMonth(aResult['MM'] - 1); 224 d.setUTCDate(aResult['DD']); 225 d.setUTCHours(0, 0, 0, 0); 226 } else { 227 d.setDate(1); 228 d.setFullYear(aResult['YYYY']); 229 d.setMonth(aResult['MM'] - 1); 230 d.setDate(aResult['DD']); 231 d.setHours(0, 0, 0, 0); 232 } 233 if ((!isNaN(aResult['HH']) || !isNaN(aResult['GG']) || !isNaN(aResult['H']) || !isNaN(aResult['G'])) && !isNaN(aResult['MI'])) { 234 if (!isNaN(aResult['H']) || !isNaN(aResult['G'])) { 235 const bPM = (aResult['T'] || aResult['TT'] || 'am').toUpperCase() === 'PM', 236 h = parseInt(aResult['H'] || aResult['G'] || 0, 10); 237 if (bPM) { 238 aResult['HH'] = h + (h === 12 ? 0 : 12); 239 } else { 240 aResult['HH'] = h < 12 ? h : 0; 241 } 242 } else { 243 aResult['HH'] = parseInt(aResult['HH'] || aResult['GG'] || 0, 10); 244 } 245 if (isNaN(aResult['SS'])) { 246 aResult['SS'] = 0; 247 } 248 if (isUTC) { 249 d.setUTCHours(aResult['HH'], aResult['MI'], aResult['SS']); 250 } else { 251 d.setHours(aResult['HH'], aResult['MI'], aResult['SS']); 252 } 253 } 254 return d; 255 } 256 } 257 return null; 258 } 259 }, { 260 key: "getMonthIndex", 261 value: function getMonthIndex(month) { 262 const q = month.toUpperCase(); 263 const wordMonthCut = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']; 264 const wordMonth = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december']; 265 for (let i = 1; i <= 12; i++) { 266 if (q === this._getMessage('MON_' + i).toUpperCase() || q === this._getMessage('MONTH_' + i).toUpperCase() || q === wordMonthCut[i - 1].toUpperCase() || q === wordMonth[i - 1].toUpperCase()) { 267 return i; 268 } 269 } 270 return month; 271 } 272 }, { 273 key: "format", 274 value: function format(_format, timestamp, now, utc) { 275 /* 276 PHP to Javascript: 277 time() = new Date() 278 mktime(...) = new Date(...) 279 gmmktime(...) = new Date(Date.UTC(...)) 280 mktime(0,0,0, 1, 1, 1970) != 0 new Date(1970,0,1).getTime() != 0 281 gmmktime(0,0,0, 1, 1, 1970) == 0 new Date(Date.UTC(1970,0,1)).getTime() == 0 282 date('d.m.Y H:i:s') = BX.Main.Date.format('d.m.Y H:i:s') 283 gmdate('d.m.Y H:i:s') = BX.Main.Date.format('d.m.Y H:i:s', null, null, true); 284 */ 285 const date = main_core.Type.isDate(timestamp) ? new Date(timestamp.getTime()) : main_core.Type.isNumber(timestamp) ? new Date(timestamp * 1000) : new Date(); 286 const nowDate = main_core.Type.isDate(now) ? new Date(now.getTime()) : main_core.Type.isNumber(now) ? new Date(now * 1000) : new Date(); 287 const isUTC = !!utc; 288 // used in hoisting inner functions, like _formatDateInterval 289 const thisDateTimeFormat = this; 290 if (main_core.Type.isArray(_format)) { 291 return _formatDateInterval(_format, date, nowDate, isUTC); 292 } else { 293 if (!main_core.Type.isStringFilled(_format)) { 294 return ''; 295 } 296 } 297 const replaceMap = (_format.match(/{{([^{}]*)}}/g) || []).map(x => { 298 return (x.match(/[^{}]+/) || [''])[0]; 299 }); 300 if (replaceMap.length > 0) {
301 replaceMap.forEach((element, index) => { 302 _format = _format.replace('{{' + element + '}}', '{{' + index + '}}'); 303 }); 304 } 305 const formatRegex = /\\?(sago|iago|isago|Hago|dago|mago|Yago|sdiff|idiff|Hdiff|ddiff|mdiff|Ydiff|sshort|ishort|Hshort|dshort|mhort|Yshort|yesterday|today|tommorow|tomorrow|[a-z])/gi; 306 const dateFormats = { 307 d: () => { 308 // Day of the month 01 to 31 309 return getDate(date).toString().padStart(2, '0'); 310 }, 311 D: () => { 312 //Mon through Sun 313 return this._getMessage('DOW_' + getDay(date)); 314 }, 315 j: () => { 316 //Day of the month 1 to 31 317 return getDate(date); 318 }, 319 l: () => { 320 //Sunday through Saturday 321 return this._getMessage('DAY_OF_WEEK_' + getDay(date)); 322 }, 323 N: () => { 324 //1 (for Monday) through 7 (for Sunday) 325 return getDay(date) || 7; 326 }, 327 S: () => { 328 //st, nd, rd or th. Works well with j 329 if (getDate(date) % 10 == 1 && getDate(date) != 11) { 330 return 'st'; 331 } else if (getDate(date) % 10 == 2 && getDate(date) != 12) { 332 return 'nd'; 333 } else if (getDate(date) % 10 == 3 && getDate(date) != 13) { 334 return 'rd'; 335 } else { 336 return 'th'; 337 } 338 }, 339 w: () => { 340 //0 (for Sunday) through 6 (for Saturday) 341 return getDay(date); 342 }, 343 z: () => { 344 //0 through 365 345 const firstDay = new Date(getFullYear(date), 0, 1); 346 const currentDay = new Date(getFullYear(date), getMonth(date), getDate(date)); 347 return Math.ceil((currentDay - firstDay) / (24 * 3600 * 1000)); 348 }, 349 W: () => { 350 //ISO-8601 week number of year 351 const newDate = new Date(date.getTime()); 352 const dayNumber = (getDay(date) + 6) % 7; 353 setDate(newDate, getDate(newDate) - dayNumber + 3); 354 const firstThursday = newDate.getTime(); 355 setMonth(newDate, 0, 1); 356 if (getDay(newDate) != 4) { 357 setMonth(newDate, 0, 1 + (4 - getDay(newDate) + 7) % 7); 358 } 359 const weekNumber = 1 + Math.ceil((firstThursday - newDate) / (7 * 24 * 3600 * 1000)); 360 return weekNumber.toString().padStart(2, '0'); 361 }, 362 F: () => { 363 //January through December 364 return this._getMessage('MONTH_' + (getMonth(date) + 1) + '_S'); 365 }, 366 f: () => { 367 //January through December 368 return this._getMessage('MONTH_' + (getMonth(date) + 1)); 369 }, 370 m: () => { 371 //Numeric representation of a month 01 through 12 372 return (getMonth(date) + 1).toString().padStart(2, '0'); 373 }, 374 M: () => { 375 //A short textual representation of a month, three letters Jan through Dec 376 return this._getMessage('MON_' + (getMonth(date) + 1)); 377 }, 378 n: () => { 379 //Numeric representation of a month 1 through 12 380 return getMonth(date) + 1; 381 }, 382 t: () => { 383 //Number of days in the given month 28 through 31 384 const lastMonthDay = isUTC ? new Date(Date.UTC(getFullYear(date), getMonth(date) + 1, 0)) : new Date(getFullYear(date), getMonth(date) + 1, 0); 385 return getDate(lastMonthDay); 386 }, 387 L: () => { 388 //1 if it is a leap year, 0 otherwise. 389 const year = getFullYear(date); 390 return year % 4 == 0 && year % 100 != 0 || year % 400 == 0 ? 1 : 0; 391 }, 392 o: () => { 393 //ISO-8601 year number 394 const correctDate = new Date(date.getTime()); 395 setDate(correctDate, getDate(correctDate) - (getDay(date) + 6) % 7 + 3); 396 return getFullYear(correctDate); 397 }, 398 Y: () => { 399 //A full numeric representation of a year, 4 digits 400 return getFullYear(date); 401 }, 402 y: () => { 403 //A two digit representation of a year 404 return getFullYear(date).toString().slice(2); 405 }, 406 a: () => { 407 //am or pm 408 return getHours(date) > 11 ? 'pm' : 'am'; 409 }, 410 A: () => { 411 //AM or PM 412 return getHours(date) > 11 ? 'PM' : 'AM'; 413 }, 414 B: () => { 415 //000 through 999 416 const swatch = (date.getUTCHours() + 1) % 24 + date.getUTCMinutes() / 60 + date.getUTCSeconds() / 3600; 417 return Math.floor(swatch * 1000 / 24).toString().padStart(3, '0'); 418 }, 419 g: () => { 420 //12-hour format of an hour without leading zeros 1 through 12 421 return getHours(date) % 12 || 12; 422 }, 423 G: () => { 424 //24-hour format of an hour without leading zeros 0 through 23 425 return getHours(date); 426 }, 427 h: () => { 428 //12-hour format of an hour with leading zeros 01 through 12 429 return (getHours(date) % 12 || 12).toString().padStart(2, '0'); 430 }, 431 H: () => { 432 //24-hour format of an hour with leading zeros 00 through 23 433 return getHours(date).toString().padStart(2, '0'); 434 }, 435 i: () => { 436 //Minutes with leading zeros 00 to 59 437 return getMinutes(date).toString().padStart(2, '0'); 438 }, 439 s: () => { 440 //Seconds, with leading zeros 00 through 59 441 return getSeconds(date).toString().padStart(2, '0'); 442 }, 443 u: () => { 444 //Microseconds 445 return (getMilliseconds(date) * 1000).toString().padStart(6, '0'); 446 }, 447 e: () => { 448 if (isUTC) { 449 return 'UTC'; 450 } 451 return ''; 452 }, 453 I: () => { 454 if (isUTC) { 455 return 0; 456 } 457 458 //Whether or not the date is in daylight saving time 1 if Daylight Saving Time, 0 otherwise 459 const firstJanuary = new Date(getFullYear(date), 0, 1); 460 const firstJanuaryUTC = Date.UTC(getFullYear(date), 0, 1); 461 const firstJuly = new Date(getFullYear(date), 6, 0); 462 const firstJulyUTC = Date.UTC(getFullYear(date), 6, 0); 463 return 0 + (firstJanuary - firstJanuaryUTC !== firstJuly - firstJulyUTC); 464 }, 465 O: () => { 466 if (isUTC) { 467 return '+0000'; 468 } 469 470 //Difference to Greenwich time (GMT) in hours +0200 471 const timezoneOffset = date.getTimezoneOffset(); 472 const timezoneOffsetAbs = Math.abs(timezoneOffset); 473 return (timezoneOffset > 0 ? '-' : '+') + (Math.floor(timezoneOffsetAbs / 60) * 100 + timezoneOffsetAbs % 60).toString().padStart(4, '0'); 474 }, 475 //this method references 'O' method of the same object, arrow function is not suitable here 476 P: function () { 477 if (isUTC) { 478 return '+00:00'; 479 } 480 481 //Difference to Greenwich time (GMT) with colon between hours and minutes +02:00 482 const difference = this.O(); 483 return difference.substr(0, 3) + ':' + difference.substr(3); 484 }, 485 Z: () => { 486 if (isUTC) { 487 return 0; 488 } 489 //Timezone offset in seconds. The offset for timezones west of UTC is always negative, 490 //and for those east of UTC is always positive. 491 return -date.getTimezoneOffset() * 60; 492 }, 493 c: () => { 494 //ISO 8601 date 495 return 'Y-m-d\\TH:i:sP'.replace(formatRegex, _replaceDateFormat); 496 }, 497 r: () => { 498 //RFC 2822 formatted date 499 return 'D, d M Y H:i:s O'.replace(formatRegex, _replaceDateFormat); 500 }, 501 U: () => { 502 //Seconds since the Unix Epoch 503 return Math.floor(date.getTime() / 1000); 504 }, 505 sago: () => { 506 return _formatDateMessage(intval((nowDate - date) / 1000), { 507 '0': 'FD_SECOND_AGO_0', 508 '1': 'FD_SECOND_AGO_1', 509 '10_20': 'FD_SECOND_AGO_10_20', 510 'MOD_1': 'FD_SECOND_AGO_MOD_1', 511 'MOD_2_4': 'FD_SECOND_AGO_MOD_2_4', 512 'MOD_OTHER': 'FD_SECOND_AGO_MOD_OTHER' 513 }); 514 }, 515 sdiff: () => { 516 return _formatDateMessage(intval((nowDate - date) / 1000), { 517 '0': 'FD_SECOND_DIFF_0', 518 '1': 'FD_SECOND_DIFF_1', 519 '10_20': 'FD_SECOND_DIFF_10_20', 520 'MOD_1': 'FD_SECOND_DIFF_MOD_1', 521 'MOD_2_4': 'FD_SECOND_DIFF_MOD_2_4', 522 'MOD_OTHER': 'FD_SECOND_DIFF_MOD_OTHER' 523 }); 524 },
525 sshort: () => { 526 return this._getMessage('FD_SECOND_SHORT').replace(/#VALUE#/g, intval((nowDate - date) / 1000)); 527 }, 528 iago: () => { 529 return _formatDateMessage(intval((nowDate - date) / 60 / 1000), { 530 '0': 'FD_MINUTE_AGO_0', 531 '1': 'FD_MINUTE_AGO_1', 532 '10_20': 'FD_MINUTE_AGO_10_20', 533 'MOD_1': 'FD_MINUTE_AGO_MOD_1', 534 'MOD_2_4': 'FD_MINUTE_AGO_MOD_2_4', 535 'MOD_OTHER': 'FD_MINUTE_AGO_MOD_OTHER' 536 }); 537 }, 538 idiff: () => { 539 return _formatDateMessage(intval((nowDate - date) / 60 / 1000), { 540 '0': 'FD_MINUTE_DIFF_0', 541 '1': 'FD_MINUTE_DIFF_1', 542 '10_20': 'FD_MINUTE_DIFF_10_20', 543 'MOD_1': 'FD_MINUTE_DIFF_MOD_1', 544 'MOD_2_4': 'FD_MINUTE_DIFF_MOD_2_4', 545 'MOD_OTHER': 'FD_MINUTE_DIFF_MOD_OTHER' 546 }); 547 }, 548 isago: () => { 549 const minutesAgo = intval((nowDate - date) / 60 / 1000); 550 let result = _formatDateMessage(minutesAgo, { 551 '0': 'FD_MINUTE_0', 552 '1': 'FD_MINUTE_1', 553 '10_20': 'FD_MINUTE_10_20', 554 'MOD_1': 'FD_MINUTE_MOD_1', 555 'MOD_2_4': 'FD_MINUTE_MOD_2_4', 556 'MOD_OTHER': 'FD_MINUTE_MOD_OTHER' 557 }); 558 result += ' '; 559 const secondsAgo = intval((nowDate - date) / 1000) - minutesAgo * 60; 560 result += _formatDateMessage(secondsAgo, { 561 '0': 'FD_SECOND_AGO_0', 562 '1': 'FD_SECOND_AGO_1', 563 '10_20': 'FD_SECOND_AGO_10_20', 564 'MOD_1': 'FD_SECOND_AGO_MOD_1', 565 'MOD_2_4': 'FD_SECOND_AGO_MOD_2_4', 566 'MOD_OTHER': 'FD_SECOND_AGO_MOD_OTHER' 567 }); 568 return result; 569 }, 570 ishort: () => { 571 return this._getMessage('FD_MINUTE_SHORT').replace(/#VALUE#/g, intval((nowDate - date) / 60 / 1000)); 572 }, 573 Hago: () => { 574 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 1000), { 575 '0': 'FD_HOUR_AGO_0', 576 '1': 'FD_HOUR_AGO_1', 577 '10_20': 'FD_HOUR_AGO_10_20', 578 'MOD_1': 'FD_HOUR_AGO_MOD_1', 579 'MOD_2_4': 'FD_HOUR_AGO_MOD_2_4', 580 'MOD_OTHER': 'FD_HOUR_AGO_MOD_OTHER' 581 }); 582 }, 583 Hdiff: () => { 584 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 1000), { 585 '0': 'FD_HOUR_DIFF_0', 586 '1': 'FD_HOUR_DIFF_1', 587 '10_20': 'FD_HOUR_DIFF_10_20', 588 'MOD_1': 'FD_HOUR_DIFF_MOD_1', 589 'MOD_2_4': 'FD_HOUR_DIFF_MOD_2_4', 590 'MOD_OTHER': 'FD_HOUR_DIFF_MOD_OTHER' 591 }); 592 }, 593 Hshort: () => { 594 return this._getMessage('FD_HOUR_SHORT').replace(/#VALUE#/g, intval((nowDate - date) / 60 / 60 / 1000)); 595 }, 596 yesterday: () => { 597 return this._getMessage('FD_YESTERDAY'); 598 }, 599 today: () => { 600 return this._getMessage('FD_TODAY'); 601 }, 602 tommorow: () => { 603 return this._getMessage('FD_TOMORROW'); 604 }, 605 tomorrow: () => { 606 return this._getMessage('FD_TOMORROW'); 607 }, 608 dago: () => { 609 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 24 / 1000), { 610 '0': 'FD_DAY_AGO_0', 611 '1': 'FD_DAY_AGO_1', 612 '10_20': 'FD_DAY_AGO_10_20', 613 'MOD_1': 'FD_DAY_AGO_MOD_1', 614 'MOD_2_4': 'FD_DAY_AGO_MOD_2_4', 615 'MOD_OTHER': 'FD_DAY_AGO_MOD_OTHER' 616 }); 617 }, 618 ddiff: () => { 619 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 24 / 1000), { 620 '0': 'FD_DAY_DIFF_0', 621 '1': 'FD_DAY_DIFF_1', 622 '10_20': 'FD_DAY_DIFF_10_20', 623 'MOD_1': 'FD_DAY_DIFF_MOD_1', 624 'MOD_2_4': 'FD_DAY_DIFF_MOD_2_4', 625 'MOD_OTHER': 'FD_DAY_DIFF_MOD_OTHER' 626 }); 627 }, 628 dshort: () => { 629 return this._getMessage('FD_DAY_SHORT').replace(/#VALUE#/g, intval((nowDate - date) / 60 / 60 / 24 / 1000)); 630 }, 631 mago: () => { 632 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 24 / 31 / 1000), { 633 '0': 'FD_MONTH_AGO_0', 634 '1': 'FD_MONTH_AGO_1', 635 '10_20': 'FD_MONTH_AGO_10_20', 636 'MOD_1': 'FD_MONTH_AGO_MOD_1', 637 'MOD_2_4': 'FD_MONTH_AGO_MOD_2_4', 638 'MOD_OTHER': 'FD_MONTH_AGO_MOD_OTHER' 639 }); 640 }, 641 mdiff: () => { 642 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 24 / 31 / 1000), { 643 '0': 'FD_MONTH_DIFF_0', 644 '1': 'FD_MONTH_DIFF_1', 645 '10_20': 'FD_MONTH_DIFF_10_20', 646 'MOD_1': 'FD_MONTH_DIFF_MOD_1', 647 'MOD_2_4': 'FD_MONTH_DIFF_MOD_2_4', 648 'MOD_OTHER': 'FD_MONTH_DIFF_MOD_OTHER' 649 }); 650 }, 651 mshort: () => { 652 return this._getMessage('FD_MONTH_SHORT').replace(/#VALUE#/g, intval((nowDate - date) / 60 / 60 / 24 / 31 / 1000)); 653 }, 654 Yago: () => { 655 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 24 / 365 / 1000), { 656 '0': 'FD_YEARS_AGO_0', 657 '1': 'FD_YEARS_AGO_1', 658 '10_20': 'FD_YEARS_AGO_10_20', 659 'MOD_1': 'FD_YEARS_AGO_MOD_1', 660 'MOD_2_4': 'FD_YEARS_AGO_MOD_2_4', 661 'MOD_OTHER': 'FD_YEARS_AGO_MOD_OTHER' 662 }); 663 }, 664 Ydiff: () => { 665 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 24 / 365 / 1000), { 666 '0': 'FD_YEARS_DIFF_0', 667 '1': 'FD_YEARS_DIFF_1', 668 '10_20': 'FD_YEARS_DIFF_10_20', 669 'MOD_1': 'FD_YEARS_DIFF_MOD_1', 670 'MOD_2_4': 'FD_YEARS_DIFF_MOD_2_4', 671 'MOD_OTHER': 'FD_YEARS_DIFF_MOD_OTHER' 672 }); 673 }, 674 Yshort: () => { 675 return _formatDateMessage(intval((nowDate - date) / 60 / 60 / 24 / 365 / 1000), { 676 '0': 'FD_YEARS_SHORT_0', 677 '1': 'FD_YEARS_SHORT_1', 678 '10_20': 'FD_YEARS_SHORT_10_20', 679 'MOD_1': 'FD_YEARS_SHORT_MOD_1', 680 'MOD_2_4': 'FD_YEARS_SHORT_MOD_2_4', 681 'MOD_OTHER': 'FD_YEARS_SHORT_MOD_OTHER' 682 }); 683 }, 684 x: () => { 685 const ampm = this.isAmPmMode(true); 686 const timeFormat = ampm === this.AM_PM_MODE.LOWER ? 'g:i a' : ampm === this.AM_PM_MODE.UPPER ? 'g:i A' : 'H:i'; 687 return this.format([['tomorrow', 'tomorrow, ' + timeFormat], ['-', this.convertBitrixFormat(this._getMessage('FORMAT_DATETIME')).replace(/:s/g, '')], ['
687s', 'sago'], ['i', 'iago'], ['today', 'today, ' + timeFormat], ['yesterday', 'yesterday, ' + timeFormat], ['', this.convertBitrixFormat(this._getMessage('FORMAT_DATETIME')).replace(/:s/g, '')]], date, nowDate, isUTC); 688 }, 689 X: () => { 690 const ampm = this.isAmPmMode(true); 691 const timeFormat = ampm === this.AM_PM_MODE.LOWER ? 'g:i a' : ampm === this.AM_PM_MODE.UPPER ? 'g:i A' : 'H:i'; 692 const day = this.format([['tomorrow', 'tomorrow'], ['-', this.convertBitrixFormat(this._getMessage('FORMAT_DATE'))], ['today', 'today'], ['yesterday', 'yesterday'], ['', this.convertBitrixFormat(this._getMessage('FORMAT_DATE'))]], date, nowDate, isUTC); 693 const time = this.format([['tomorrow', timeFormat], ['today', timeFormat], ['yesterday', timeFormat], ['', '']], date, nowDate, isUTC); 694 if (time.length > 0) { 695 return this._getMessage('FD_DAY_AT_TIME').replace(/#DAY#/g, day).replace(/#TIME#/g, time); 696 } else { 697 return day; 698 } 699 }, 700 Q: () => { 701 const daysAgo = intval((nowDate - date) / 60 / 60 / 24 / 1000); 702 if (daysAgo == 0) { 703 return this._getMessage('FD_DAY_DIFF_1').replace(/#VALUE#/g, 1); 704 } else { 705 return this.format([['d', 'ddiff'], ['m', 'mdiff'], ['', 'Ydiff']], date, nowDate); 706 } 707 } 708 }; 709 let cutZeroTime = false; 710 if (_format[0] && _format[0] == '^') { 711 cutZeroTime = true; 712 _format = _format.substr(1); 713 } 714 let result = _format.replace(formatRegex, _replaceDateFormat); 715 if (cutZeroTime) { 716 /* 15.04.12 13:00:00 => 15.04.12 13:00 717 00:01:00 => 00:01 718 4 may 00:00:00 => 4 may 719 01-01-12 00:00 => 01-01-12 720 */ 721 722 result = result.replace(/\s*00:00:00\s*/g, '').replace(/(\d\d:\d\d)(:00)/g, '$1').replace(/(\s*00:00\s*)(?!:)/g, ''); 723 } 724 if (replaceMap.length > 0) { 725 replaceMap.forEach(function (element, index) { 726 result = result.replace('{{' + index + '}}', element); 727 }); 728 } 729 return result; 730 function _formatDateInterval(formats, date, nowDate, isUTC) { 731 const secondsAgo = intval((nowDate - date) / 1000); 732 for (let i = 0; i < formats.length; i++) { 733 const formatInterval = formats[i][0]; 734 const formatValue = formats[i][1]; 735 let match = null; 736 if (formatInterval == 's') { 737 if (secondsAgo < 60) { 738 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 739 } 740 } else if ((match = /^s(\d+)\>?(\d+)?/.exec(formatInterval)) != null) { 741 if (match[1] && match[2]) { 742 if (secondsAgo < match[1] && secondsAgo > match[2]) { 743 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 744 } 745 } else if (secondsAgo < match[1]) { 746 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 747 } 748 } else if (formatInterval == 'i') { 749 if (secondsAgo < 60 * 60) { 750 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 751 } 752 } else if ((match = /^i(\d+)\>?(\d+)?/.exec(formatInterval)) != null) { 753 if (match[1] && match[2]) { 754 if (secondsAgo < match[1] * 60 && secondsAgo > match[2] * 60) { 755 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 756 } 757 } else if (secondsAgo < match[1] * 60) { 758 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 759 } 760 } else if (formatInterval == 'H') { 761 if (secondsAgo < 24 * 60 * 60) { 762 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 763 } 764 } else if ((match = /^H(\d+)\>?(\d+)?/.exec(formatInterval)) != null) { 765 if (match[1] && match[2]) { 766 if (secondsAgo < match[1] * 60 * 60 && secondsAgo > match[2] * 60 * 60) { 767 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 768 } 769 } else if (secondsAgo < match[1] * 60 * 60) { 770 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 771 } 772 } else if (formatInterval == 'd') { 773 if (secondsAgo < 31 * 24 * 60 * 60) { 774 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 775 } 776 } else if ((match = /^d(\d+)\>?(\d+)?/.exec(formatInterval)) != null) { 777 if (match[1] && match[2]) { 778 if (secondsAgo < match[1] * 24 * 60 * 60 && secondsAgo > match[2] * 24 * 60 * 60) { 779 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 780 } 781 } else if (secondsAgo < match[1] * 24 * 60 * 60) { 782 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 783 } 784 } else if (formatInterval == 'm') { 785 if (secondsAgo < 365 * 24 * 60 * 60) { 786 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 787 } 788 } else if ((match = /^m(\d+)\>?(\d+)?/.exec(formatInterval)) != null) { 789 if (match[1] && match[2]) { 790 if (secondsAgo < match[1] * 31 * 24 * 60 * 60 && secondsAgo > match[2] * 31 * 24 * 60 * 60) { 791 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 792 } 793 } else if (secondsAgo < match[1] * 31 * 24 * 60 * 60) { 794 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 795 } 796 } else if (formatInterval == 'now') { 797 if (date.getTime() == nowDate.getTime()) { 798 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 799 } 800 } else if (formatInterval == 'today') { 801 const year = getFullYear(nowDate);
802 const month = getMonth(nowDate); 803 const day = getDate(nowDate); 804 const todayStart = isUTC ? new Date(Date.UTC(year, month, day, 0, 0, 0, 0)) : new Date(year, month, day, 0, 0, 0, 0); 805 const todayEnd = isUTC ? new Date(Date.UTC(year, month, day + 1, 0, 0, 0, 0)) : new Date(year, month, day + 1, 0, 0, 0, 0); 806 if (date >= todayStart && date < todayEnd) { 807 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 808 } 809 } else if (formatInterval == 'todayFuture') { 810 const year = getFullYear(nowDate); 811 const month = getMonth(nowDate); 812 const day = getDate(nowDate); 813 const todayStart = nowDate.getTime(); 814 const todayEnd = isUTC ? new Date(Date.UTC(year, month, day + 1, 0, 0, 0, 0)) : new Date(year, month, day + 1, 0, 0, 0, 0); 815 if (date >= todayStart && date < todayEnd) { 816 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 817 } 818 } else if (formatInterval == 'yesterday') { 819 const year = getFullYear(nowDate);
820 const month = getMonth(nowDate); 821 const day = getDate(nowDate); 822 const yesterdayStart = isUTC ? new Date(Date.UTC(year, month, day - 1, 0, 0, 0, 0)) : new Date(year, month, day - 1, 0, 0, 0, 0); 823 const yesterdayEnd = isUTC ? new Date(Date.UTC(year, month, day, 0, 0, 0, 0)) : new Date(year, month, day, 0, 0, 0, 0); 824 if (date >= yesterdayStart && date < yesterdayEnd) { 825 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 826 } 827 } else if (formatInterval == 'tommorow' || formatInterval == 'tomorrow') { 828 const year = getFullYear(nowDate); 829 const month = getMonth(nowDate); 830 const day = getDate(nowDate); 831 const tomorrowStart = isUTC ? new Date(Date.UTC(year, month, day + 1, 0, 0, 0, 0)) : new Date(year, month, day + 1, 0, 0, 0, 0); 832 const tomorrowEnd = isUTC ? new Date(Date.UTC(year, month, day + 2, 0, 0, 0, 0)) : new Date(year, month, day + 2, 0, 0, 0, 0); 833 if (date >= tomorrowStart && date < tomorrowEnd) { 834 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 835 } 836 } else if (formatInterval == '-') { 837 if (secondsAgo < 0) { 838 return thisDateTimeFormat.format(formatValue, date, nowDate, isUTC); 839 } 840 } 841 } 842 843 //return formats.length > 0 ? thisDateTimeFormat.format(formats.pop()[1], date, nowDate, isUTC) : ''; 844 return formats.length > 0 ? thisDateTimeFormat.format(formats[formats.length - 1][1], date, nowDate, isUTC) : ''; 845 } 846 function getFullYear(date) { 847 return isUTC ? date.getUTCFullYear() : date.getFullYear(); 848 } 849 function getDate(date) { 850 return isUTC ? date.getUTCDate() : date.getDate(); 851 } 852 function getMonth(date) { 853 return isUTC ? date.getUTCMonth() : date.getMonth(); 854 } 855 function getHours(date) { 856 return isUTC ? date.getUTCHours() : date.getHours(); 857 } 858 function getMinutes(date) { 859 return isUTC ? date.getUTCMinutes() : date.getMinutes(); 860 } 861 function getSeconds(date) { 862 return isUTC ? date.getUTCSeconds() : date.getSeconds(); 863 } 864 function getMilliseconds(date) { 865 return isUTC ? date.getUTCMilliseconds() : date.getMilliseconds(); 866 } 867 function getDay(date) { 868 return isUTC ? date.getUTCDay() : date.getDay(); 869 } 870 function setDate(date, dayValue) { 871 return isUTC ? date.setUTCDate(dayValue) : date.setDate(dayValue); 872 } 873 function setMonth(date, monthValue, dayValue) { 874 return isUTC ? date.setUTCMonth(monthValue, dayValue) : date.setMonth(monthValue, dayValue); 875 } 876 function _formatDateMessage(value, messages) { 877 const val = value < 100 ? Math.abs(value) : Math.abs(value % 100); 878 const dec = val % 10; 879 let message = ''; 880 if (val == 0) { 881 message = thisDateTimeFormat._getMessage(messages['0']); 882 } else if (val == 1) { 883 message = thisDateTimeFormat._getMessage(messages['1']); 884 } else if (val >= 10 && val <= 20) { 885 message = thisDateTimeFormat._getMessage(messages['10_20']); 886 } else if (dec == 1) { 887 message = thisDateTimeFormat._getMessage(messages['MOD_1']); 888 } else if (2 <= dec && dec <= 4) { 889 message = thisDateTimeFormat._getMessage(messages['MOD_2_4']); 890 } else { 891 message = thisDateTimeFormat._getMessage(messages['MOD_OTHER']); 892 } 893 return message.replace(/#VALUE#/g, value); 894 } 895 function _replaceDateFormat(match, matchFull) { 896 if (dateFormats[match]) { 897 return dateFormats[match](); 898 } else { 899 return matchFull; 900 } 901 } 902 function intval(number) { 903 return number >= 0 ? Math.floor(number) : Math.ceil(number); 904 } 905 } 906 }]); 907 return DateTimeFormat; 908 }(); 909 babelHelpers.defineProperty(DateTimeFormat, "AM_PM_MODE", { 910 UPPER: 1, 911 LOWER: 2, 912 NONE: false 913 }); 914 babelHelpers.defineProperty(DateTimeFormat, "convertBitrixFormat", convertBitrixFormat); 915 babelHelpers.defineProperty(DateTimeFormat, "getFormat", getFormat); 916 917 const cache = new main_core.Cache.MemoryCache(); 918 919 /** 920 * @memberOf BX.Main.Timezone 921 * 922 * WARNING! Don't use this class or any classes from Timezone namespace on sites without Bitrix Framework. 923 * It is not designed to handle this case and will definitely break. 924 */ 925 const Offset = { 926 get SERVER_TO_UTC() { 927 return cache.remember('SERVER_TO_UTC', () => { 928 return main_core.Text.toInteger(main_core.Loc.getMessage('SERVER_TZ_OFFSET')); 929 }); 930 }, 931 get USER_TO_SERVER() { 932 return cache.remember('USER_TO_SERVER', () => { 933 return main_core.Text.toInteger(main_core.Loc.getMessage('USER_TZ_OFFSET')); 934 }); 935 }, 936 // Date returns timezone offset in minutes by default, change it to seconds 937 // Also offset is negative in UTC+ timezones and positive in UTC- timezones. 938 // By convention Bitrix uses the opposite approach, so change offset sign. 939 get BROWSER_TO_UTC() { 940 return cache.remember('BROWSER_TO_UTC', () => { 941 return main_core.Text.toInteger(new Date().getTimezoneOffset() * 60); 942 }); 943 } 944 }; 945 Object.freeze(Offset); 946 947 function _classStaticPrivateMethodGet(receiver, classConstructor, method) { _classCheckPrivateStaticAccess(receiver, classConstructor); return method; } 948 function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } } 949
950 /** 951 * @memberOf BX.Main.Timezone 952 * 953 * WARNING! Don't use this class or any classes from Timezone namespace on sites without Bitrix Framework. 954 * It is not designed to handle this case and will definitely break. 955 */ 956 let BrowserTime = /*#__PURE__*/function () { 957 function BrowserTime() { 958 babelHelpers.classCallCheck(this, BrowserTime); 959 } 960 babelHelpers.createClass(BrowserTime, null, [{ 961 key: "getTimestamp", 962 /** 963 * Returns timestamp with current time in browser timezone. 964 * 965 * @returns {number} timestamp in seconds 966 */ 967 value: function getTimestamp() { 968 return Math.round(Date.now() / 1000); 969 } 970 /** 971 * Returns Date object with current time in browser timezone. 972 * 973 * @returns {Date} 974 */ 975 }, { 976 key: "getDate", 977 value: function getDate() { 978 return new Date(this.getTimestamp() * 1000); 979 } 980 /** 981 * Converts timestamp in browser timezone to timestamp in user timezone. 982 * 983 * @param browserTimestamp timestamp in browser timezone in seconds 984 * @returns {number} timestamp in user timezone in seconds 985 */ 986 }, { 987 key: "toUser", 988 value: function toUser(browserTimestamp) { 989 return main_core.Text.toInteger(browserTimestamp) + Offset.USER_TO_SERVER; 990 } 991 /** 992 * Converts timestamp in browser timezone to timestamp in server timezone. 993 * 994 * @param browserTimestamp timestamp in browser timezone in seconds 995 * @returns {number} timestamp in server timezone in seconds 996 */ 997 }, { 998 key: "toServer", 999 value: function toServer(browserTimestamp) { 1000 return _classStaticPrivateMethodGet(this, BrowserTime, _toUTC).call(this, browserTimestamp) + Offset.SERVER_TO_UTC; 1001 } 1002 }]); 1003 return BrowserTime; 1004 }(); 1005 function _toUTC(browserTimestamp) { 1006 return main_core.Text.toInteger(browserTimestamp) - Offset.BROWSER_TO_UTC; 1007 } 1008 1009 /** 1010 * @memberOf BX.Main.Timezone 1011 * 1012 * WARNING! Don't use this class or any classes from Timezone namespace on sites without Bitrix Framework. 1013 * It is not designed to handle this case and will definitely break. 1014 * 1015 * ATTENTION! In Bitrix user timezone !== browser timezone. Users can change their timezone from their profile settings 1016 * and the timezone will be different from browser timezone. 1017 */ 1018 let UserTime = /*#__PURE__*/function () { 1019 function UserTime() { 1020 babelHelpers.classCallCheck(this, UserTime); 1021 } 1022 babelHelpers.createClass(UserTime, null, [{ 1023 key: "getTimestamp", 1024 /** 1025 * Returns timestamp with current time in user timezone. 1026 * 1027 * @returns {number} timestamp in seconds 1028 */ 1029 value: function getTimestamp() { 1030 return BrowserTime.toUser(BrowserTime.getTimestamp()); 1031 } 1032 /** 1033 * Returns Date object with current time in user timezone. If you need to get 'now' in a user's perspective, 1034 * use this method instead of 'new Date()'. 1035 * 1036 * Note that 'getTimezoneOffset' will not return correct user timezone, its always returns browser offset 1037 * 1038 * @returns {Date} 1039 */ 1040 }, { 1041 key: "getDate", 1042 value: function getDate() { 1043 return new Date(this.getTimestamp() * 1000); 1044 } 1045 /** 1046 * Converts timestamp in user timezone to timestamp in browser timezone. 1047 * 1048 * @param userTimestamp timestamp in user timezone in seconds 1049 * @returns {number} timestamp in browser timezone in seconds 1050 */ 1051 }, { 1052 key: "toBrowser", 1053 value: function toBrowser(userTimestamp) { 1054 return main_core.Text.toInteger(userTimestamp) + Offset.BROWSER_TO_UTC - Offset.SERVER_TO_UTC - Offset.USER_TO_SERVER; 1055 } 1056 /** 1057 * Converts timestamp in user timezone to timestamp in server timezone. 1058 * 1059 * @param userTimestamp timestamp in user timezone in seconds 1060 * @returns {number} timestamp in server timezone in seconds 1061 */ 1062 }, { 1063 key: "toServer", 1064 value: function toServer(userTimestamp) { 1065 return main_core.Text.toInteger(userTimestamp) - Offset.USER_TO_SERVER; 1066 } 1067 }]); 1068 return UserTime; 1069 }(); 1070 1071 /** 1072 * @memberOf BX.Main.Timezone 1073 * 1074 * WARNING! Don't use this class or any classes from Timezone namespace on sites without Bitrix Framework. 1075 * It is not designed to handle this case and will definitely break. 1076 */ 1077 let ServerTime = /*#__PURE__*/function () { 1078 function ServerTime() { 1079 babelHelpers.classCallCheck(this, ServerTime); 1080 } 1081 babelHelpers.createClass(ServerTime, null, [{ 1082 key: "getTimestamp", 1083 /** 1084 * Returns timestamp with current time in server timezone. 1085 * 1086 * @returns {number} timestamp in seconds 1087 */ 1088 value: function getTimestamp() { 1089 return BrowserTime.toServer(BrowserTime.getTimestamp()); 1090 } 1091 /** 1092 * Returns Date object with current time in server timezone. 1093 * 1094 * Note that 'getTimezoneOffset' will not return correct server timezone, its always returns browser offset 1095 * 1096 * @returns {Date} 1097 */ 1098 }, { 1099 key: "getDate", 1100 value: function getDate() { 1101 return new Date(this.getTimestamp() * 1000); 1102 } 1103 /** 1104 * Converts timestamp in server timezone to timestamp in user timezone. 1105 * 1106 * @param serverTimestamp timestamp in server timezone in seconds 1107 * @returns {number} timestamp in user timezone in seconds 1108 */ 1109 }, { 1110 key: "toUser", 1111 value: function toUser(serverTimestamp) { 1112 return main_core.Text.toInteger(serverTimestamp) + Offset.USER_TO_SERVER; 1113 } 1114 /** 1115 * Converts timestamp in server timezone to timestamp in browser timezone. 1116 * 1117 * @param serverTimestamp timestamp in server timezone in seconds 1118 * @returns {number} timestamp in browser timezone in seconds 1119 */ 1120 }, { 1121 key: "toBrowser", 1122 value: function toBrowser(serverTimestamp) { 1123 return main_core.Text.toInteger(serverTimestamp) + Offset.BROWSER_TO_UTC - Offset.SERVER_TO_UTC; 1124 } 1125 }]); 1126 return ServerTime; 1127 }(); 1128 1129 //compatibility alias 1130 const Date$1 = DateTimeFormat; 1131 const Timezone = Object.freeze({ 1132 Offset, 1133 BrowserTime, 1134 UserTime, 1135 ServerTime 1136 }); 1137 1138 exports.DateTimeFormat = DateTimeFormat; 1139 exports.Date = Date$1; 1140 exports.Timezone = Timezone; 1141 1142}((this.BX.Main = this.BX.Main || {}),BX)); 1143//# sourceMappingURL=main.date.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.