Project

General

Profile

Feature #11262 ยป pfsense-sel-month.js

Andrei Caba, 01/18/2021 05:22 PM

 
1
var themonthsel = document.getElementById("monthsel").value;
2
var theyearsel = new Date().getFullYear();
3

    
4
Date.prototype.getWeek = function() {
5
  var onejan = new Date(theyearsel, 0, 1);
6
  return Math.ceil(((date2calc - onejan) / 86400000 + loopdownvalues(onejan.getDay(), 0, 6) + 1) / 7);
7
};
8

    
9
function loopupvalues(counter, min, max) {
10
  if (counter < max) {
11
    counter++;
12
  } else {
13
    counter = min;
14
  }
15
  return counter;
16
}
17

    
18
function loopdownvalues(counter, min, max) {
19
  if (counter <= min) {
20
    counter = max;
21
  } else {
22
    counter--;
23
  }
24
  return counter;
25
}
26

    
27
var theday = 1;
28
var date2calc = new Date(theyearsel, themonthsel - 1, theday);
29
var thelastday = new Date(theyearsel, themonthsel, 0).getDate();
30
var theweekday = date2calc.getDay();
31
var theweek = date2calc.getWeek();
32

    
33
var sel2toggle =
34
  'w' +
35
  loopdownvalues(theweek, 1, 53) +
36
  'p' +
37
  loopdownvalues(theweekday + 1, 1, 7) +
38
  '-m' +
39
  themonthsel +
40
  'd' +
41
  theday;
42

    
43
for (theday = 1; theday <= thelastday; theday++) {
44
  date2calc.setDate(theday);
45
  theweekday = date2calc.getDay();
46
  theweek = date2calc.getWeek();
47
  sel2toggle =
48
    'w' +
49
    loopdownvalues(theweek, 1, 53) +
50
    'p' +
51
    loopdownvalues(theweekday + 1, 1, 7) +
52
    '-m' +
53
    themonthsel +
54
    'd' +
55
    theday;
56
//  console.log(sel2toggle);
57
  	daytoggle(sel2toggle);
58
}
    (1-1/1)