Last active
January 30, 2023 07:40
-
-
Save Nia-TN1012/b58e951b626f9c9b3ac0515acfb651f3 to your computer and use it in GitHub Desktop.
【旧バージョン】F#でカレンダーを出力するソースコードです。
This file contains hidden or 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 | |
open System; | |
[<EntryPoint>] | |
let main argv = | |
// 現在の日付を取得し、当月1日の曜日と末日を求めます。 | |
let now = DateTime.Today | |
let prePad = int( DateTime( now.Year, now.Month, 1 ).DayOfWeek ) | |
let lastDay = DateTime.DaysInMonth( now.Year, now.Month ) | |
// カレンダーを出力します。 | |
for curDay in [( -prePad + 1 )..lastDay] do | |
// 範囲を[( - 1日の曜日 + 1 )..末日]にし、要素が負の時に空白を出力します。 | |
// こうすることで1日の曜日に合わせてオフセットすることができます。 | |
if curDay > 0 then printf "%3d" curDay else printf " " | |
if ( curDay + prePad ) % 7 = 0 || curDay = lastDay then printfn "" | |
done | |
0 | |
// Calender.fs | |
// 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 |
This file contains hidden or 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
// 旧コード | |
open System; | |
[<EntryPoint>] | |
let main argv = | |
let now = DateTime.Today | |
let firstWeek = int( DateTime( now.Year, now.Month, 1 ).DayOfWeek ) | |
let lastDay = DateTime.DaysInMonth( now.Year, now.Month ) | |
for i = 1 to firstWeek do printf " " done | |
for day in [1..lastDay] do | |
printf "%3d" day | |
if ( day + firstWeek ) % 7 = 0 then printfn "" | |
else if ( day = lastDay ) then printfn "" | |
done | |
0 |
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/575548d5c96366411f96
移行元のGistのコメント履歴