Skip to content

Instantly share code, notes, and snippets.

@stknohg
Last active August 29, 2015 14:07
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 stknohg/5d8f6c4c250a5545c696 to your computer and use it in GitHub Desktop.
Save stknohg/5d8f6c4c250a5545c696 to your computer and use it in GitHub Desktop.
プロ生ちゃん #カレンダープログラミング プチコンテスト用カレンダーPowerShell版
#
# プロ生ちゃん #カレンダープログラミング プチコンテスト用カレンダーPowerShell版
# 日曜始まりの当月のカレンダーを表示します。
# 土曜日は青色、日曜日は赤色で表示されます。
#
$Today = (Get-Date).Date; $Year = $Today.Year; $Month = $Today.Month;
$CharWidth = 2; $SpaceWidth = 1; $DefaultColor= 'White';
Write-Host ( "{0:yyyy/MM}" -F $Today).PadLeft(($CharWidth * 7 + $SpaceWidth * 6) / 2 + 4 ) -ForegroundColor:$DefaultColor;
Write-Host "".PadLeft(($CharWidth + $SpaceWidth) * (Get-Date -Year $Year -Month $Month -Day 1).DayOfWeek) -NoNewline;
1..[DateTime]::DaysInMonth($Year, $Month) | ForEach-Object {
$Params = @{ 'SpaceWidth' = $SpaceWidth; 'NoNewLine' = $true; 'ForeColor' = $DefaultColor; }
Switch ( (Get-Date -Year $Year -Month $Month -Day $_).DayOfWeek )
{
Saturday { $Params.SpaceWidth = 0; $Params.NoNewLine = $false; $Params.ForeColor = 'Blue'; }
Sunday { $Params.SpaceWidth = $SpaceWidth; $Params.NoNewLine = $true; $Params.ForeColor = 'Red'; }
Default { $Params.SpaceWidth = $SpaceWidth; $Params.NoNewLine = $true; $Params.ForeColor = $DefaultColor; }
}
Write-Host ("{0,$CharWidth}" -F $_ ).PadRight($CharWidth + $Params.SpaceWidth) -NoNewline:$Params.NoNewLine -ForegroundColor:$Params.ForeColor;
}
Write-Host -NoNewline:(!$Params.NoNewLine);
@stknohg
Copy link
Author

stknohg commented Oct 21, 2014

なんとなくパイプラインを使いたかったのでForEach-Objectを使う様に変更した。

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