| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- /**
- * DevExtreme (ui/scheduler/timezones/ui.scheduler.timezones.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- var query = require("../../../data/query");
- var errors = require("../../../core/errors");
- var tzData = require("./ui.scheduler.timezones_data");
- var SchedulerTimezones = {
- _displayNames: tzData.displayNames,
- _list: tzData.timezones,
- getTimezones: function() {
- return this._list
- },
- getDisplayNames: function() {
- return this._displayNames
- },
- queryableTimezones: function() {
- return query(this.getTimezones())
- },
- getTimezoneById: function(id) {
- var result;
- var i = 0;
- var tzList = this.getTimezones();
- if (id) {
- while (!result) {
- if (!tzList[i]) {
- errors.log("W0009", id);
- return
- }
- var currentId = tzList[i].id;
- if (currentId === id) {
- result = tzList[i]
- }
- i++
- }
- }
- return result
- },
- getTimezoneOffsetById: function(id, dateTimeStamp) {
- var tz = this.getTimezoneById(id);
- var offsets;
- var offsetIndices;
- var untils;
- var result;
- if (tz) {
- if (tz.link) {
- var rootTz = this.getTimezones()[tz.link];
- offsets = rootTz.offsets;
- untils = rootTz.untils;
- offsetIndices = rootTz.offsetIndices
- } else {
- offsets = tz.offsets;
- untils = tz.untils;
- offsetIndices = tz.offsetIndices
- }
- result = this.getUtcOffset(offsets, offsetIndices, untils, dateTimeStamp)
- }
- return result
- },
- getUtcOffset: function(offsets, offsetIndices, untils, dateTimeStamp) {
- var index = 0;
- var offsetIndicesList = offsetIndices.split("");
- var untilsList = untils.split("|").map(function(until) {
- if ("Infinity" === until) {
- return null
- }
- return 1e3 * parseInt(until, 36)
- });
- var currentUntil = 0;
- for (var i = 0, listLength = untilsList.length; i < listLength; i++) {
- currentUntil += untilsList[i];
- if (dateTimeStamp >= currentUntil) {
- index = i;
- continue
- } else {
- break
- }
- }
- if (untilsList[index + 1]) {
- index++
- }
- return offsets[Number(offsetIndicesList[index])]
- },
- getTimezoneShortDisplayNameById: function(id) {
- var tz = this.getTimezoneById(id);
- var result;
- if (tz) {
- result = tz.DisplayName.substring(0, 11)
- }
- return result
- },
- getTimezonesDisplayName: function() {
- return query(this.getDisplayNames()).sortBy().toArray()
- },
- getTimezoneDisplayNameById: function(id) {
- var tz = this.getTimezoneById(id);
- return tz ? this.getDisplayNames()[tz.winIndex] : ""
- },
- getSimilarTimezones: function(id) {
- if (!id) {
- return []
- }
- var tz = this.getTimezoneById(id);
- return this.getTimezonesIdsByWinIndex(tz.winIndex)
- },
- getTimezonesIdsByWinIndex: function(winIndex) {
- return this.queryableTimezones().filter(["winIndex", winIndex]).sortBy("title").toArray().map(function(item) {
- return {
- id: item.id,
- displayName: item.title
- }
- })
- },
- getTimezonesIdsByDisplayName: function(displayName) {
- var displayNameIndex = this.getDisplayNames().indexOf(displayName);
- return this.getTimezonesIdsByWinIndex(displayNameIndex)
- },
- getClientTimezoneOffset: function(date) {
- return 6e4 * date.getTimezoneOffset()
- },
- processDateDependOnTimezone: function(date, tzOffset) {
- var result = new Date(date);
- if (tzOffset) {
- var tzDiff = tzOffset + this.getClientTimezoneOffset(date) / 36e5;
- result = new Date(result.setHours(result.getHours() + tzDiff))
- }
- return result
- }
- };
- module.exports = SchedulerTimezones;
|