-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathgetTimeZoneInfo.js
More file actions
34 lines (32 loc) · 1.26 KB
/
getTimeZoneInfo.js
File metadata and controls
34 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import ajax from './ajax.js'
import getURL from './getURL.js'
/**
* @name $SP().getTimeZoneInfo
* @function
* @category utils
* @description Permits to retrieve the TimeZone informations (ID, Description, XMLTZone) based on the server's timezone
*
* @param {Object} [settings]
* @param {String} [settings.url="current website"]
* @return {Object} resolve({ID, Description, XMLTZone}), reject(error)
*/
export default async function getTimeZoneInfo(settings) {
// https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-server/ms453853(v%3Doffice.15)
try {
settings = settings || {};
if (!settings.url) {
settings.url = await getURL();
}
let data = await ajax.call(this, {url:settings.url+'/_api/web/RegionalSettings/TimeZone'});
return Promise.resolve({
ID:data.d.Id,
Description:data.d.Description,
Bias:data.d.Information.Bias,
StandardBias:data.d.Information.StandardBias,
DaylightBias:data.d.Information.DaylightBias,
XMLTZone:"<timeZoneRule><standardBias>"+(data.d.Information.Bias*1+data.d.Information.StandardBias*1)+"</standardBias><additionalDaylightBias>"+data.d.Information.DaylightBias+"</additionalDaylightBias></timeZoneRule>"
})
} catch(err) {
return Promise.reject(err);
}
}