Skip to content

Instantly share code, notes, and snippets.

@kureikei
Created October 23, 2014 12:53
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 kureikei/65f78fdf175631af3410 to your computer and use it in GitHub Desktop.
Save kureikei/65f78fdf175631af3410 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment