PageSourceSearch

https://worldofwarplanes.com/static/1.22.0/portal/js/wgsdk.time.js

js worldofwarplanes.com collected 2026-09-24 21:54:28 UTC 19,062 bytes, 537 lines download raw bytes

1wgsdk = window.wgsdk || {};
2wgsdk.vars = window.wgsdk.vars || {};
3
4wgsdk.time = {};
5wgsdk.time.init = (function () {
6
7    var obj = function(){
8        var wotTimeDelimiter = wgsdk.vars.TIME_DELIMITER || ':';
9        var wotDateDelimiter = wgsdk.vars.DATE_DELIMITER || '.';
10        var wotDateFormat = wgsdk.vars.DATE_FORMAT || 'dmy';
11
12        function PadZeros2(number){
13            if(number === undefined) {
14                return "00";
15            }
16            var str = number.toString();
17            switch(str.length) {
18            case 0: return "00";
19            case 1: return "0"+str;
20            default: return str;
21            }
22        }
23
24        function FormatDate(day, month, year, delimiter) {
25            var str = '';
26            for (var i=0; i<wotDateFormat.length; ++i) {
27                switch (wotDateFormat.charAt(i).toLowerCase()) {
28                case 'y': {
29                    str += year;
30                    break;
31                }
32                case 'm': {
33                    str += month;
34                    break;
35                }
36                case 'd': {
37                    str += day;
38                    break;
39                }
40                }
41                if (i != wotDateFormat.length - 1) {
42                    str += delimiter;
43                }
44            }
45            return str;
46        }
47
48        Date.prototype.wotGetDatepickerDateFormat = function() {
49            var str = '';
50            for (var i=0; i<wotDateFormat.length; ++i) {
51                switch (wotDateFormat.charAt(i).toLowerCase()) {
52                case 'y': {
53                    str += 'yy';
54                    break;
55                }
56                case 'm': {
57                    str += 'mm';
58                    break;
59                }
60                case 'd': {
61                    str += 'dd';
62                    break;
63                }
64                }
65                if (i != wotDateFormat.length - 1) {
66                    str += wotDateDelimiter;
67                }
68            }
69            return str;
70        };
71
72        Date.prototype.wotGetDatepickerTimeFormat = function() {
73            return 'hh'+wotTimeDelimiter+'mm'+wotTimeDelimiter+'ss';
74        };
75
76        Date.prototype.wotFormatTime = function(h, m, s) {
77            var str =
78                PadZeros2(h) + wotTimeDelimiter +
79                PadZeros2(m) + wotTimeDelimiter +
80                PadZeros2(s);
81            return str;
82        };
83
84        Date.prototype.wotFormatTimeHM = function(h, m) {
85            if (m === undefined) {
86                if (h === undefined) {
87                    h = this.getHours();
88                    m = this.getMinutes();
89                }
90                else {
91                    h = Math.floor(h / 1000);
92
93                    m = Math.floor(h % (60*60) / 60);
94                    h = Math.floor(h % (60*60*24) / (60*60));
95                }
96            }
97            var str = PadZeros2(h) + wotTimeDelimiter + PadZeros2(m);
98            return str;
99        };
100
101        Date.prototype.wotFormatTimeMS = function(m, s) {
102            if (s === undefined) {
103                if (m === undefined) {
104                    m = this.getMinutes();
105                    s = this.getSeconds();
106                }
107                else {
108                    m = Math.floor(m / 1000);
109
110                    s = m % 60;
111                    m = Math.floor(m % (60*60) / 60);
112                }
113            }
114            var str = PadZeros2(m) + wotTimeDelimiter + PadZeros2(s);
115            return str;
116        };
117
118        Date.prototype.wotFormatDate = function(day, month, year) {
119            if (day === undefined) day = this.getDate();
120            if (month === undefined) month = this.getMonth();
121            if (year === undefined) year = this.getFullYear();
122
123            // universal big-endian format time
124            day = PadZeros2(parseInt(day));
125            month = PadZeros2(parseInt(month) + 1);
126
127            var str = FormatDate(day, month, year, wotDateDelimiter);
128
129            return str;
130        };
131
132
133        function FormatDateWithoutYear(day, month, delimiter) {
134            date_array = [];
135            for (var i=0; i<wotDateFormat.length; ++i) {
136                var code = wotDateFormat.charAt(i).toLowerCase();
137                if (code == 'm') {
138                    date_array.push(month)
139                }else if(code=='d'){
140                    date_array.push(day)
141                }
142            }
143            return date_array.join(delimiter)
144        }
145
146        Date.prototype.wotFormatDateWithoutYear = function(day, month) {
147            if (day === undefined) day = this.getDate();
148            if (month === undefined) month = this.getMonth();
149
150            // universal big-endian format time
151            day = PadZeros2(parseInt(day));
152            month = PadZeros2(parseInt(month) + 1);
153            var str = FormatDateWithoutYear(day, month, wotDateDelimiter);
154            return str;
155        };
156
157
158        Date.prototype.wotUTCDateStringWithoutYear = function(){
159            var str = this.wotFormatDateWithoutYear(this.getUTCDate(),
160                                                    this.getUTCMonth());
161            return str;
162        };
163        
164        Date.prototype.wotTimeString = function(time){
165            if (time !== undefined) {
166                time = Math.floor(time / 1000);
167
168                var s = time % 60;
169                var m = ( (time - s) / 60) % 60;
170                var h = (time - m * 60 - s) / (60*60) % 24;
171                return this.wotFormatTime(h, m ,s);
172            }
173
174            return this.wotFormatTime(this.getHours(), this.getMinutes(), this.getSeconds());
175        };
176
177        Date.prototype.wotUTCTimeString = function(){
178            var str =
179                PadZeros2(this.getUTCHours()) + wotTimeDelimiter +
180                PadZeros2(this.getUTCMinutes()) + wotTimeDelimiter +
181                PadZeros2(this.getUTCSeconds());
182            return str;
183        };
184
185        Date.prototype.wotDateString = function(){
186            return this.wotFormatDate();
187        };
188        Date.prototype.wotUTCDateString = function(){
189            var str = this.wotFormatDate(this.getUTCDate(),
190                                        this.getUTCMonth(),
191                                        this.getUTCFullYear());
192            return str;
193        };
194
195        Date.prototype.wotDateTimeString = function(){
196            return this.wotDateString()+' '+this.wotFormatTimeHM();
197        };
198        Date.prototype.wotUTCDateTimeString = function(){
199            return this.wotUTCDateString()+' '+this.wotFormatTimeHM(this.getUTCHours(), this.getUTCMinutes());
200        };
201
202        // time in seconds
203        // after converting, norm value to be in the same in [0h 0m 0s .. 23h 59m 59s]
204        Date.prototype.wotTimeFromUTC = function(time) {
205            time = Math.floor(time / 1000);
206
207            var offset = -this.getTimezoneOffset() * 60;
208            time += offset;
209
210            var day = 24 * 60 * 60;
211
212            time %= day;
213            if (time < 0) {
214                time += day;
215            }
216            return time * 1000;
217        };
218
219        Date.prototype.wotToLocaleDayOfWeek = function(dayNumber){
220
221            if (dayNumber === undefined) dayNumber = this.getDay();
222
223            switch(dayNumber) {
224                case 0: return translate('TIME_SUNDAY');
225                case 1: return translate('TIME_MONDAY');
226                case 2: return translate('TIME_TUESDAY');
227                case 3: return translate('TIME_WEDNESDAY');
228                case 4: return translate('TIME_THURSDAY');
229                case 5: return translate('TIME_FRIDAY');
230                case 6: return translate('TIME_SATURDAY');
231            }
232            return this.getDay();
233        };
234
235        Date.prototype.wotToLocaleMonthName = function(monthNumber){
236
237            if (monthNumber === undefined) monthNumber = this.getMonth();
238
239            switch(monthNumber) {
240                case 0: return translate('TIME_JANUARY');
241                case 1: return translate('TIME_FEBRUARY');
242                case 2: return translate('TIME_MARCH');
243                case 3: return translate('TIME_APRIL');
244                case 4: return translate('TIME_MAY');
245                case 5: return translate('TIME_JUNE');
246                case 6: return translate('TIME_JULY');
247                case 7: return translate('TIME_AUGUST');
248                case 8: return translate('TIME_SEPTEMBER');
249                case 9: return translate('TIME_OCTOBER');
250                case 10: return translate('TIME_NOVEMBER');
251                case 11: return translate('TIME_DECEMBER');
252            }
253
254            return this.getMonth();
255        };
256
257        Date.prototype.wotToLocaleDateString = function(){
258            var str = FormatDate(this.getDate(), this.wotToLocaleMonthName(), this.getFullYear(), ' ') + translate('TIME_YEAR_REDUCTION');
259            return str;
260        };
261
262        Date.prototype.newUTCDate = function() {
263            return new Date(
264                this.getUTCFullYear(), this.getUTCMonth(), this.getUTCDate(),
265                this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds(),
266                this.getUTCMilliseconds()
267            );
268        };
269    };
270
271    return obj
272
273})();
274
275
276function wotGetTimepickerDefaults() {
277    var timeFormat = get_format('TIME_FORMAT');
278
279    // 12-hour format strings from https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
280    var timeTwelveHourFormats = ['A', 'a', 'f', 'g', 'h', 'P'];
281    var timeTwelveHour = false;
282    for (var i in timeTwelveHourFormats) {
283        if (timeFormat.indexOf(timeTwelveHourFormats[i]) != -1)
284            timeTwelveHour = true;
285    }
286
287    return {
288        timeOnlyTitle: translate('TIME_DT_PICKER_CHOOSE_TIME'),
289        timeText: translate('TIME_DT_PICKER_TIME'),
290        hourText: translate('TIME_DT_PICKER_HOURS'),
291        minuteText: translate('TIME_DT_PICKER_MINUTES'),
292        secondText: translate('TIME_DT_PICKER_SECONDS'),
293        currentText: translate('TIME_DT_PICKER_CURRENT'),
294        closeText: translate('TIME_DT_PICKER_CLOSE'),
295        cancelText: translate('TIME_DT_PICKER_CANCEL'),
296        ampm: timeTwelveHour
297    };
298}
299
300function wotGetDatepickerDefaults() {
301
302    var date = new Date();
303
304    return { closeText: translate('TIME_DT_PICKER_CLOSE'),
305             prevText: translate('TIME_DT_PICKER_PREV'),
306             nextText: translate('TIME_DT_PICKER_NEXT'),
307             currentText: translate('TIME_DT_PICKER_TODAY'),
308             monthNames: [ translate('TIME_JANUARY'),
309                           translate('TIME_FEBRUARY'),
310                           translate('TIME_MARCH'),
311                           translate('TIME_APRIL'),
312                           translate('TIME_MAY'),
313                           translate('TIME_JUNE'),
314                           translate('TIME_JULY'),
315                           translate('TIME_AUGUST'),
316                           translate('TIME_SEPTEMBER'),
317                           translate('TIME_OCTOBER'),
318                           translate('TIME_NOVEMBER'),
319                           translate('TIME_DECEMBER')],
320             monthNamesShort: [ translate('TIME_SHORT_JANUARY'),
321                                translate('TIME_SHORT_FEBRUARY'),
322                                translate('TIME_SHORT_MARCH'),
323                                translate('TIME_SHORT_APRIL'),
324                                translate('TIME_SHORT_MAY'),
325                                translate('TIME_SHORT_JUNE'),
326                                translate('TIME_SHORT_JULY'),
327                                translate('TIME_SHORT_AUGUST'),
328                                translate('TIME_SHORT_SEPTEMBER'),
329                                translate('TIME_SHORT_OCTOBER'),
330                                translate('TIME_SHORT_NOVEMBER'),
331                                translate('TIME_SHORT_DECEMBER')],
332             dayNames: [ translate('TIME_SUNDAY'),
333                         translate('TIME_MONDAY'),
334                         translate('TIME_TUESDAY'),
335                         translate('TIME_WEDNESDAY'),
336                         translate('TIME_THURSDAY'),
337                         translate('TIME_FRIDAY'),
338                         translate('TIME_SATURDAY')],
339             dayNamesShort: [ translate('TIME_SHORT_SUNDAY'),
340                              translate('TIME_SHORT_MONDAY'),
341                              translate('TIME_SHORT_TUESDAY'),
342                              translate('TIME_SHORT_WEDNESDAY'),
343                              translate('TIME_SHORT_THURSDAY'),
344                              translate('TIME_SHORT_FRIDAY'),
345                              translate('TIME_SHORT_SATURDAY')],
346             dayNamesMin: [ translate('TIME_MIN_SUNDAY'),
347                            translate('TIME_MIN_MONDAY'),
348                            translate('TIME_MIN_TUESDAY'),
349                            translate('TIME_MIN_WEDNESDAY'),
350                            translate('TIME_MIN_THURSDAY'),
351                            translate('TIME_MIN_FRIDAY'),
352                            translate('TIME_MIN_SATURDAY')],
353             weekHeader: translate('TIME_DT_PICKER_WEEK_HEADER'),
354             dateFormat: date.wotGetDatepickerDateFormat(),
355             firstDay: 1,
356             isRTL: false,
357             showMonthAfterYear: false,
358             yearSuffix: ''};
359}
360
361
362function wotUpdateDateTimeFields(selector_prefix) {
363    if (selector_prefix){
364        selector_prefix = selector_prefix + ' '
365    }else{
366        selector_prefix = ''
367    }
368
369    function GetDateObject(el) {
370        var timestamp = parseInt(el.data('timestamp'), 10);
371
372        if (!timestamp) return undefined;
373
374        var date = new Date(timestamp * 1000);
375
376        return date;
377    }
378
379    jQuery(selector_prefix + '.js-datetime-format').each(function(i, v) {
380        var el = jQuery(v);
381        var date = GetDateObject(el);
382        if (date && date instanceof Date) {
383            var str = date.wotDateTimeString();
384            if (str) el.html(str);
385        }
386    });
387
388    jQuery(selector_prefix + '.js-date-format').each(function(i, v) {
389        var el = jQuery(v);
390        var date = GetDateObject(el);
391        if (date && date instanceof Date) {
392            var str = date.wotDateString();
393            if (str) el.html(str);
394        }
395    });
396
397    jQuery(selector_prefix + '.js-date-format-utc').each(function(i, v) {
398        var el = jQuery(v);
399        var date = GetDateObject(el);
400        if (date && date instanceof Date) {
401            var str = date.wotUTCDateString();
402            if (str) el.html(str);
403        }
404    });
405    
406    jQuery(selector_prefix + '.js-date-format-without-year').each(function(i, v) {
407        var el = jQuery(v);
408        var date = GetDateObject(el);
409        if (date && date instanceof Date) {
410            var str = date.wotFormatDateWithoutYear();
411            if (str) el.html(str);
412        }
413    });
414
415    jQuery(selector_prefix + '.js-time-format').each(function(i, v) {
416        var el = jQuery(v);
417        var date = GetDateObject(el);
418        if (date && date instanceof Date) {
419            var str = date.wotFormatTimeHM();
420            if (str) el.html(str);
421        }
422    });
423}
424
425
426// by default jQuery does not availbale in django admin
427if (window.jQuery) {
428
429    wgsdk.time.init();
430
431    jQuery(document).ready(function(){
432        wotUpdateDateTimeFields();
433    });
434
435    ( function ($) {
436
437        function Datetime(elem, param)
438        {
439            var api = this;
440            var text = $(elem).text();
441
442            if ( param.timestamp != null )
443                text = param.timestamp;
444
445            else if ($(elem).data( 'timestamp' ) != null)
446                text = $(elem).data( 'timestamp' );
447
448            var local  = new Date();
449            var source = new Date( parseInt(text) * 1000 );
450            var value  = source.wotDateTimeString();
451
452            if ( param.style == "relative" )
453            {
454                if ( param.HM == undefined || param.HM == null )
455                    param.HM = true;
456
457                var milliseconds = new Date( local.getTime() - source.getTime() ).getTime();
458                var minute = 60 * 1000;
459                var hour = minute * 60;
460                var day = ( hour * local.getHours() ) + ( minute * local.getMinutes() );
461                var yesterday = day + ( hour * 24 );
462
463                if ( milliseconds < minute ){
464                    value = translate('DATETIME_ONE_MINUTE_AGO');
465
466                } else if ( milliseconds < hour ) {
467                    value = translate('DATETIME_ONE_HOUR_AGO');
468
469                } else if ( milliseconds < day ) {
470                    value = ( param.HM ) ? translate('DATETIME_TODAY') + ', ' + source.wotFormatTimeHM() : translate('DATETIME_TODAY');
471
472                } else if ( milliseconds < yesterday ) {
473                    value = ( param.HM ) ? translate('DATETIME_YESTERDAY') + ', ' + source.wotFormatTimeHM() : translate('DATETIME_YESTERDAY');
474
475                } else {
476                    value = ( param.HM ) ? source.wotDateTimeString() : source.wotDateString();
477                }
478            }
479
480            $(elem).text( value );
481            return this;
482        }
483
484        $.fn.datetime = function(param){
485            var ret;
486
487            this.each( function() {
488                var elem = $(this);
489                elem.data('wg_datetime', new Datetime(elem, param));
490                ret = ret ? ret.add(elem) : elem;
491            });
492
493            return ret;
494        };
495
496        // wotTimePickerInit wotDatePickerInit start
497        function wotDateTimePickerInitParams(params) {
498            if (params.onClose) {
499                var callback = params.onClose;
500                params.onClose = function() {
501                    callback();
502                    $(this).parent().parent().removeClass('js-calendar-open');
503                }
504            }
505            else {
506                params.onClose = function() {
507                    $(this).parent().parent().removeClass('js-calendar-open');
508                }
509            }
510        }
511        function wotTimePickerInit(widgetSelector, params) {
512            wotDateTimePickerInitParams(params);
513            widgetSelector.datetimepicker(params);
514        }
515        window.wotTimePickerInit = wotTimePickerInit;
516
517        function wotDatePickerInit(widgetSelector, params) {
518            wotDateTimePickerInitParams(params);
519            widgetSelector.datepicker(params);
520        }
521        window.wotDatePickerInit = wotDatePickerInit;
522
523        $(document).on("click", '.js-calendar-button', function(){
524            if ($(this).parent().hasClass('js-calendar-open') ) {
525                $(this).parent().removeClass('js-calendar-open');
526            } else {
527                $(this).parent().find('input').focus();
528            }
529        });
530        $(document).on("focus", '.js-calendar-input', function(){
531            $(this).parent().parent().addClass('js-calendar-open');
532        });
533        // wotTimePickerInit wotDatePickerInit end
534
535    })(jQuery);
536
537}

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.