# 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: 1392
# x-archived: 2016-04-22T18:54:34
# x-published: 2010-10-13T07:54:00
#
# Update: Now using CultureInfo for global usage.
# Update: Move $null check to a default Date value
# 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 = (Get-Date)
)
# get current culture object
$Culture = [System.Globalization.CultureInfo]::CurrentCulture
# retrieve calendar week
$Culture.Calendar.GetWeekOfYear($Date, $Culture.DateTimeFormat.CalendarWeekRule, $Culture.DateTimeFormat.FirstDayOfWeek)
}