Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Nia-TN1012
Forked from Myoga1012/Calendar.fs
Last active January 30, 2023 07:40
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/b58e951b626f9c9b3ac0515acfb651f3 to your computer and use it in GitHub Desktop.
Save Nia-TN1012/b58e951b626f9c9b3ac0515acfb651f3 to your computer and use it in GitHub Desktop.
【旧バージョン】F#でカレンダーを出力するソースコードです。
// 名前 : 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
// 旧コード
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
@Nia-TN1012
Copy link
Author

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

旧URL: https://gist.github.com/Myoga1012/575548d5c96366411f96

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

  • 2014/10/15:
    • 月末が土曜日だと、最後に1行空いてしまうので、条件文で回避させました。

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