# encoding: ascii
# api: powershell
# title: Get-CalendarWeek
# description: This function calculates the calendar week to a given date. It either takes a given date or retrieves the current date.
# version: 0.1
# type: function
# author: Holger Adam
# license: CC0
# function: Get-CalendarWeek
# x-poshcode-id: 1391
# x-derived-from-id: 1392
# x-archived: 2016-04-26T06:31:14
# x-published: 2010-10-13T00:49:00
#
# Update: Now using CultureInfo for global usage.
# Examples:
# Get-CalendarWeek
# Get-Date | Get-CalendarWeek
#
# Get-CalendarWeek by Holger Adam
# Simple function to retrieve the calendar week to a given or the current date.

function Get-CalendarWeek {
	param(
		$Date
	)
	
	# check date input
	if ($Date -eq $null)
	{
		$Date = Get-Date
	}

	# get current culture object
	$Culture = [System.Globalization.CultureInfo]::CurrentCulture
	
	# retrieve calendar week
	$Culture.Calendar.GetWeekOfYear($Date, $Culture.DateTimeFormat.CalendarWeekRule, $Culture.DateTimeFormat.FirstDayOfWeek)
}
