#import( 'dart:html' );
main()
{
var today = new Date.now();
var firstDay = new Date( today.year, today.month, 1);
var lastDay = new Date( today.year, today.month+1, 1 ).subtract( const Duration(1) );
var calendar = new Element.html( '''
<table class="calendar">
<thead>
<tr>
<th class="mon weekday">月</th>
<th class="tue weekday">火</th>
<th class="wed weekday">水</th>
<th class="the weekday">木</th>
<th class="fri weekday">金</th>
<th class="sat weekend">土</th>
<th class="sun weekend">日</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
''');
var createWeek = () {
var week = new TableRowElement();
for( var i=0; i<7; i++ ) week.nodes.add( new TableCellElement() );
return week;
};
var currentDay = new Date( today.year, today.month, 1);
var tbody = calendar.query( 'tbody' );
var week;
while( currentDay <= lastDay ) {
if( currentDay.day == 1 || currentDay.weekday == Date.MON )
tbody.nodes.add( (week = createWeek()) );
week.nodes[ currentDay.weekday-1 ].addText( currentDay.day.toString() );
currentDay = currentDay.add( const Duration(1) );
}
document.query( 'body' ).nodes.add( calendar );
}
I2ltcG9ydCggJ2RhcnQ6aHRtbCcgKTsKCm1haW4oKQp7CiAgdmFyIHRvZGF5ID0gbmV3IERhdGUubm93KCk7CiAgdmFyIGZpcnN0RGF5ID0gbmV3IERhdGUoIHRvZGF5LnllYXIsIHRvZGF5Lm1vbnRoLCAxKTsKICB2YXIgbGFzdERheSA9IG5ldyBEYXRlKCB0b2RheS55ZWFyLCB0b2RheS5tb250aCsxLCAxICkuc3VidHJhY3QoIGNvbnN0IER1cmF0aW9uKDEpICk7CgogIHZhciBjYWxlbmRhciA9IG5ldyBFbGVtZW50Lmh0bWwoICcnJwogICAgPHRhYmxlIGNsYXNzPSJjYWxlbmRhciI+CiAgICA8dGhlYWQ+CiAgICAgIDx0cj4KICAgICAgPHRoIGNsYXNzPSJtb24gd2Vla2RheSI+5pyIPC90aD4KICAgICAgPHRoIGNsYXNzPSJ0dWUgd2Vla2RheSI+54GrPC90aD4KICAgICAgPHRoIGNsYXNzPSJ3ZWQgd2Vla2RheSI+5rC0PC90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