Skip to content

Instantly share code, notes, and snippets.

@Nia-TN1012
Forked from Myoga1012/Calendar.coffee
Last active January 30, 2023 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nia-TN1012/f6a829c7ba9737d9ab689f2f660705fd to your computer and use it in GitHub Desktop.
Save Nia-TN1012/f6a829c7ba9737d9ab689f2f660705fd to your computer and use it in GitHub Desktop.
CoffeeScriptでカレンダーを出力するソースコードです。
# 名前 : Nia Tomonaka
# Twitter : https://twitter.com/nia_tn1012
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-2023 Nia T.N. Tech Lab. / Chronoir.net.
# 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
@Nia-TN1012
Copy link
Author

GitHubのアカウント統合のため、Myoga1012→Nia-TN1012に移行しました。

旧URL: https://gist.github.com/Myoga1012/38cacec36f4233137738

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment