Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2645_ContextAlgorithms/HeuristicLab.Services.WebApp/3.3/WebApp/helper.js @ 17842

Last change on this file since 17842 was 14722, checked in by jkarder, 8 years ago

#2743: worked on web app

  • fixed InvalidOperationException
  • fixed date conversion
File size: 2.2 KB
Line 
1var isDefined = function(variable) {
2    return !(variable === undefined || variable === null);
3};
4
5function zeropad(n) { return ("0" + n).slice(-2); }
6
7Number.prototype.zeropad = function (n) {
8    return (new Array(n + 1).join("0") + this).slice(-n);
9};
10
11Number.prototype.toHHMMSS = function() {
12    d = this;
13    d = Number(d);
14    var years = Math.floor(d / 31536000);
15    var days = Math.floor(d / 86400 % 365);
16    var h = Math.floor(d / 3600 % 24);
17    var m = Math.floor(d % 3600 / 60);
18    var s = Math.floor(d % 3600 % 60);
19    var timeStr = "";
20    if (years > 0) {
21        timeStr = years + "y ";
22    }
23    if (days > 0) {
24        timeStr = timeStr + days + "d ";
25    }
26    return timeStr + h.zeropad(2) + ":" + m.zeropad(2) + ":" + s.zeropad(2);
27};
28
29var ConvertDate = function (date) {
30    var day = date.getDate().zeropad(2);
31    var month = (1 + date.getMonth()).zeropad(2);
32    var year = date.getFullYear();
33    var hour = (date.getHours() + date.getTimezoneOffset() / 60).zeropad(2);
34    var minute = date.getMinutes().zeropad(2);
35    var second = date.getSeconds().zeropad(2);
36    return year + '-' + month + '-' + day + 'T' + hour + ':' + minute + ':' + second + '.000Z';
37};
38
39var ConvertFromDate = function (date) {
40    var day = date.getDate().zeropad(2);     
41    var month = (1 + date.getMonth()).zeropad(2);
42    var year = date.getFullYear();
43    return year + '-' + month + '-' + day + 'T00:00:00.000Z';
44};
45
46var ConvertToDate = function (date) {
47    var day = date.getDate().zeropad(2);
48    var month = (1 + date.getMonth()).zeropad(2);
49    var year = date.getFullYear();
50    return year + '-' + month + '-' + day + 'T23:59:59.000Z';
51};
52
53var CSharpDateToString = function (datetime) {
54    var date = new Date(Date.parse(datetime));
55    var day = date.getDate().zeropad(2);
56    var month = (1 + date.getMonth()).zeropad(2);
57    var year = date.getFullYear();
58    var hour = date.getHours().zeropad(2);
59    var minute = date.getMinutes().zeropad(2);
60    var second = date.getSeconds().zeropad(2);
61    return day + '.' + month + '.' + year + ' ' + hour + ':' + minute + ':' + second;
62};
63
64var decryptString = function(s) {
65    return CryptoJS.AES.decrypt(s, "heuristiclab").toString(CryptoJS.enc.Utf8);
66};
Note: See TracBrowser for help on using the repository browser.