You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
1.2 KiB

define(["jquery","core/ajax","core/sessionstorage","core/config"],function(a,b,c,d){var e=86400,f={},g=function(b){var c=a("html").attr("lang").replace(/-/g,"_");return"core_user_date/"+c+"/"+d.usertimezone+"/"+b.timestamp+"/"+b.format},h=function(a){return c.get(a)},i=function(a,b){c.set(a,b)},j=function(a){return"undefined"!=typeof f[a]},k=function(a){return f[a]},l=function(a,b){f[a]=b},m=function(a){var c=a.map(function(a){return{timestamp:a.timestamp,format:a.format}}),e={methodname:"core_get_user_dates",args:{contextid:d.contextid,timestamps:c}};return b.call([e],!0,!0)[0].then(function(b){b.dates.forEach(function(b,c){var d=a[c],e=g(d);i(e,b),d.deferred.resolve(b)})})["catch"](function(b){a.forEach(function(a){a.deferred.reject(b)})})},n=function(b){var c=[],d=[];return b.forEach(function(b){var e=g(b);if(j(e))d.push(k(e));else{var f=a.Deferred(),i=h(e);i?f.resolve(i):(b.deferred=f,c.push(b)),l(e,f.promise()),d.push(f.promise())}}),c.length&&m(c),a.when.apply(a,d).then(function(){return 1===arguments.length?[arguments[0]]:Array.apply(null,arguments)})},o=function(a,b){var c=a>b,d=Math.abs(a-b),f=c?Math.floor(d/e):Math.ceil(d/e),g=f*e,h=c?b+g:b-g;return h};return{get:n,getUserMidnightForTimestamp:o}});