Welcome, guest | Sign In | My Account | Store | Cart

Prints calendar at current month.

Batch, 60 lines
 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@set @env=0 /*
  @echo off
    set @env=
    cscript //nologo //e:jscript "%~dpnx0"
  exit /b
*/

var cal = cal || {
  getMonthLastDay : function(year, month) {
    for (var i = 29; i < 33; i++) {
      if (new Date(year, month, i).getMonth() != month) return --i;
    }
  },
  
  setFormatString : function(arr) {
    var str, i;
    for (i = 0; i < arr.length; i++) {
      str = ' ' + arr[i];
      if(str.length == 2) str = ' ' + str;
      WScript.StdOut.Write(str);
    }
    WScript.StdOut.WriteLine();
  },
  
  getCurrentMonth : function() {
    var arr = [], cur, i, mon = {
      0  : '       January',
      1  : '       February',
      2  : '        March',
      3  : '        April',
      4  : '         May',
      5  : '         June',
      6  : '         July',
      7  : '        August',
      8  : '      September',
      9  : '       October',
      10 : '       November',
      11 : '       December'
    };
    with (new Date()) {
      cur = new Date(getYear(), getMonth(), 1).getDay();
      if (cur != 0) {
        for (i = 1; i <= cur; i++) arr.push(' ');
      }
      
      for (i = 1; i <= this.getMonthLastDay(getYear(), getMonth()); i++) {
        arr.push(new Date(getYear(), getMonth(), i).getDate());
      }
      
      WScript.echo(mon[getMonth()]);
      WScript.echo(" Su Mo Tu We Th Fr Sa");
      for (i = 0; i <= arr.length; i += 7) {
        this.setFormatString(arr.slice(i, i + 7));
      }
      WScript.echo("\n Today: " + getDate());
    }
  }
}

WScript.echo(cal.getCurrentMonth());