-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.hgn
executable file
·79 lines (75 loc) · 1.67 KB
/
calendar.hgn
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /bin/sh
exec huginn -E "${0}" "${@}"
#! huginn
import DateTime as dt;
import Algorithms as algo;
import Text as text;
class Calendar {
_monthNames_ = none;
_dayNames_ = none;
constructor() {
t = dt.now();
_monthNames_ = algo.materialize(
algo.map(
algo.range( 1, 13 ),
@[t]( m ) { dt.format( "%B", t.set_date( 1, m, 1 ) ); }
),
tuple
);
_dayNames_ = algo.materialize(
algo.map(
algo.range( 1, 8 ),
@[t]( d ) { dt.format( "%a", t.set_date( 1, 1, d ) )[:2]; }
),
tuple
);
}
print_year( year_, cols_ ) {
t = dt.now();
print( "{:^66d}\n".format( year_ ) );
for ( rm : algo.range( 12 / cols_ ) ) {
m = rm * cols_;
print( text.repeat( "{:^22s}", cols_ ).format( _monthNames_[m:m + cols_]... ) + "\n" );
day = [];
daysInMonth = [];
for ( mc : algo.range( cols_ ) ) {
print( " {} {} {} {} {} {} {} ".format( _dayNames_... ) );
t.set_date( year_, m + mc + 1, 1 );
day.push( - t.get_day_of_week() + 1 );
daysInMonth.push( t.get_days_in_month() );
}
print( "\n" );
haveDay = true;
while ( haveDay ) {
haveDay = false;
for ( mc : algo.range( cols_ ) ) {
for ( d : algo.range( 7 ) ) {
if ( ( day[mc] > 0 ) && ( day[mc] <= daysInMonth[mc] ) ) {
print( " {:2d}".format( day[mc] ) );
haveDay = true;
} else {
print( " " );
}
day[mc] += 1;
}
print( " " );
}
print( "\n" );
}
}
}
}
main( argv_ ) {
cal = Calendar();
cols = size( argv_ ) > 2 ? integer( argv_[2] ) : 3;
if ( 12 % cols != 0 ) {
cols = 3;
}
cal.print_year(
size( argv_ ) > 1
? integer( argv_[1] )
: dt.now().get_year(),
cols
);
}
// # vim: set ft=huginn