Skip to content

Instantly share code, notes, and snippets.

@Nia-TN1012
Forked from Myoga1012/Calendar.js
Created January 30, 2023 08:16
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/54e11f35079a028d0321ad084030fb3a to your computer and use it in GitHub Desktop.
Save Nia-TN1012/54e11f35079a028d0321ad084030fb3a to your computer and use it in GitHub Desktop.
TypeScriptでカレンダーを出力するソースコードです。
// 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 += "&nbsp;" + (curDay < 1 ? "&nbsp;&nbsp;" : (curDay < 10 ? "&nbsp;" : "") + curDay.toString() + ((prePad + curDay) % 7 == 0) ? "<br/>" : "");
}
};
//# sourceMappingURL=app.js.map
// 名前 : 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 += "&nbsp;" + ( curDay < 1 ? "&nbsp;&nbsp;" :
// curDayが正の時です。1桁なら半角スペースを1つ出力します。そして日付を出力します。
( curDay < 10 ? "&nbsp;" : "" ) + 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
@Nia-TN1012
Copy link
Author

Nia-TN1012 commented Jan 30, 2023

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

旧URL: https://gist.github.com/Myoga1012/fa9712f81a00b03fd910

移行元のGistのコメント履歴

  • 2014/10/18:
    • HTMLではcontentのIDを持つタグのフォントは等幅フォントにしておきます。

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