Created
January 30, 2023 08:52
-
-
Save Nia-TN1012/fead524333a0009e1979c2186f37195f to your computer and use it in GitHub Desktop.
Ceylonでカレンダーを出力するソースコードです。
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 | |
import ceylon.time { Date, date, today } | |
"Run the module `calendar`." | |
shared void run() { | |
// 現在日を取得し、当月1日の曜日と月末日を求めます。 | |
Date now = today(); variable String wl = ""; // wlはカレンダー出力用文字列変数です。 | |
value prePad = date( now.year, now.month, 1 ).dayOfWeek.integer; // 日曜日0始まりです。 | |
value lastDay = date( now.year, now.month.integer + 1, 1 ).minusDays( 1 ).day; | |
// カレンダーを出力します。 | |
print( now.month.string + " " + now.year.string ); // 年月を出力します。 | |
for( curDay in ( -prePad + 1 )..lastDay ){ | |
// Ceylonのprintメソッドは自動的に改行してしまうので、 | |
// 週単位で文字列にまとめ、それを出力します。 | |
wl += ( curDay < 1 then " " else ( curDay < 10 then " " + curDay.string else curDay.string ) ) + " "; | |
if( ( curDay + prePad ) % 7 == 0 || curDay == lastDay ){ print( wl ); wl = ""; } | |
} | |
} | |
/* | |
※備考 | |
Ceylonでは、Date.monthの値(月)とDate.dayOfWeekの値(曜日)が | |
いわゆる列挙体のようなデータ型です。 | |
それらのstringプロパティの値は月名の英語(januaryなど)や曜日名の英語(sundayなど) | |
となります。数値として扱うときはintegerプロパティを使用します。 | |
*/ | |
// Calender.ceylon | |
//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/f2968e4c695bb7fcc56e