-
-
Save Nia-TN1012/54e11f35079a028d0321ad084030fb3a to your computer and use it in GitHub Desktop.
TypeScriptでカレンダーを出力するソースコードです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Visual StudioでそのTypeScriptファイルをビルドした時に生成されるJavaScriptコードです。 | |
window.onload = function () { | |
// 現在日を取得し、当月1日の曜日と末日を求めます。 | |
var now = new Date(); | |
var prePad = new Date(now.getFullYear(), now.getMonth(), 1).getDay(); | |
var lastDay = new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate(); | |
// カレンダーを出力します。 | |
var el = document.getElementById('content'); | |
for (var curDay = -prePad + 1; curDay <= lastDay; curDay++) { | |
// 半角スペース1つ出力します。curDayが負の時はさらに2つ出力します。 | |
el.innerHTML += " " + (curDay < 1 ? " " : (curDay < 10 ? " " : "") + curDay.toString() + ((prePad + curDay) % 7 == 0) ? "<br/>" : ""); | |
} | |
}; | |
//# sourceMappingURL=app.js.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 名前 : Nia Tomonaka | |
// Twitter : https://twitter.com/nia_tn1012 | |
window.onload = () => { | |
// 現在日を取得し、当月1日の曜日と末日を求めます。 | |
var now: Date = new Date(); | |
var prePad: number = new Date( now.getFullYear(), now.getMonth(), 1 ).getDay(); | |
var lastDay: number = new Date( now.getFullYear(), now.getMonth() + 1, 0 ).getDate(); | |
// カレンダーを出力します。 | |
var el = document.getElementById( 'content' ); | |
for ( var curDay: number = -prePad + 1; curDay <= lastDay; curDay++ ) { | |
// 半角スペース1つ出力します。curDayが負の時はさらに2つ出力します。 | |
el.innerHTML += " " + ( curDay < 1 ? " " : | |
// curDayが正の時です。1桁なら半角スペースを1つ出力します。そして日付を出力します。 | |
( curDay < 10 ? " " : "" ) + curDay.toString() + | |
// 土曜日を出力したら、改行タグを入れます。 | |
( ( ( prePad + curDay ) % 7 == 0 ) ? "<br/>" : "" ) ); | |
} | |
}; | |
// Calendar.ts | |
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GitHubのアカウント統合のため、Myoga1012→Nia-TN1012に移行しました。
旧URL: https://gist.github.com/Myoga1012/fa9712f81a00b03fd910
移行元のGistのコメント履歴