Skip to content

Instantly share code, notes, and snippets.

@Myoga1012
Last active January 30, 2023 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Myoga1012/38cacec36f4233137738 to your computer and use it in GitHub Desktop.
Save Myoga1012/38cacec36f4233137738 to your computer and use it in GitHub Desktop.
CoffeeScriptでカレンダーを出力するソースコードです。
# 名前 : Myoga Screw-bright (旧名:Myoga S. Tomonaka)
# Twitter : https://twitter.com/Myoga1012
window.onload = () ->
# 現在日を取得し、当月1日の曜日と末日を求めます。
now = new Date()
prePad = new Date( now.getFullYear(), now.getMonth(), 1 ).getDay()
lastDay = new Date( now.getFullYear(), now.getMonth() + 1, 0 ).getDate()
# カレンダーを出力します。
el = document.getElementById( 'content' )
for curDay in [( -prePad + 1 )..lastDay]
# 半角スペース1つ出力します。curDayが負の時はさらに2つ出力します。
el.innerHTML += "&nbsp;" + if curDay < 1 then "&nbsp;&nbsp;"
# curDayが正の時です。1桁なら半角スペースを1つ出力します。そして日付を出力します。
else ( if curDay < 10 then "&nbsp;" else "" ) + curDay.toString() +
# 土曜日を出力したら、改行タグを入れます。
if ( prePad + curDay ) % 7 is 0 then "<br/>" else ""
# Calendar.coffee
# Copyright (c) 2014 Myoga-TN.net All Rights Reserved.
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php
// Visual StudioでそのCoffeeScriptファイルをビルドした時に生成されるJavaScriptコードです。
(function() {
window.onload = function() {
var curDay, el, lastDay, now, prePad, _i, _ref, _results;
now = new Date();
prePad = new Date(now.getFullYear(), now.getMonth(), 1).getDay();
lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate();
el = document.getElementById('content');
_results = [];
for (curDay = _i = _ref = -prePad + 1; _ref <= lastDay ? _i <= lastDay : _i >= lastDay; curDay = _ref <= lastDay ? ++_i : --_i) {
_results.push(el.innerHTML += "&nbsp;" + (curDay < 1 ? "&nbsp;&nbsp;" : (curDay < 10 ? "&nbsp;" : "") + curDay.toString() + ((prePad + curDay) % 7 === 0 ? "<br/>" : "")));
}
return _results;
};
}).call(this);
//# sourceMappingURL=Calendar.js.map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment