diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..68323fa --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,62 @@ +name: build module + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build-module: + name: Run build and upload artifacts + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-tags: true + fetch-depth: 0 + + - name: Install Modules + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module ModuleBuilder,PSScriptAnalyzer + Install-Module Pester -MinimumVersion 5.5.0 + + - name: Run build + shell: pwsh + run: | + $Version = git describe --tags --abbrev=0 + Write-Host "Version : $Version" + .\build.ps1 -Version $Version + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: my-build + path: Build + + test-module: + needs: build-module + name: Test Module + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v3 + with: + name: my-build + path: Build + + - name: Install Modules + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module Pester -MinimumVersion 5.5.0 + + - name: Test build + shell: pwsh + run: .\test-build.ps1 + \ No newline at end of file diff --git a/.gitignore b/.gitignore index e616ae2..cb7ee3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Publish/APIKey.json -Publish/PSDates/ \ No newline at end of file +Publish/PSDates/ +Build/ \ No newline at end of file diff --git a/Public/ConvertFrom-WmiDateTime.ps1 b/Public/ConvertFrom-WmiDateTime.ps1 deleted file mode 100644 index 877e0eb..0000000 --- a/Public/ConvertFrom-WmiDateTime.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -Function ConvertFrom-WmiDateTime { - <# -.SYNOPSIS - Converts a Wmi Time value to a datetime value - -.DESCRIPTION - This function will return the datetime based on a WMI datetime string. - -.PARAMETER WmiTime - The WmiTime value to return the datetime for - -.EXAMPLE - ConvertFrom-WmiDateTime -WmiTime '20190912173652.000000-300' - Gets datetime for the Wmi time 20190912173652.000000-300 - -.OUTPUTS - The datetime value based on the wmi time -#> - [CmdletBinding()] - [OutputType([datetime])] - param( - [Parameter(Mandatory = $true)] - [string]$WmiTime - ) - - [Management.ManagementDateTimeConverter]::ToDateTime($WmiTime) -} \ No newline at end of file diff --git a/README.md b/README.md index c46c468..2ecba0b 100644 --- a/README.md +++ b/README.md @@ -1,327 +1,26 @@ -# PSDates - -PSDates provides you all the tools you need when working with dates and times in PowerShell. It contains function to help you find specific date formats, get certain dates based on other dates (first/last day of the month or year, patch Tuesday, etc). I also has functions for working with timezones, unix time, WMI time, crontabs. - -# Installation - -```powershell -Install-Module PSDates -``` - -# Examples - -* [Get-DateExtended](#Get-DateExtended) -* [Get-DateFormats](#Get-DateFormats) -* [Get-PatchTuesday](#Get-PatchTuesday) -* [Test-CrontabSchedule](#Test-CrontabSchedule) -* [Get-CronNextOccurrence](#Get-CronNextOccurrence) -* [Find-TimeZone](#Find-TimeZone) -* [Convert-TimeZone](#Convert-TimeZone) -* [ConvertFrom-UnixTime](#ConvertFrom-UnixTime) -* [ConvertTo-UnixTime](#ConvertTo-UnixTime) -* [ConvertFrom-WmiDateTime](#ConvertFrom-WmiDateTime) -* [ConvertTo-WmiDateTime](#ConvertTo-WmiDateTime) - -## Get-DateExtended -Gets common extended date values that are not included by default with the Get-Date cmdlet. It expects all the same parameters as the standard Get-Date cmdlet. - -### Example 1: Gets extended date and time information based on the current time -```powershell -PS:> Get-DateExtended - -Date WeekOfYear DayOfWeek StartOfWeek EndOfWeek StartOfMonth EndOfMonth ----- ---------- --------- ----------- --------- ------------ ---------- -7/15/2020 7:30:36 AM 29 Wednesday 7/12/2020 7/18/2020 7/1/2020 7/31/2020 -``` - -### Example 2: Gets extended date and time information for a specific date -```powershell -PS:> Get-DateExtended -Date "11/17/2017" - -DateTime : 11/17/2017 12:00:00 AM -FirstDayOfYear : 1/1/2017 12:00:00 AM -LastDayOfYear : 12/31/2017 12:00:00 AM -StartOfWeek : 11/12/2017 12:00:00 AM -EndOfWeek : 11/18/2017 11:59:59 PM -StartOfMonth : 11/1/2017 12:00:00 AM -EndOfMonth : 11/30/2017 11:59:59 PM -WeekOfYear : 46 -TimeZone : (UTC-06:00) Central Time (US & Canada) -Quater : 4 -Date : 11/17/2017 12:00:00 AM -Day : 17 -DayOfWeek : Friday -DayOfYear : 321 -Hour : 0 -Kind : Unspecified -Millisecond : 0 -Minute : 0 -Month : 11 -Second : 0 -Ticks : 636464736000000000 -TimeOfDay : 00:00:00 -Year : 2017 -``` -[top](#examples) -## Get-DateFormats -Get-DateFormats returns the date and time values into multiple different common formats. All dates are based on the date passed. If no date is passed in the current date and time are used. - -### Example 1: Gets formatted date and time information based on the current time -```powershell -PS:> Get-DateFormats - -24HourTime : 07:36 -DateTime : 7/15/2020 7:36:41 AM -Day : 15 -DayAbrv : Wed -DayName : Wednesday -DayOfWeek : 3 -FileTime : 132392902016053261 -FullDateShortTime : Wednesday, July 15, 2020 7:36 AM -FullDateTime : Wednesday, July 15, 2020 7:36:41 AM -GeneralDateShortTime : 7/15/2020 7:36 AM -GeneralDateTime : 7/15/2020 7:36:41 AM -IsDaylightSavingTime : True -IsLeapYear : True -ISO8601 : 2020-07-15T07:36:41.605-06:00 -ISO8601UTC : 2020-07-15T12:36:41.605Z -LongDate : Wednesday, July 15, 2020 -LongTime : 7:36:41 AM -Month : 7 -MonthAbrv : Jul -MonthDay : July 15 -MonthName : July -Quater : 3 -RFC1123 : Wed, 15 Jul 2020 07:36:41 GMT -RFC1123UTC : Wed, 15 Jul 2020 12:36:41 GMT -RoundTrip : 2020-07-15T07:36:41.6053261-05:00 -ShortDate : 7/15/2020 -ShortTime : 7:36 AM -SortableDateTime : 2020-07-15T07:36:41 -SQL : 2020-07-15 07:36:41.605 -UniversalFullDateTime : Wednesday, July 15, 2020 12:36:41 PM -UniversalSortableDateTime : 2020-07-15 07:36:41Z -UnixEpochTime : 1594816602 -WimDatetime : 20200715073641.605326-300 -Year : 2020 -YearMonth : July 2020 -YearQuater : 202003 -``` -[top](#examples) -## Get-PatchTuesday -Get-PatchTuesday allows you to pass a date, or a month/year combination to find the second Tuesday (aka Patch Tuesday) of any month. - -### Example 1: Returns the second Tuesday for the current month -```powershell -PS:> Get-PatchTuesday - -Tuesday, July 14, 2020 12:00:00 AM -``` - -### Example 2: Returns the second Tuesday for November 2021 -```powershell -PS:> Get-PatchTuesday -Date "11/17/2021" - -Tuesday, November 9, 2021 12:00:00 AM -``` - -### Example 3: Returns the second Tuesday for June 2020 -```powershell -PS:> Get-PatchTuesday -Month 6 -Year 2020 - -Tuesday, June 9, 2020 12:00:00 AM -``` - -### Example 4: Returns the second Tuesday for April of the current year -```powershell -PS:> Get-PatchTuesday -Month 4 - -Tuesday, April 14, 2020 12:00:00 AM -``` -[top](#examples) -## Test-CrontabSchedule -This function attempts to parse a crontab string to ensure it is valid. - -### Example 1 : Valid schedule that returns: -```powershell -PS:> Test-CrontabSchedule -crontab '0 17 * * *' - -Schedule Valid --------- ----- -0 17 * * * True -``` - -### Example 2 : Invalid schedule that returns: -```powershell -PS:> Test-CrontabSchedule -crontab '0 17 * 13 *' - -Schedule Valid ErrorMsg --------- ----- -------- -0 17 * 13 * False 13 is higher than the maximum allowable value for the [Month] field. Value must be between 1 and 12 (all inclusive). -``` -[top](#examples) -## Get-CronNextOccurrence -This function will either return the next occurrence, or if an end date is supplied, it will return -all the occurrences between the start and end date. - -### Example 1 : Will return the next occurrence of the crontab from the current time -```powershell -PS:> Get-CronNextOccurrence -Crontab '0 17 * * *' - -Wednesday, July 15, 2020 5:00:00 PM -``` - -### Example 2 : Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date -```powershell -PS:> $Date = Get-Date '12/14/2032' -PS:> Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date - -Tuesday, December 14, 2032 5:00:00 PM -``` - -### Example 3 : Will return the all occurrences of the crontab between the two times -```powershell -PS:> $Date = Get-Date '12/14/2020' -PS:> Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date -EndTime $Date.AddDays(3) - -Monday, December 14, 2020 5:00:00 PM -Tuesday, December 15, 2020 5:00:00 PM -Wednesday, December 16, 2020 5:00:00 PM -``` -[top](#examples) -## Find-TimeZone -This function will return the information for the system time zones. You can search by name and/or hour offsets. -You can also return the local time zone. - -### Example 1 : Return the time zone of the local system -```powershell -PS:> Find-TimeZone -local - -Id : Central Standard Time -DisplayName : (UTC-06:00) Central Time (US & Canada) -StandardName : Central Standard Time -DaylightName : Central Daylight Time -BaseUtcOffset : -06:00:00 -SupportsDaylightSavingTime : True -``` - -### Example 2 : Search for time zones with 'GMT' in the name -```powershell -PS:> Find-TimeZone -Name "GMT" - -Id : GMT Standard Time -DisplayName : (UTC+00:00) Dublin, Edinburgh, Lisbon, London -StandardName : GMT Standard Time -DaylightName : GMT Daylight Time -BaseUtcOffset : 00:00:00 -SupportsDaylightSavingTime : True -``` - -### Example 3 : Search for time zones with 'Central' in the name and have a UTC offset of -6 hours -```powershell -PS:> Find-TimeZone -Name "central" -Offset -6 - -Id : Central America Standard Time -DisplayName : (UTC-06:00) Central America -StandardName : Central America Standard Time -DaylightName : Central America Daylight Time -BaseUtcOffset : -06:00:00 -SupportsDaylightSavingTime : False - -Id : Central Standard Time -DisplayName : (UTC-06:00) Central Time (US & Canada) -StandardName : Central Standard Time -DaylightName : Central Daylight Time -BaseUtcOffset : -06:00:00 -SupportsDaylightSavingTime : True - -Id : Central Standard Time (Mexico) -DisplayName : (UTC-06:00) Guadalajara, Mexico City, Monterrey -StandardName : Central Standard Time (Mexico) -DaylightName : Central Daylight Time (Mexico) -BaseUtcOffset : -06:00:00 -SupportsDaylightSavingTime : True - -Id : Canada Central Standard Time -DisplayName : (UTC-06:00) Saskatchewan -StandardName : Canada Central Standard Time -DaylightName : Canada Central Daylight Time -BaseUtcOffset : -06:00:00 -SupportsDaylightSavingTime : False -``` -[top](#examples) -## Convert-TimeZone -This function will allows you to pass a date to convert from one time zone to another. -If no date is specified the local time is used. If no FromTimeZone is passed then the -local time zone is used. - -If you don't know the time zone ID you can use the [Find-TimeZone](Find-TimeZone) cmdlet. - -### Example 1 : FromDateTime : 11/11/2017 3:54:12 PM -```powershell -PS:> Convert-TimeZone -ToTimeZone "GMT Standard Time" - -FromDateTime : 7/15/2020 7:57:15 AM -FromTimeZone : Central Standard Time -ToDateTime : 7/15/2020 1:57:15 PM -ToTimeZone : GMT Standard Time -Offset : 06:00:00 -``` - -### Example 2 : FromDateTime : 11/17/2017 12:34:00 AM -```powershell -PS:> Convert-TimeZone -date '11/17/2017 12:34 AM' -FromTimeZone "China Standard Time" -ToTimeZone "US Mountain Standard Time" - -FromDateTime : 11/17/2017 12:34:00 AM -FromTimeZone : China Standard Time -ToDateTime : 11/16/2017 9:34:00 AM -ToTimeZone : US Mountain Standard Time -Offset : -15:00:00 -``` -[top](#examples) -## ConvertFrom-UnixTime -This function will return the datetime based on the unix epoch time. - -### Example 1 : Gets datetime for the Unix time 1509512400 -```powershell -PS:> ConvertFrom-UnixTime -UnixTime 1509512400 - -Wednesday, November 1, 2017 12:00:00 AM -``` -[top](#examples) -## ConvertTo-UnixTime -This function will return the unix time based on the unix epoch time. If no date is passed in the current date and time is used. - -### Example 1 : Gets unix time for the current time -```powershell -PS:> ConvertTo-UnixTime - -1594817994 -``` - -### Example 2 : Gets unix time for a specific date -```powershell -PS:> ConvertTo-UnixTime -date "11/17/2017" - -1510898400 -``` -[top](#examples) -## ConvertFrom-WmiDateTime -This function will return the datetime based on a WMI datetime string. - -### Example 1 : Gets datetime for the Wmi time 20190912173652.000000-300 -```powershell -PS:> ConvertFrom-WmiDateTime -WmiTime '20190912173652.000000-300' - -Thursday, September 12, 2019 5:36:52 PM -``` -[top](#examples) -## ConvertTo-WmiDateTime -This function will return the WMI datetime string based on a datetime passed. - -### Example 1 : Return the WMI datetime string for the datetime of "06/25/2019 16:17" -```powershell -PS:> ConvertTo-WmiDateTime -Date '06/25/2019 16:17' - -20190625161700.000000-300 -``` \ No newline at end of file +# PSDates + +PSDates provides you all the tools you need when working with dates and times in PowerShell. It contains function to help you find specific date formats, get certain dates based on other dates (first/last day of the month or year, patch Tuesday, etc). I also has functions for working with timezones, unix time, WMI time, crontabs. + +# Installation + +```powershell +Install-Module PSDates +``` + +# Commands + +* [Convert-TimeZone](docs/Convert-TimeZone.md) +* [ConvertFrom-UnixTime](docs/ConvertFrom-UnixTime.md) +* [ConvertFrom-WmiDateTime](docs/ConvertFrom-WmiDateTime.md) +* [ConvertTo-UnixTime](docs/ConvertTo-UnixTime.md) +* [ConvertTo-WmiDateTime](docs/ConvertTo-WmiDateTime.md) +* [Find-TimeZone](docs/Find-TimeZone.md) +* [Get-CronNextOccurrence](docs/Get-CronNextOccurrence.md) +* [Get-DateExtended](docs/Get-DateExtended.md) +* [Get-DateFormat](docs/Get-DateFormat.md) +* [Get-Easter](docs/Get-Easter.md) +* [Get-PatchTuesday](docs/Get-PatchTuesday.md) +* [New-Duration](docs/New-Duration.md) +* [Test-CrontabSchedule](docs/Test-CrontabSchedule.md) + diff --git a/Resources/DateTimeExtended.ps1 b/Source/Classes/DateTimeExtended.ps1 similarity index 100% rename from Resources/DateTimeExtended.ps1 rename to Source/Classes/DateTimeExtended.ps1 diff --git a/Resources/DateTimeFormats.ps1 b/Source/Classes/DateTimeFormats.ps1 similarity index 97% rename from Resources/DateTimeFormats.ps1 rename to Source/Classes/DateTimeFormats.ps1 index 791e208..4e9dd29 100644 --- a/Resources/DateTimeFormats.ps1 +++ b/Source/Classes/DateTimeFormats.ps1 @@ -15,6 +15,7 @@ class DateTimeFormats { [string] $ISO8601 [string] $ISO8601UTC [string] $LongDate + [string] $LongDateNoDay [string] $LongTime [int32] $Month [string] $MonthAbrv diff --git a/Source/Classes/TimeZoneConversion.ps1 b/Source/Classes/TimeZoneConversion.ps1 new file mode 100644 index 0000000..5383d6a --- /dev/null +++ b/Source/Classes/TimeZoneConversion.ps1 @@ -0,0 +1,21 @@ +class TimeZoneConversion { + [DateTime] $FromDateTime + [String] $FromTimeZone + [DateTime] $ToDateTime + [String] $ToTimeZone + [TimeSpan] $Offset + + TimeZoneConversion ($ToTimeZone, $Date, $FromTimeZone) { + $DateTime = [DateTime]::SpecifyKind($Date, [DateTimeKind]::Unspecified) + $from = [System.TimeZoneInfo]::FindSystemTimeZoneById($FromTimeZone) + $to = [System.TimeZoneInfo]::FindSystemTimeZoneById($ToTimeZone) + $utc = [System.TimeZoneInfo]::ConvertTimeToUtc($DateTime, $from) + $newTime = [System.TimeZoneInfo]::ConvertTime($utc, $to) + + $this.FromDateTime = $Date + $this.FromTimeZone = $FromTimeZone + $this.ToDateTime = $newTime + $this.ToTimeZone = $ToTimeZone + $this.Offset = (New-TimeSpan -Start $date -End $newTime) + } +} \ No newline at end of file diff --git a/PSDates.psd1 b/Source/PSDates.psd1 similarity index 94% rename from PSDates.psd1 rename to Source/PSDates.psd1 index d249d40..542d936 100644 --- a/PSDates.psd1 +++ b/Source/PSDates.psd1 @@ -56,11 +56,10 @@ ProcessorArchitecture = 'Amd64' # RequiredModules = @() # Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() +RequiredAssemblies = @('.\Resources\NCrontab.dll') # Script files (.ps1) that are run in the caller's environment prior to importing this module. -ScriptsToProcess = '.\Resources\DateTimeFormats.ps1', - '.\Resources\DateTimeExtended.ps1' +# ScriptsToProcess = '.\Classes\DateTimeFormats.ps1', '.\Classes\DateTimeExtended.ps1' # Type files (.ps1xml) to be loaded when importing this module # TypesToProcess = @() diff --git a/PSDates.psm1 b/Source/PSDates.psm1 similarity index 100% rename from PSDates.psm1 rename to Source/PSDates.psm1 diff --git a/Public/Convert-TimeZone.ps1 b/Source/Public/Convert-TimeZone.ps1 similarity index 68% rename from Public/Convert-TimeZone.ps1 rename to Source/Public/Convert-TimeZone.ps1 index 28184ce..5901220 100644 --- a/Public/Convert-TimeZone.ps1 +++ b/Source/Public/Convert-TimeZone.ps1 @@ -1,66 +1,52 @@ -Function Convert-TimeZone { - <# -.SYNOPSIS - Convert a datetime value from one time zone to another - -.DESCRIPTION - This function will allows you to pass a date to convert from one time zone to another. - If no date is specified the local time is used. If no FromTimeZone is passed then the - local time zone is used. - If you don't know the time zone ID you can use the Find-TimeZone cmdlet. - -.PARAMETER ToTimeZone - The time zone ID of the time zone you want to convert the date to - -.PARAMETER date - The date to convert. If not specified the current time will be used - -.PARAMETER FromTimeZone - The time zone ID of the time zone you want to convert the date from. If not specified the local time zone will be used - -.EXAMPLE - Convert-TimeZone -ToTimeZone "GMT Standard Time" - - Convert the local system time to GMT Standard Time - -.EXAMPLE - Convert-TimeZone -date '11/17/2017 12:34 AM' -FromTimeZone "China Standard Time" -ToTimeZone "US Mountain Standard Time" - - Converts the date and time 11/17/2017 12:34 AM from 'China Standard Time' to 'US Mountain Standard Time' - -.OUTPUTS - A PSObject object containing the time zone conversion data -#> - param( - [parameter(Mandatory = $True)] - [Validatescript( { try { $id = $_; [System.TimeZoneInfo]::FindSystemTimeZoneById($_) } - catch { throw("'$Id' is not a valid time zone Id. Use the Find-TimeZone cmdlet to find the valid time zone Id.") } })] - [string]$ToTimeZone, - - [Parameter(Mandatory = $false)] - [datetime]$date = $(Get-Date), - - [parameter(Mandatory = $false)] - [Validatescript( { try { $id = $_; [System.TimeZoneInfo]::FindSystemTimeZoneById($_) } - catch { throw("'$Id' is not a valid time zone Id. Use the Find-TimeZone cmdlet to find the valid time zone Id.") } })] - [string]$FromTimeZone = [System.TimeZoneInfo]::Local.Id.ToString() - ) - - $DateTime = [DateTime]::SpecifyKind($date, [DateTimeKind]::Unspecified) - $from = [System.TimeZoneInfo]::FindSystemTimeZoneById($FromTimeZone) - $to = [System.TimeZoneInfo]::FindSystemTimeZoneById($ToTimeZone) - $utc = [System.TimeZoneInfo]::ConvertTimeToUtc($DateTime, $from) - $newTime = [System.TimeZoneInfo]::ConvertTime($utc, $to) - - [PSCustomObject]@{ - - PsTypeName = 'TimeZoneConversion' - - FromDateTime = $Date - FromTimeZone = $FromTimeZone - ToDateTime = $newTime - ToTimeZone = $ToTimeZone - - Offset = (New-TimeSpan -Start $date -End $newTime) - } -} \ No newline at end of file +Function Convert-TimeZone { + <# +.SYNOPSIS + Convert a datetime value from one time zone to another + +.DESCRIPTION + This function will allows you to pass a date to convert from one time zone to another. + If no date is specified the local time is used. If no FromTimeZone is passed then the + local time zone is used. + If you don't know the time zone ID you can use the Find-TimeZone cmdlet. + +.PARAMETER ToTimeZone + The time zone ID of the time zone you want to convert the date to + +.PARAMETER date + The date to convert. If not specified the current time will be used + +.PARAMETER FromTimeZone + The time zone ID of the time zone you want to convert the date from. If not specified the local time zone will be used + +.EXAMPLE + Convert-TimeZone -ToTimeZone "GMT Standard Time" + + Convert the local system time to GMT Standard Time + +.EXAMPLE + Convert-TimeZone -date '11/17/2017 12:34 AM' -FromTimeZone "China Standard Time" -ToTimeZone "US Mountain Standard Time" + + Converts the date and time 11/17/2017 12:34 AM from 'China Standard Time' to 'US Mountain Standard Time' + +.OUTPUTS + A PSObject object containing the time zone conversion data +#> + [CmdletBinding()] + [OutputType([TimeZoneConversion])] + param( + [parameter(Mandatory = $True)] + [Validatescript( { try { $id = $_; [System.TimeZoneInfo]::FindSystemTimeZoneById($_) } + catch { throw("'$Id' is not a valid time zone Id. Use the Find-TimeZone cmdlet to find the valid time zone Id.") } })] + [string]$ToTimeZone, + + [Parameter(Mandatory = $false)] + [datetime]$Date = $(Get-Date), + + [parameter(Mandatory = $false)] + [Validatescript( { try { $id = $_; [System.TimeZoneInfo]::FindSystemTimeZoneById($_) } + catch { throw("'$Id' is not a valid time zone Id. Use the Find-TimeZone cmdlet to find the valid time zone Id.") } })] + [string]$FromTimeZone = [System.TimeZoneInfo]::Local.Id.ToString() + ) + + [TimeZoneConversion]::new($ToTimeZone, $Date, $FromTimeZone) +} diff --git a/Public/ConvertFrom-UnixTime.ps1 b/Source/Public/ConvertFrom-UnixTime.ps1 similarity index 82% rename from Public/ConvertFrom-UnixTime.ps1 rename to Source/Public/ConvertFrom-UnixTime.ps1 index 316f0b1..6d3d199 100644 --- a/Public/ConvertFrom-UnixTime.ps1 +++ b/Source/Public/ConvertFrom-UnixTime.ps1 @@ -1,28 +1,28 @@ -Function ConvertFrom-UnixTime { - <# -.SYNOPSIS - Converts a Unix Time value to a datetime value - -.DESCRIPTION - This function will return the datetime based on the unix epoch time. - -.PARAMETER UnixTime - The UnixTime value to return the datetime for - -.EXAMPLE - ConvertFrom-UnixTime -UnixTime 1509512400 - Gets datetime for the Unix time 1509512400 - -.OUTPUTS - The datetime value based on the unix time - -#> - [CmdletBinding()] - [OutputType([datetime])] - param( - [Parameter(Mandatory = $true)] - [double]$UnixTime - ) - - [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($UnixTime)) -} \ No newline at end of file +Function ConvertFrom-UnixTime { + <# +.SYNOPSIS + Converts a Unix Time value to a datetime value + +.DESCRIPTION + This function will return the datetime based on the unix epoch time. + +.PARAMETER UnixTime + The UnixTime value to return the datetime for + +.EXAMPLE + ConvertFrom-UnixTime -UnixTime 1509512400 + Gets datetime for the Unix time 1509512400 + +.OUTPUTS + The datetime value based on the unix time + +#> + [CmdletBinding()] + [OutputType([datetime])] + param( + [Parameter(Mandatory = $true)] + [double]$UnixTime + ) + + (Get-Date '1970-01-01T00:00:00.000Z').ToUniversalTime().AddSeconds($UnixTime) +} diff --git a/Source/Public/ConvertFrom-WmiDateTime.ps1 b/Source/Public/ConvertFrom-WmiDateTime.ps1 new file mode 100644 index 0000000..1696c04 --- /dev/null +++ b/Source/Public/ConvertFrom-WmiDateTime.ps1 @@ -0,0 +1,54 @@ +Function ConvertFrom-WmiDateTime { + <# +.SYNOPSIS + Converts a Wmi Time value to a datetime value + +.DESCRIPTION + This function will return the datetime based on a WMI datetime string. + +.PARAMETER WmiTime + The WmiTime value to return the datetime for + +.EXAMPLE + ConvertFrom-WmiDateTime -WmiTime '20190912173652.000000-300' + Gets datetime for the Wmi time 20190912173652.000000-300 + +.OUTPUTS + The datetime value based on the wmi time +#> + [CmdletBinding()] + [OutputType([datetime])] + param( + [Parameter(Mandatory = $true)] + [string]$WmiTime + ) + + # Extract individual components from the WMI DateTime string + $year = [int]$WmiTime.Substring(0, 4) + $month = [int]$WmiTime.Substring(4, 2) + $day = [int]$WmiTime.Substring(6, 2) + $hour = [int]$WmiTime.Substring(8, 2) + $minute = [int]$WmiTime.Substring(10, 2) + $second = [int]$WmiTime.Substring(12, 2) + $millisecond = [int]$WmiTime.Substring(15, 6) + + # Create a DateTime object + $dateTime = [datetime]::SpecifyKind(([datetime]"$year-$month-$day $($hour):$($minute):$second.$millisecond"), 'Utc') + + # Create a TimeSpan object for the UTC offset + if ($WmiTime -match '\+') { + $offsetMinutes = [int]$WmiTime.Split('+')[-1] + $offset = New-TimeSpan -Minutes $offsetMinutes + # Adjust for the UTC offset + $dateTime = $dateTime.Add(-$offset) + } + elseif ($WmiTime -match '\-') { + $offsetMinutes = [int]$WmiTime.Split('-')[-1] + $offset = New-TimeSpan -Minutes $offsetMinutes + # Adjust for the UTC offset + $dateTime = $dateTime.Add($offset) + } + + # Convert to local time and output + $dateTime.ToLocalTime() +} diff --git a/Public/ConvertTo-UnixTime.ps1 b/Source/Public/ConvertTo-UnixTime.ps1 similarity index 87% rename from Public/ConvertTo-UnixTime.ps1 rename to Source/Public/ConvertTo-UnixTime.ps1 index 0e6d924..529aa87 100644 --- a/Public/ConvertTo-UnixTime.ps1 +++ b/Source/Public/ConvertTo-UnixTime.ps1 @@ -1,26 +1,26 @@ -Function ConvertTo-UnixTime { - <# -.SYNOPSIS - Converts a datetime value to Unix Time -.DESCRIPTION - This function will return the unix time based on the unix epoch time. If no date is passed in the current date and time is used. -.PARAMETER Date - The datetime value to return the unix time for -.EXAMPLE - ConvertTo-UnixTime - Gets unix time for the current time -.EXAMPLE - ConvertTo-UnixTime -date "11/17/2017" - Gets unix time for a specific date -.OUTPUTS - The int32 value of the unix time -#> - [CmdletBinding()] - [OutputType([int32])] - param( - [Parameter(Mandatory = $false)] - [datetime]$date = $(Get-Date) - ) - - [int][double]::Parse((Get-Date ($date).touniversaltime() -UFormat %s)) -} \ No newline at end of file +Function ConvertTo-UnixTime { + <# +.SYNOPSIS + Converts a datetime value to Unix Time +.DESCRIPTION + This function will return the unix time based on the unix epoch time. If no date is passed in the current date and time is used. +.PARAMETER Date + The datetime value to return the unix time for +.EXAMPLE + ConvertTo-UnixTime + Gets unix time for the current time +.EXAMPLE + ConvertTo-UnixTime -date "11/17/2017" + Gets unix time for a specific date +.OUTPUTS + The int32 value of the unix time +#> + [CmdletBinding()] + [OutputType([int32])] + param( + [Parameter(Mandatory = $false)] + [datetime]$date = $(Get-Date) + ) + + [int][double]::Parse((Get-Date ($date).touniversaltime() -UFormat %s)) +} diff --git a/Public/ConvertTo-WmiDateTime.ps1 b/Source/Public/ConvertTo-WmiDateTime.ps1 similarity index 66% rename from Public/ConvertTo-WmiDateTime.ps1 rename to Source/Public/ConvertTo-WmiDateTime.ps1 index f3006fb..c6e17f7 100644 --- a/Public/ConvertTo-WmiDateTime.ps1 +++ b/Source/Public/ConvertTo-WmiDateTime.ps1 @@ -1,28 +1,36 @@ -Function ConvertTo-WmiDateTime { - <# -.SYNOPSIS - Converts a datetime value to a Wmi datetime string - -.DESCRIPTION - This function will return the WMI datetime string based on a datetime passed. - -.PARAMETER WmiTime - The WmiTime value to return the datetime for - -.EXAMPLE - ConvertTo-WmiDateTime -Date '06/25/2019 16:17' - - Return the WMI datetime string for the datetime of "06/25/2019 16:17" - -.OUTPUTS - The string value based on the datetime -#> - [CmdletBinding()] - [OutputType([string])] - param( - [Parameter(Mandatory = $false)] - [datetime]$Date = (Get-Date) - ) - - [Management.ManagementDateTimeConverter]::ToDmtfDateTime($Date) -} \ No newline at end of file +Function ConvertTo-WmiDateTime { + <# +.SYNOPSIS + Converts a datetime value to a Wmi datetime string + +.DESCRIPTION + This function will return the WMI datetime string based on a datetime passed. + +.PARAMETER WmiTime + The WmiTime value to return the datetime for + +.EXAMPLE + ConvertTo-WmiDateTime -Date '06/25/2019 16:17' + + Return the WMI datetime string for the datetime of "06/25/2019 16:17" + +.OUTPUTS + The string value based on the datetime +#> + [CmdletBinding()] + [OutputType([string])] + param( + [Parameter(Mandatory = $false)] + [datetime]$Date = (Get-Date) + ) + + $wmiString = $Date.ToString("yyyyMMddHHmmss.ffffff") + if($Date.Kind -eq 'Utc'){ + $wmiString += '+000' + } + else{ + $offset = ([System.TimeZoneInfo]::Local).BaseUtcOffset.TotalMinutes + $wmiString += "$($offset)" + } + $wmiString +} diff --git a/Public/Find-TimeZone.ps1 b/Source/Public/Find-TimeZone.ps1 similarity index 91% rename from Public/Find-TimeZone.ps1 rename to Source/Public/Find-TimeZone.ps1 index cd6b97e..c6491cc 100644 --- a/Public/Find-TimeZone.ps1 +++ b/Source/Public/Find-TimeZone.ps1 @@ -1,67 +1,67 @@ -Function Find-TimeZone { - <# -.SYNOPSIS - Returns Time Zone information - -.DESCRIPTION - This function will return the information for the system time zones. You can search by name and/or hour offsets. - You can also return the local time zone. - -.PARAMETER Name - All or part of the time zone name. Will be used to perform a wildcard search on the time zones - -.PARAMETER Offset - The number of hours the time zone is offset from UTC - -.PARAMETER local - Use to return the time zone of the current system - -.EXAMPLE - Find-TimeZone -local - Return the time zone of the local system - -.EXAMPLE - Find-TimeZone -Name "GMT" - Search for time zones with 'GMT' in the name - -.EXAMPLE - Find-TimeZone -Name "central" -Offset -6 - Search for time zones with 'Central' in the name and have a UTC offset of -6 hours - -.OUTPUTS - The TimeZoneInfo value or values found -#> - [CmdletBinding()] - [OutputType([System.TimeZoneInfo])] - param( - [parameter(Mandatory = $false)][string]$Name, - [parameter(Mandatory = $false)][int]$Offset, - [parameter(Mandatory = $false)][switch]$Local, - [parameter(Mandatory = $false)][switch]$OutGrid - ) - - if ($Local) { - [System.TimeZoneInfo]::Local - } - else { - $TimeZones = [System.TimeZoneInfo]::GetSystemTimeZones() - - if ($Name) { - $TimeZones = $TimeZones | Where-Object { $_.DisplayName -like "*$($Name)*" -or $_.DaylightName -like "*$($Name)*" -or - $_.StandardName -like "*$($Name)*" -or - $_.Id -like "*$($Name)*" } - } - - if ($Offset) { - $TimeZones = $TimeZones | Where-Object { $_.BaseUtcOffset.Hours -eq $Offset } - } - - if ($OutGrid) { - $TimeZones | Out-Gridview -Title "Select the timezone(s) to return" -PassThru - } - else { - $TimeZones - } - - } -} \ No newline at end of file +Function Find-TimeZone { + <# +.SYNOPSIS + Returns Time Zone information + +.DESCRIPTION + This function will return the information for the system time zones. You can search by name and/or hour offsets. + You can also return the local time zone. + +.PARAMETER Name + All or part of the time zone name. Will be used to perform a wildcard search on the time zones + +.PARAMETER Offset + The number of hours the time zone is offset from UTC + +.PARAMETER local + Use to return the time zone of the current system + +.EXAMPLE + Find-TimeZone -local + Return the time zone of the local system + +.EXAMPLE + Find-TimeZone -Name "GMT" + Search for time zones with 'GMT' in the name + +.EXAMPLE + Find-TimeZone -Name "central" -Offset -6 + Search for time zones with 'Central' in the name and have a UTC offset of -6 hours + +.OUTPUTS + The TimeZoneInfo value or values found +#> + [CmdletBinding()] + [OutputType([System.TimeZoneInfo])] + param( + [parameter(Mandatory = $false)][string]$Name, + [parameter(Mandatory = $false)][int]$Offset, + [parameter(Mandatory = $false)][switch]$Local, + [parameter(Mandatory = $false)][switch]$OutGrid + ) + + if ($Local) { + [System.TimeZoneInfo]::Local + } + else { + $TimeZones = [System.TimeZoneInfo]::GetSystemTimeZones() + + if ($Name) { + $TimeZones = $TimeZones | Where-Object { $_.DisplayName -like "*$($Name)*" -or $_.DaylightName -like "*$($Name)*" -or + $_.StandardName -like "*$($Name)*" -or + $_.Id -like "*$($Name)*" } + } + + if ($Offset) { + $TimeZones = $TimeZones | Where-Object { $_.BaseUtcOffset.Hours -eq $Offset } + } + + if ($OutGrid) { + $TimeZones | Out-Gridview -Title "Select the timezone(s) to return" -PassThru + } + else { + $TimeZones + } + + } +} diff --git a/Public/Get-CronNextOccurrence.ps1 b/Source/Public/Get-CronNextOccurrence.ps1 similarity index 94% rename from Public/Get-CronNextOccurrence.ps1 rename to Source/Public/Get-CronNextOccurrence.ps1 index c8ce038..cbbb2ed 100644 --- a/Public/Get-CronNextOccurrence.ps1 +++ b/Source/Public/Get-CronNextOccurrence.ps1 @@ -1,63 +1,63 @@ -Function Get-CronNextOccurrence { - <# -.SYNOPSIS - Get the next occurrence for a crontab - -.DESCRIPTION - This function will either return the next occurrence, or if an end date is supplied, it will return - all the occurrences between the start and end date. - -.PARAMETER Crontab - A valid crontab string - -.PARAMETER StartTime - The datetime object to find the next occurrence from. Uses current time if not supplied. - -.PARAMETER EndTime - The datetime object to stop finding occurrences for from the StartTime - -.EXAMPLE - Get-CronNextOccurrence -Crontab '0 17 * * *' - - Will return the next occurrence of the crontab from the current time - -.EXAMPLE - $Date = Get-Date '12/14/2032' - Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date - - Will return the next occurrence of the crontab from the time provided - -.EXAMPLE - Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date -EndTime $Date.AddDays(3) - - Will return the all occurrences of the crontab between the two times - -.OUTPUTS - A datetime object for every occurrence returned -#> - [CmdletBinding()] - [OutputType('datetime')] - param( - [Parameter(Mandatory = $true)] - [string]$Crontab, - [Parameter(Mandatory = $false)] - [datetime]$StartTime = (Get-Date), - [Parameter(Mandatory = $false)] - [datetime]$EndTime - ) - # validat crontab - $Schedule = Test-CrontabSchedule -Crontab $Crontab - - # if no end date, just get next occurrence, else find all occurrences between start and end - if ($Schedule.valid -eq $true -and $null -eq $EndTime) { - $schedule.schedule.GetNextOccurrence($StartTime) - } - elseif ($Schedule.valid -eq $true) { - $schedule.schedule.GetNextOccurrences($StartTime, $EndTime) - } - else { - throw $Schedule.ErrorMsg - } - - -} \ No newline at end of file +Function Get-CronNextOccurrence { + <# +.SYNOPSIS + Get the next occurrence for a crontab + +.DESCRIPTION + This function will either return the next occurrence, or if an end date is supplied, it will return + all the occurrences between the start and end date. + +.PARAMETER Crontab + A valid crontab string + +.PARAMETER StartTime + The datetime object to find the next occurrence from. Uses current time if not supplied. + +.PARAMETER EndTime + The datetime object to stop finding occurrences for from the StartTime + +.EXAMPLE + Get-CronNextOccurrence -Crontab '0 17 * * *' + + Will return the next occurrence of the crontab from the current time + +.EXAMPLE + $Date = Get-Date '12/14/2032' + Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date + + Will return the next occurrence of the crontab from the time provided + +.EXAMPLE + Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date -EndTime $Date.AddDays(3) + + Will return the all occurrences of the crontab between the two times + +.OUTPUTS + A datetime object for every occurrence returned +#> + [CmdletBinding()] + [OutputType('datetime')] + param( + [Parameter(Mandatory = $true)] + [string]$Crontab, + [Parameter(Mandatory = $false)] + [datetime]$StartTime = (Get-Date), + [Parameter(Mandatory = $false)] + [datetime]$EndTime + ) + # validat crontab + $Schedule = Test-CrontabSchedule -Crontab $Crontab + + # if no end date, just get next occurrence, else find all occurrences between start and end + if ($Schedule.valid -eq $true -and $null -eq $EndTime) { + $schedule.schedule.GetNextOccurrence($StartTime) + } + elseif ($Schedule.valid -eq $true) { + $schedule.schedule.GetNextOccurrences($StartTime, $EndTime) + } + else { + throw $Schedule.ErrorMsg + } + + +} diff --git a/Public/Get-DateExtended.ps1 b/Source/Public/Get-DateExtended.ps1 similarity index 85% rename from Public/Get-DateExtended.ps1 rename to Source/Public/Get-DateExtended.ps1 index 338ffaf..092f7d4 100644 --- a/Public/Get-DateExtended.ps1 +++ b/Source/Public/Get-DateExtended.ps1 @@ -1,79 +1,80 @@ -Function Get-DateExtended { - <# -.SYNOPSIS - Gets common extended date values that are not included by default with the Get-Date cmdlet - -.DESCRIPTION - This function includes added values for: - FirstDayOfYear : First day of the year - LastDayOfYear : Last day of the year - StartOfWeek : First day of the week - EndOfWeek : Last day of the week - StartOfMonth : First day of the month - EndOfMonth : Last day of the month - TimeZone : Current machine timezone - Quater : The quarter of the year. - - All dates are based on the date passed. If no date is passed in the current date and time are used. - -.PARAMETER Date - The datetime value to return the information for - -.EXAMPLE - Get-DateExtended - Gets extended date and time information based on the current time - -.EXAMPLE - Get-DateExtended "11/17/2017" - Gets extended date and time information for a specific date - -.OUTPUTS - A PSObject containing extended values for the date. -#> - [CmdletBinding()] - [OutputType('DateTimeExtended')] - param( - [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] - [Alias("LastWriteTime")] - [DateTime]$Date = [DateTime]::Now, - - [Parameter()] - [switch] $FromUnixTime, - - [Parameter()] - [ValidateRange(1, 9999)] - [int] $Year, - - [Parameter()] - [ValidateRange(1, 12)] - [int] $Month, - - [Parameter()] - [ValidateRange(1, 31)] - [int] $Day, - - [Parameter()] - [ValidateRange(0, 23)] - [int] $Hour, - - [Parameter()] - [ValidateRange(0, 59)] - [int] $Minute, - - [Parameter()] - [ValidateRange(0, 59)] - [int] $Second, - - [Parameter()] - [ValidateRange(0, 999)] - [int] $Millisecond, - - [Parameter()] - [ValidateSet('Date', 'Time', 'DateTime')] - [string] $DisplayHint - ) - - - [DateTimeExtended]::New((Get-Date @PSBoundParameters)) - -} +Function Get-DateExtended { + <# +.SYNOPSIS + Gets common extended date values that are not included by default with the Get-Date cmdlet + +.DESCRIPTION + This function includes added values for: + FirstDayOfYear : First day of the year + LastDayOfYear : Last day of the year + StartOfWeek : First day of the week + EndOfWeek : Last day of the week + StartOfMonth : First day of the month + EndOfMonth : Last day of the month + TimeZone : Current machine timezone + Quater : The quarter of the year. + + All dates are based on the date passed. If no date is passed in the current date and time are used. + +.PARAMETER Date + The datetime value to return the information for + +.EXAMPLE + Get-DateExtended + Gets extended date and time information based on the current time + +.EXAMPLE + Get-DateExtended "11/17/2017" + Gets extended date and time information for a specific date + +.OUTPUTS + A PSObject containing extended values for the date. +#> + [CmdletBinding()] + [OutputType('DateTimeExtended')] + param( + [Parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] + [Alias("LastWriteTime")] + [DateTime]$Date = [DateTime]::Now, + + [Parameter()] + [switch] $FromUnixTime, + + [Parameter()] + [ValidateRange(1, 9999)] + [int] $Year, + + [Parameter()] + [ValidateRange(1, 12)] + [int] $Month, + + [Parameter()] + [ValidateRange(1, 31)] + [int] $Day, + + [Parameter()] + [ValidateRange(0, 23)] + [int] $Hour, + + [Parameter()] + [ValidateRange(0, 59)] + [int] $Minute, + + [Parameter()] + [ValidateRange(0, 59)] + [int] $Second, + + [Parameter()] + [ValidateRange(0, 999)] + [int] $Millisecond, + + [Parameter()] + [ValidateSet('Date', 'Time', 'DateTime')] + [string] $DisplayHint + ) + + process{ + [DateTimeExtended]::New((Get-Date @PSBoundParameters)) + } + +} diff --git a/Public/Get-DateFormats.ps1 b/Source/Public/Get-DateFormat.ps1 similarity index 87% rename from Public/Get-DateFormats.ps1 rename to Source/Public/Get-DateFormat.ps1 index 1f6b18e..411c806 100644 --- a/Public/Get-DateFormats.ps1 +++ b/Source/Public/Get-DateFormat.ps1 @@ -1,73 +1,74 @@ -Function Get-DateFormats { - <# -.SYNOPSIS - Returns common date and time formats -.DESCRIPTION - This function format date and time values into multiple different common formats. All dates are based on the date passed. - If no date is passed in the current date and time are used. - -.PARAMETER Date - The datetime value to return the formats for - -.EXAMPLE - Get-DateFormats - - Gets formatted date and time information based on the current time -.EXAMPLE - Get-DateFormats -Date "11/17/2017" - - Gets formatted date and time information for a specific date - -.OUTPUTS - A PSObject containing the diffent values for the datetime formats. -#> - [CmdletBinding()] - [OutputType('DateTimeFormats')] - param( - [Parameter(Mandatory = $false)] - [datetime]$Date = $(Get-Date) - ) - - $offset = ([System.TimeZoneInfo]::Local).BaseUtcOffset.ToString() - $offset = $offset.Substring(0, $offset.LastIndexOf(':')) - - [DateTimeFormats]@{ - DateTime = $Date.DateTime - RFC1123UTC = $Date.ToUniversalTime().ToString('r') - SQL = $Date.ToString("yyyy-MM-dd HH:mm:ss.fff") - ISO8601UTC = $Date.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ") - ISO8601 = $Date.ToString("yyyy-MM-ddTHH:mm:ss.fff") + $offset - ShortDate = $Date.ToString('d') - LongDate = $Date.ToString('D') - FullDateShortTime = $Date.ToString('f') - FullDateTime = $Date.ToString('F') - GeneralDateShortTime = $Date.ToString('g') - GeneralDateTime = $Date.ToString('G') - MonthDay = $Date.ToString('M') - RoundTrip = $Date.ToString('o') - RFC1123 = $Date.ToString('r') - SortableDateTime = $Date.ToString('s') - ShortTime = $Date.ToString('t') - LongTime = $Date.ToString('T') - UniversalSortableDateTime = $Date.ToString('u') - UniversalFullDateTime = $Date.ToString('U') - YearMonth = $Date.ToString('Y') - "24HourTime" = $Date.ToString("HH:mm") - Day = $Date.Day - DayAbrv = (Get-Culture).DateTimeFormat.GetAbbreviatedDayName($Date.DayOfWeek.value__) - DayName = $Date.DayOfWeek.ToString() - DayOfWeek = $Date.DayOfWeek.value__ - Month = $Date.Month - MonthName = (Get-Culture).DateTimeFormat.GetMonthName($Date.Month) - MonthAbrv = (Get-Culture).DateTimeFormat.GetAbbreviatedMonthName($Date.Month) - Quater = [Math]::ceiling($Date.Month / 3) - YearQuater = "$($Date.Year)$("{0:00}" -f [Math]::ceiling($Date.Month/3) )" - Year = $Date.Year - WimDatetime = (ConvertTo-WmiDateTime $Date) - UnixEpochTime = (ConvertTo-UnixTime $Date) - IsDaylightSavingTime = $Date.IsDaylightSavingTime() - IsLeapYear = [datetime]::IsLeapYear($Date.Year) - FileTime = $Date.ToFileTime() - - } -} \ No newline at end of file +Function Get-DateFormat { + [alias("Get-DateFormats")] + <# +.SYNOPSIS + Returns common date and time formats +.DESCRIPTION + This function format date and time values into multiple different common formats. All dates are based on the date passed. + If no date is passed in the current date and time are used. + +.PARAMETER Date + The datetime value to return the formats for + +.EXAMPLE + Get-DateFormats + + Gets formatted date and time information based on the current time +.EXAMPLE + Get-DateFormats -Date "11/17/2017" + + Gets formatted date and time information for a specific date + +.OUTPUTS + A PSObject containing the diffent values for the datetime formats. +#> + [CmdletBinding()] + [OutputType([DateTimeFormats])] + param( + [Parameter(Mandatory = $false)] + [datetime]$Date = $(Get-Date) + ) + + $offset = ([System.TimeZoneInfo]::Local).BaseUtcOffset.ToString() + $offset = $offset.Substring(0, $offset.LastIndexOf(':')) + + [DateTimeFormats]@{ + DateTime = $Date.DateTime + RFC1123UTC = $Date.ToUniversalTime().ToString('r') + SQL = $Date.ToString("yyyy-MM-dd HH:mm:ss.fff") + ISO8601UTC = $Date.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ") + ISO8601 = $Date.ToString("yyyy-MM-ddTHH:mm:ss.fff") + $offset + ShortDate = $Date.ToString('d') + LongDate = $Date.ToString('D') + LongDateNoDay = $Date.ToString('D').Substring($Date.ToString('D').IndexOf(',')+2) + FullDateShortTime = $Date.ToString('f') + FullDateTime = $Date.ToString('F') + GeneralDateShortTime = $Date.ToString('g') + GeneralDateTime = $Date.ToString('G') + MonthDay = $Date.ToString('M') + RoundTrip = $Date.ToString('o') + RFC1123 = $Date.ToString('r') + SortableDateTime = $Date.ToString('s') + ShortTime = $Date.ToString('t') + LongTime = $Date.ToString('T') + UniversalSortableDateTime = $Date.ToString('u') + UniversalFullDateTime = $Date.ToString('U') + YearMonth = $Date.ToString('Y') + "24HourTime" = $Date.ToString("HH:mm") + Day = $Date.Day + DayAbrv = (Get-Culture).DateTimeFormat.GetAbbreviatedDayName($Date.DayOfWeek.value__) + DayName = $Date.DayOfWeek.ToString() + DayOfWeek = $Date.DayOfWeek.value__ + Month = $Date.Month + MonthName = (Get-Culture).DateTimeFormat.GetMonthName($Date.Month) + MonthAbrv = (Get-Culture).DateTimeFormat.GetAbbreviatedMonthName($Date.Month) + Quater = [Math]::ceiling($Date.Month / 3) + YearQuater = "$($Date.Year)$("{0:00}" -f [Math]::ceiling($Date.Month/3) )" + Year = $Date.Year + WimDatetime = (ConvertTo-WmiDateTime $Date) + UnixEpochTime = (ConvertTo-UnixTime $Date) + IsDaylightSavingTime = $Date.IsDaylightSavingTime() + IsLeapYear = [datetime]::IsLeapYear($Date.Year) + FileTime = $Date.ToFileTime() + } +} diff --git a/Source/Public/Get-Easter.ps1 b/Source/Public/Get-Easter.ps1 new file mode 100644 index 0000000..5bad776 --- /dev/null +++ b/Source/Public/Get-Easter.ps1 @@ -0,0 +1,66 @@ +Function Get-Easter { + <# + .SYNOPSIS + This function offers a generic Easter computing method for any given year, using Western, Orthodox or Julian algorithms. + + .DESCRIPTION + Shamelessly stolen from python dateutil (https://github.com/dateutil/dateutil/blob/master/src/dateutil/easter.py) + + .PARAMETER Year + The year to get Easter from + + .PARAMETER Calendar + Gregorian : is the default and valid from 1583 to 4099 + Orthodox : valid from 1583 to 4099 + Julian : valid from 326 + + .EXAMPLE + Get-Easter -Year 2024 + + #> + [CmdletBinding()] + [OutputType([datetime])] + param( + [Parameter(Mandatory = $false)] + [int]$year = (Get-Date).Year, + + [Parameter(Mandatory = $false)] + [ValidateSet('Gregorian', 'Julian', 'Orthodox')] + [string]$Calendar = 'Gregorian' + ) + + # Golden year - 1 + $g = $year % 19 + $e = 0 + if ($Calendar -ne 'Gregorian') { + # Old method + $i = (19 * $g + 15) % 30 + $j = ($year + [math]::floor($year / 4) + $i) % 7 + if ($Calendar -eq 'Orthodox') { + # Extra dates to convert Julian to Gregorian date + $e = 10 + if ($year -gt 1600) { + $e = $e + [math]::floor([math]::floor($year / 100) - 16 - ([math]::floor($year / 100) - 16) / 4) + } + } + } + else { + # Century + $c = [math]::floor($year / 100) + # (23 - Epact) mod 30 + $h = ($c - [math]::floor($c / 4) - [math]::floor((8 * $c + 13) / 25) + 19 * $g + 15) % 30 + # Number of days from March 21 to Paschal Full Moon + $i = $h - ([math]::floor($h / 28)) * (1 - ([math]::floor($h / 28)) * ([math]::floor(29 / ($h + 1))) * ([math]::floor((21 - $g) / 11))) + # Weekday for PFM (0=Sunday, etc) + $j = ($year + [math]::floor($year / 4) + $i + 2 - $c + [math]::floor($c / 4)) % 7 + } + + + + # Number of days from March 21 to Sunday on or before PFM + $p = $i - $j + $e + $d = 1 + ($p + 27 + [math]::floor(($p + 6) / 40)) % 31 + $m = 3 + [math]::floor(($p + 26) / 30) + + [datetime]::new($year, $m, $d) +} diff --git a/Public/Get-PatchTuesday.ps1 b/Source/Public/Get-PatchTuesday.ps1 similarity index 74% rename from Public/Get-PatchTuesday.ps1 rename to Source/Public/Get-PatchTuesday.ps1 index f504391..0ff24db 100644 --- a/Public/Get-PatchTuesday.ps1 +++ b/Source/Public/Get-PatchTuesday.ps1 @@ -1,60 +1,60 @@ -Function Get-PatchTuesday { - <# -.SYNOPSIS - Returns the second Tuesday of the month - -.DESCRIPTION - This function allow you to pass a date, or a month/year combination to find the second Tuesday (aka Patch Tuesday) of any month - -.PARAMETER Date - The datetime value to return the second Tuesday for the month - -.PARAMETER Month - The month to return the second Tuesday for. Enter a value from 1 to 12. - -.PARAMETER Year - The year to return the second Tuesday for. Enter a value from 1 to 9999 - -.EXAMPLE - Get-PatchTuesday - Returns the second Tuesday for the current month - -.EXAMPLE - Get-PatchTuesday -Date "11/17/2021" - Returns the second Tuesday for November 2021 - -.EXAMPLE - Get-PatchTuesday -Month 6 -Year 2020 - Returns the second Tuesday for June 2020 - -.EXAMPLE - Get-PatchTuesday -Month 4 - Returns the second Tuesday for April of the current year - -.OUTPUTS - A datetime object of the second Tuesday. -#> - [CmdletBinding(DefaultParameterSetName = 'Date')] - [OutputType('datetime')] - param( - [Parameter(Mandatory = $false, ParameterSetName = "Date")] - [datetime]$Date = $(Get-Date), - [Parameter(Mandatory = $false, ParameterSetName = "MonthYear")] - [ValidateRange(1, 12)] - [int]$Month = $(Get-Date).Month, - [Parameter(Mandatory = $false, ParameterSetName = "MonthYear")] - [ValidateRange(1, 9999)] - [int]$Year = $(Get-Date).Year - ) - # Get the first day of the month - if ($PsCmdlet.ParameterSetName -eq "MonthYear") { - $StartOfMonth = (Get-Date -Day 1 -Month $Month -Year $Year).Date - } - else { - $StartOfMonth = Get-Date $date.Date -Day 1 - } - - # Get every Tuesday, and return the second one - (0..30 | Foreach-Object { $StartOfMonth.adddays($_) } | Where-Object { $_.dayofweek.value__ -eq 2 })[1] - -} \ No newline at end of file +Function Get-PatchTuesday { + <# +.SYNOPSIS + Returns the second Tuesday of the month + +.DESCRIPTION + This function allow you to pass a date, or a month/year combination to find the second Tuesday (aka Patch Tuesday) of any month + +.PARAMETER Date + The datetime value to return the second Tuesday for the month + +.PARAMETER Month + The month to return the second Tuesday for. Enter a value from 1 to 12. + +.PARAMETER Year + The year to return the second Tuesday for. Enter a value from 1 to 9999 + +.EXAMPLE + Get-PatchTuesday + Returns the second Tuesday for the current month + +.EXAMPLE + Get-PatchTuesday -Date "11/17/2021" + Returns the second Tuesday for November 2021 + +.EXAMPLE + Get-PatchTuesday -Month 6 -Year 2020 + Returns the second Tuesday for June 2020 + +.EXAMPLE + Get-PatchTuesday -Month 4 + Returns the second Tuesday for April of the current year + +.OUTPUTS + A datetime object of the second Tuesday. +#> + [CmdletBinding(DefaultParameterSetName = 'Date')] + [OutputType([datetime])] + param( + [Parameter(Mandatory = $false, ParameterSetName = "Date")] + [datetime]$Date = $(Get-Date), + [Parameter(Mandatory = $false, ParameterSetName = "MonthYear")] + [ValidateRange(1, 12)] + [int]$Month = $(Get-Date).Month, + [Parameter(Mandatory = $false, ParameterSetName = "MonthYear")] + [ValidateRange(1, 9999)] + [int]$Year = $(Get-Date).Year + ) + + if ($PsCmdlet.ParameterSetName -eq "MonthYear") { + $date = (Get-Date -Day 1 -Month $Month -Year $Year).Date + } + + # Get the first day of the month + $StartOfMonth = Get-Date $date.Date -Day 1 + + # Get every Tuesday, and return the second one + $ptdate = (0..30 | Foreach-Object { $StartOfMonth.adddays($_) } | Where-Object { $_.dayofweek.value__ -eq 2 })[1] + $ptdate.Date +} diff --git a/Source/Public/New-Duration.ps1 b/Source/Public/New-Duration.ps1 new file mode 100644 index 0000000..b21588b --- /dev/null +++ b/Source/Public/New-Duration.ps1 @@ -0,0 +1,105 @@ +Function New-Duration { + <# + .SYNOPSIS + Calculates the time span between two dates and returns the duration in the ISO 8601 format + + .DESCRIPTION + Calculates the timespan between two dates and returns the duration in the ISO 8601 format + + https://en.wikipedia.org/wiki/ISO_8601#Durations + + .PARAMETER Start + Specifies the start of a time span. + + .PARAMETER End + Specifies the end of a time span. End date must be greater than the start date + + .EXAMPLE + New-Duration -Start '2/3/2023' -End (Get-Date) + + .EXAMPLE + New-Duration -Days 1 -Hours 4 + + .EXAMPLE + New-Duration -Weeks 3 + #> + [CmdletBinding()] + [OutputType([string])] + param( + [Parameter(Mandatory = $true, + ParameterSetName = "datetime")] + [datetime]$Start, + + [Parameter(Mandatory = $true, + ParameterSetName = "datetime")] + [datetime]$End, + + [Parameter(Mandatory = $false, + ParameterSetName = "numbers")] + [int]$Years = 0, + + [Parameter(Mandatory = $false, + ParameterSetName = "numbers")] + [int]$Months = 0, + + [Parameter(Mandatory = $false, + ParameterSetName = "numbers")] + [int]$Days = 0, + + [Parameter(Mandatory = $false, + ParameterSetName = "numbers")] + [int]$Hours = 0, + + [Parameter(Mandatory = $false, + ParameterSetName = "numbers")] + [int]$Minutes = 0, + + [Parameter(Mandatory = $false, + ParameterSetName = "numbers")] + [int]$Seconds = 0, + + [Parameter(Mandatory = $false, + ParameterSetName = "week")] + [int]$Weeks = 0 + ) + + if ($Start -gt $End) { + throw "Start date must be before the end date" + } + if ($PSCmdlet.ParameterSetName -eq 'datetime') { + # If start date is later in the month offset by 1 + $daysOffset = if ($start.Day -gt $End.Day) { 1 }else { 0 } + # Get the total months between dates + $TotalMonths = ($End.Month - $start.Month - $daysOffset) + ($End.Year - $start.Year) * 12 + # Get the number of years + $Years = [math]::floor($TotalMonths / 12) + # Get the number of months less the years + $Months = $TotalMonths % 12 + # Calculate the remaining timespan + $TimeSpan = New-TimeSpan -Start $start.AddYears($Years).AddMonths($Months) -End $End + + # Set variables to build the string + $Days = $TimeSpan.Days + $Hours = $TimeSpan.Hours + $Minutes = $TimeSpan.Minutes + $Seconds = $TimeSpan.Seconds + } + + $Duration = 'P' + if ($Years -ne 0) { $Duration += "$($Years)Y" } + if ($Weeks -ne 0) { $Duration += "$($Weeks)W" } + if ($Months -ne 0) { $Duration += "$($Months)M" } + if ($Days -ne 0) { $Duration += "$($Days)D" } + if (($Hours + $Minutes + $Seconds) -ne 0) { + $Duration += "T" + if ($Hours -ne 0) { $Duration += "$($Hours)H" } + if ($Minutes -ne 0) { $Duration += "$($Minutes)M" } + if ($Seconds -ne 0) { $Duration += "$($Seconds)S" } + } + + if($Duration -eq 'P'){ + $Duration = 'PT0S' + } + + $Duration +} diff --git a/Public/Test-CrontabSchedule.ps1 b/Source/Public/Test-CrontabSchedule.ps1 similarity index 93% rename from Public/Test-CrontabSchedule.ps1 rename to Source/Public/Test-CrontabSchedule.ps1 index 3359890..c8ce361 100644 --- a/Public/Test-CrontabSchedule.ps1 +++ b/Source/Public/Test-CrontabSchedule.ps1 @@ -1,56 +1,56 @@ -Function Test-CrontabSchedule { - <# -.SYNOPSIS - Tests that a crontab string is valid - -.DESCRIPTION - This function attempts to parse a crontab string to ensure it is valid. - -.PARAMETER Crontab - The datetime value to return the second Tuesday for the month - -.EXAMPLE - Test-CrontabSchedule -crontab '0 17 * * *' - - Valid schedule that returns: - Crontab Valid - ------- ----- - 0 17 * * * True - -.EXAMPLE - Test-CrontabSchedule -crontab '0 17 * 13 *' - - Invalid schedule that returns: - Crontab Valid ErrorMsg - ------- ----- -------- - 0 17 * 13 * False 13 is higher than the maximum allowable value for the [Month] field. Value must be between 1 and 12 (all inclusive). - -.OUTPUTS - A psobject that contains the crontable, a validation value, and any error messages returned -#> - [CmdletBinding()] - [OutputType('string')] - param( - [Parameter(Mandatory = $true)] - [string]$Crontab - ) - - $Result = [ordered]@{ - Schedule = $Crontab - Valid = $false - } - - try { - $Result['Schedule'] = [NCrontab.CrontabSchedule]::Parse($Crontab) - $Result['Valid'] = $true - } - catch { - $ErrorMsg = $_.Exception.ErrorRecord.ToString() - $ErrorMsg = $ErrorMsg.Substring($ErrorMsg.IndexOf(': "') + 3) - $ErrorMsg = $ErrorMsg.Substring(0, $ErrorMsg.Length - 1) - $Result.Add('ErrorMsg', $ErrorMsg) - } - - [PSCustomObject]$Result - -} \ No newline at end of file +Function Test-CrontabSchedule { + <# +.SYNOPSIS + Tests that a crontab string is valid + +.DESCRIPTION + This function attempts to parse a crontab string to ensure it is valid. + +.PARAMETER Crontab + The datetime value to return the second Tuesday for the month + +.EXAMPLE + Test-CrontabSchedule -crontab '0 17 * * *' + + Valid schedule that returns: + Crontab Valid + ------- ----- + 0 17 * * * True + +.EXAMPLE + Test-CrontabSchedule -crontab '0 17 * 13 *' + + Invalid schedule that returns: + Crontab Valid ErrorMsg + ------- ----- -------- + 0 17 * 13 * False 13 is higher than the maximum allowable value for the [Month] field. Value must be between 1 and 12 (all inclusive). + +.OUTPUTS + A psobject that contains the crontable, a validation value, and any error messages returned +#> + [CmdletBinding()] + [OutputType([string])] + param( + [Parameter(Mandatory = $true)] + [string]$Crontab + ) + + $Result = [ordered]@{ + Schedule = $Crontab + Valid = $false + } + + try { + $Result['Schedule'] = [NCrontab.CrontabSchedule]::Parse($Crontab) + $Result['Valid'] = $true + } + catch { + $ErrorMsg = $_.Exception.ErrorRecord.ToString() + $ErrorMsg = $ErrorMsg.Substring($ErrorMsg.IndexOf(': "') + 3) + $ErrorMsg = $ErrorMsg.Substring(0, $ErrorMsg.Length - 1) + $Result.Add('ErrorMsg', $ErrorMsg) + } + + [PSCustomObject]$Result + +} diff --git a/Resources/DateTimeExtensions.format.ps1xml b/Source/Resources/DateTimeExtensions.format.ps1xml similarity index 100% rename from Resources/DateTimeExtensions.format.ps1xml rename to Source/Resources/DateTimeExtensions.format.ps1xml diff --git a/Resources/ncrontab.3.3.0/lib/net35/NCrontab.dll b/Source/Resources/NCrontab.dll similarity index 100% rename from Resources/ncrontab.3.3.0/lib/net35/NCrontab.dll rename to Source/Resources/NCrontab.dll diff --git a/Resources/ncrontab.3.3.0/COPYING.txt b/Source/Resources/ncrontab.3.3.0/COPYING.txt similarity index 100% rename from Resources/ncrontab.3.3.0/COPYING.txt rename to Source/Resources/ncrontab.3.3.0/COPYING.txt diff --git a/Source/Resources/ncrontab.3.3.0/lib/net35/NCrontab.dll b/Source/Resources/ncrontab.3.3.0/lib/net35/NCrontab.dll new file mode 100644 index 0000000..e2138c6 Binary files /dev/null and b/Source/Resources/ncrontab.3.3.0/lib/net35/NCrontab.dll differ diff --git a/Resources/ncrontab.3.3.0/lib/netstandard1.0/NCrontab.dll b/Source/Resources/ncrontab.3.3.0/lib/netstandard1.0/NCrontab.dll similarity index 100% rename from Resources/ncrontab.3.3.0/lib/netstandard1.0/NCrontab.dll rename to Source/Resources/ncrontab.3.3.0/lib/netstandard1.0/NCrontab.dll diff --git a/Resources/ncrontab.3.3.0/lic/OpenSymphony.txt b/Source/Resources/ncrontab.3.3.0/lic/OpenSymphony.txt similarity index 100% rename from Resources/ncrontab.3.3.0/lic/OpenSymphony.txt rename to Source/Resources/ncrontab.3.3.0/lic/OpenSymphony.txt diff --git a/Resources/ncrontab.3.3.0/ncrontab.3.3.0.nupkg b/Source/Resources/ncrontab.3.3.0/ncrontab.3.3.0.nupkg similarity index 100% rename from Resources/ncrontab.3.3.0/ncrontab.3.3.0.nupkg rename to Source/Resources/ncrontab.3.3.0/ncrontab.3.3.0.nupkg diff --git a/Source/Test/Public/Convert-TimeZone.Tests.ps1 b/Source/Test/Public/Convert-TimeZone.Tests.ps1 new file mode 100644 index 0000000..c119599 --- /dev/null +++ b/Source/Test/Public/Convert-TimeZone.Tests.ps1 @@ -0,0 +1,17 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'Convert-TimeZone Tests' { + It 'Convert-TimeZone Test' { + $conversion = Convert-TimeZone -Date '11/17/2017 12:34 AM' -FromTimeZone "China Standard Time" -ToTimeZone "US Mountain Standard Time" + $conversion.FromDateTime | Should -Be (Get-Date '11/17/2017 12:34:00 AM') + $conversion.FromTimeZone | Should -Be 'China Standard Time' + $conversion.ToDateTime | Should -Be (Get-Date '11/16/2017 9:34:00 AM') + $conversion.ToTimeZone | Should -Be 'US Mountain Standard Time' + $conversion.Offset | Should -Be '-15:00:00' + } +} diff --git a/Source/Test/Public/ConvertFrom-UnixTime.Tests.ps1 b/Source/Test/Public/ConvertFrom-UnixTime.Tests.ps1 new file mode 100644 index 0000000..320e0c6 --- /dev/null +++ b/Source/Test/Public/ConvertFrom-UnixTime.Tests.ps1 @@ -0,0 +1,12 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'ConvertFrom-UnixTime Tests' { + It 'ConvertFrom-UnixTime Test' { + ConvertFrom-UnixTime -UnixTime 1510876800 | Should -Be (Get-Date '2017-11-17T00:00:00.000Z').ToUniversalTime() + } +} diff --git a/Source/Test/Public/ConvertFrom-WmiDateTime.Tests.ps1 b/Source/Test/Public/ConvertFrom-WmiDateTime.Tests.ps1 new file mode 100644 index 0000000..9ab2184 --- /dev/null +++ b/Source/Test/Public/ConvertFrom-WmiDateTime.Tests.ps1 @@ -0,0 +1,12 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'ConvertFrom-WmiDateTime Tests' { + It 'ConvertFrom-WmiDateTime Test' { + ConvertFrom-WmiDateTime -WmiTime '20190912173652.000000-000' | Should -Be (Get-Date '2019-09-12T17:36:52.000Z').ToLocalTime() + } +} diff --git a/Source/Test/Public/ConvertTo-UnixTime.Tests.ps1 b/Source/Test/Public/ConvertTo-UnixTime.Tests.ps1 new file mode 100644 index 0000000..7143ed5 --- /dev/null +++ b/Source/Test/Public/ConvertTo-UnixTime.Tests.ps1 @@ -0,0 +1,12 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'ConvertTo-UnixTime Tests' { + It 'ConvertTo-UnixTime Test' { + ConvertTo-UnixTime -Date (Get-Date '2017-11-17T00:00:00.000Z').ToUniversalTime() | Should -Be 1510876800 + } +} diff --git a/Source/Test/Public/ConvertTo-WmiDateTime.Tests.ps1 b/Source/Test/Public/ConvertTo-WmiDateTime.Tests.ps1 new file mode 100644 index 0000000..18379a5 --- /dev/null +++ b/Source/Test/Public/ConvertTo-WmiDateTime.Tests.ps1 @@ -0,0 +1,12 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'ConvertTo-WmiDateTime Tests' { + It 'ConvertTo-WmiDateTime Test' { + ConvertTo-WmiDateTime -Date (Get-Date '2017-06-25T16:17:00.000Z').ToUniversalTime() | Should -Be '20170625161700.000000+000' + } +} diff --git a/Source/Test/Public/Find-TimeZone.Tests.ps1 b/Source/Test/Public/Find-TimeZone.Tests.ps1 new file mode 100644 index 0000000..e881512 --- /dev/null +++ b/Source/Test/Public/Find-TimeZone.Tests.ps1 @@ -0,0 +1,16 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'Find-TimeZone Tests' { + It 'Find-TimeZone Test' { + $london = 'GMT Standard Time' + if($IsLinux){ + $london = 'Europe/London' + } + (Find-TimeZone -Name "London").Id | Should -Be $london + } +} diff --git a/Source/Test/Public/Get-CronNextOccurrence.Tests.ps1 b/Source/Test/Public/Get-CronNextOccurrence.Tests.ps1 new file mode 100644 index 0000000..a20b13a --- /dev/null +++ b/Source/Test/Public/Get-CronNextOccurrence.Tests.ps1 @@ -0,0 +1,27 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'Get-CronNextOccurrence Tests' { + It 'Get-CronNextOccurrence Test' { + $fivePM = Get-Date '17:00' + if($fivePM -lt (Get-Date)){ + $fivePM = $fivePM.AddDays(1) + } + Get-CronNextOccurrence -Crontab '0 17 * * *' | Should -Be $fivePM + } + It 'Get-CronNextOccurrence Specific Date Test' { + $StartTime = Get-Date '12/14/2032' + Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $StartTime | Should -Be (Get-Date '12/14/2032 17:00') + } + It 'Get-CronNextOccurrence Multiple Occurrences Test' { + $StartTime = Get-Date '12/14/2032' + $threeDays = 14..16 | ForEach-Object{ + Get-Date "12/$($_)/2032 17:00" + } + Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $StartTime -EndTime $StartTime.AddDays(3) | Should -Be $threeDays + } +} diff --git a/Source/Test/Public/Get-DateExtended.Tests.ps1 b/Source/Test/Public/Get-DateExtended.Tests.ps1 new file mode 100644 index 0000000..b212936 --- /dev/null +++ b/Source/Test/Public/Get-DateExtended.Tests.ps1 @@ -0,0 +1,35 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'Get-DateExtended Tests' { + It 'Get-DateExtended Test' { + $dateExt = Get-DateExtended "11/17/2017" + $dateExt.DateTime | Should -Be (Get-Date '11/17/2017 00:00:00') + $dateExt.FirstDayOfYear | Should -Be (Get-Date '01/01/2017 00:00:00') + $dateExt.LastDayOfYear | Should -Be (Get-Date '12/31/2017 00:00:00') + $dateExt.StartOfWeek | Should -Be (Get-Date '11/12/2017 00:00:00') + $dateExt.EndOfWeek | Should -Be (Get-Date '11/18/2017 23:59:59') + $dateExt.StartOfMonth | Should -Be (Get-Date '11/01/2017 00:00:00') + $dateExt.EndOfMonth | Should -Be (Get-Date '11/30/2017 23:59:59') + $dateExt.WeekOfYear | Should -Be 46 + $dateExt.TimeZone | Should -Be ([System.TimeZoneInfo]::Local) + $dateExt.Quater | Should -Be 4 + $dateExt.Date | Should -Be (Get-Date '11/17/2017 00:00:00') + $dateExt.Day | Should -Be 17 + $dateExt.DayOfWeek | Should -Be 'Friday' + $dateExt.DayOfYear | Should -Be 321 + $dateExt.Hour | Should -Be 0 + $dateExt.Kind | Should -Be 'Unspecified' + $dateExt.Millisecond | Should -Be 0 + $dateExt.Minute | Should -Be 0 + $dateExt.Month | Should -Be 11 + $dateExt.Second | Should -Be 0 + $dateExt.Ticks | Should -Be 636464736000000000 + $dateExt.TimeOfDay | Should -Be 00:00:00 + $dateExt.Year | Should -Be 2017 + } +} diff --git a/Source/Test/Public/Get-DateFormat.Tests.ps1 b/Source/Test/Public/Get-DateFormat.Tests.ps1 new file mode 100644 index 0000000..1b97fc7 --- /dev/null +++ b/Source/Test/Public/Get-DateFormat.Tests.ps1 @@ -0,0 +1,50 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force + [cultureinfo]::CurrentCulture = 'en-US' +} + +Describe 'Get-DateFormat Tests' { + It 'Get-DateFormat Test' { + $dateFormat = Get-DateFormat -Date (Get-Date '2017-11-17T00:00:00.000Z').ToUniversalTime() + $dateFormat.'24HourTime' | Should -Be '00:00' + $dateFormat.DateTime | Should -Be '11/17/2017 00:00:00' + $dateFormat.Day | Should -Be '17' + $dateFormat.DayAbrv | Should -Be 'Fri' + $dateFormat.DayName | Should -Be 'Friday' + $dateFormat.DayOfWeek | Should -Be '5' + $dateFormat.FileTime | Should -Be '131553504000000000' + $dateFormat.FullDateShortTime | Should -Be 'Friday, November 17, 2017 12:00 AM' + $dateFormat.FullDateTime | Should -Be 'Friday, November 17, 2017 12:00:00 AM' + $dateFormat.GeneralDateShortTime | Should -Be '11/17/2017 12:00 AM' + $dateFormat.GeneralDateTime | Should -Be '11/17/2017 12:00:00 AM' + $dateFormat.IsDaylightSavingTime | Should -Be 'False' + $dateFormat.IsLeapYear | Should -Be 'False' + $dateFormat.ISO8601 | Should -Match '2017-11-17T00:00:00.000' + $dateFormat.ISO8601UTC | Should -Be '2017-11-17T00:00:00.000Z' + $dateFormat.LongDate | Should -Be 'Friday, November 17, 2017' + $dateFormat.LongDateNoDay | Should -Be 'November 17, 2017' + $dateFormat.LongTime | Should -Be '12:00:00 AM' + $dateFormat.Month | Should -Be '11' + $dateFormat.MonthAbrv | Should -Be 'Nov' + $dateFormat.MonthDay | Should -Be 'November 17' + $dateFormat.MonthName | Should -Be 'November' + $dateFormat.Quater | Should -Be '4' + $dateFormat.RFC1123 | Should -Be 'Fri, 17 Nov 2017 00:00:00 GMT' + $dateFormat.RFC1123UTC | Should -Be 'Fri, 17 Nov 2017 00:00:00 GMT' + $dateFormat.RoundTrip | Should -Be '2017-11-17T00:00:00.0000000Z' + $dateFormat.ShortDate | Should -Be '11/17/2017' + $dateFormat.ShortTime | Should -Be '12:00 AM' + $dateFormat.SortableDateTime | Should -Be '2017-11-17T00:00:00' + $dateFormat.SQL | Should -Be '2017-11-17 00:00:00.000' + $dateFormat.UniversalFullDateTime | Should -Be 'Friday, November 17, 2017 12:00:00 AM' + $dateFormat.UniversalSortableDateTime | Should -Be '2017-11-17 00:00:00Z' + $dateFormat.UnixEpochTime | Should -Be '1510876800' + $dateFormat.WimDatetime | Should -Be '20171117000000.000000+000' + $dateFormat.Year | Should -Be '2017' + $dateFormat.YearMonth | Should -Be 'November 2017' + $dateFormat.YearQuater | Should -Be '201704' + } +} diff --git a/Source/Test/Public/Get-Easter.Tests.ps1 b/Source/Test/Public/Get-Easter.Tests.ps1 new file mode 100644 index 0000000..478164f --- /dev/null +++ b/Source/Test/Public/Get-Easter.Tests.ps1 @@ -0,0 +1,40 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'Get-Easter Tests' { + It ' Gregorian Test' -ForEach @( + @{Year = '1583'; Easter = '1583-04-10'; } + @{Year = '1612'; Easter = '1612-04-22'; } + @{Year = '1722'; Easter = '1722-04-05'; } + @{Year = '1784'; Easter = '1784-04-11'; } + @{Year = '1892'; Easter = '1892-04-17'; } + @{Year = '2075'; Easter = '2075-04-07'; } + @{Year = '2096'; Easter = '2096-04-15'; } + @{Year = '2221'; Easter = '2221-04-15'; } + @{Year = '2369'; Easter = '2369-03-30'; } + @{Year = '2387'; Easter = '2387-04-05'; } + @{Year = '2553'; Easter = '2553-04-01'; } + @{Year = '2599'; Easter = '2599-04-07'; } + @{Year = '2715'; Easter = '2715-04-11'; } + @{Year = '2861'; Easter = '2861-04-17'; } + @{Year = '2933'; Easter = '2933-04-05'; } + @{Year = '3078'; Easter = '3078-04-21'; } + @{Year = '3125'; Easter = '3125-04-12'; } + @{Year = '3229'; Easter = '3229-04-08'; } + @{Year = '3372'; Easter = '3372-04-12'; } + @{Year = '3457'; Easter = '3457-04-05'; } + @{Year = '3510'; Easter = '3510-04-24'; } + @{Year = '3681'; Easter = '3681-04-20'; } + @{Year = '3695'; Easter = '3695-04-17'; } + @{Year = '3783'; Easter = '3783-04-06'; } + @{Year = '3947'; Easter = '3947-04-20'; } + @{Year = '3988'; Easter = '3988-04-17'; } + @{Year = '4099'; Easter = '4099-04-19'; } + ) { + Get-Easter $Year | Should -Be (Get-Date $Easter) + } +} \ No newline at end of file diff --git a/Source/Test/Public/Get-PatchTuesday.Tests.ps1 b/Source/Test/Public/Get-PatchTuesday.Tests.ps1 new file mode 100644 index 0000000..7903654 --- /dev/null +++ b/Source/Test/Public/Get-PatchTuesday.Tests.ps1 @@ -0,0 +1,12 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'Get-PatchTuesday Tests' { + It 'Get-PatchTuesday Test' { + Get-PatchTuesday -Date "11/17/2021" | Should -Be (Get-Date '2021-11-09') + } +} diff --git a/Source/Test/Public/New-Duration.Tests.ps1 b/Source/Test/Public/New-Duration.Tests.ps1 new file mode 100644 index 0000000..c343aa1 --- /dev/null +++ b/Source/Test/Public/New-Duration.Tests.ps1 @@ -0,0 +1,14 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'New-Duration Tests' { + It 'New-Duration Test' { + New-Duration -Start '2/3/2023' -End '2/5/2023' | Should -Be 'P2D' + New-Duration -Days 1 -Hours 4 | Should -Be 'P1DT4H' + New-Duration -Weeks 3 | Should -Be 'P3W' + } +} diff --git a/Source/Test/Public/Test-CrontabSchedule.Tests.ps1 b/Source/Test/Public/Test-CrontabSchedule.Tests.ps1 new file mode 100644 index 0000000..c533597 --- /dev/null +++ b/Source/Test/Public/Test-CrontabSchedule.Tests.ps1 @@ -0,0 +1,21 @@ +BeforeAll { + # Import the module + $TopLevel = (Split-Path(Split-Path(Split-Path $PSScriptRoot))) + $ModulePath = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + Import-Module $ModulePath.FullName -Force +} + +Describe 'Test-CrontabSchedule Tests' { + It 'Test-CrontabSchedule Valid Test' { + $valid = Test-CrontabSchedule -crontab '0 17 * * *' + $valid.Schedule | Should -Be '0 17 * * *' + $valid.Valid | Should -BeTrue + } + + It 'Test-CrontabSchedule Invalid Test' { + $invalid = Test-CrontabSchedule -crontab '0 17 * 13 *' + $invalid.Schedule | Should -Be '0 17 * 13 *' + $invalid.Valid | Should -BeFalse + $invalid.ErrorMsg | Should -Be '13 is higher than the maximum allowable value for the [Month] field. Value must be between 1 and 12 (all inclusive).' + } +} diff --git a/Source/Test/ScriptAnalyzer/PSScriptAnalyzerSettings.psd1 b/Source/Test/ScriptAnalyzer/PSScriptAnalyzerSettings.psd1 new file mode 100644 index 0000000..c44d026 --- /dev/null +++ b/Source/Test/ScriptAnalyzer/PSScriptAnalyzerSettings.psd1 @@ -0,0 +1,4 @@ +@{ + Severity=@('Error','Warning') + ExcludeRules=@('PSUseShouldProcessForStateChangingFunctions') +} \ No newline at end of file diff --git a/Source/Test/ScriptAnalyzer/ScriptAnalyzer.Linter.ps1 b/Source/Test/ScriptAnalyzer/ScriptAnalyzer.Linter.ps1 new file mode 100644 index 0000000..2f8798c --- /dev/null +++ b/Source/Test/ScriptAnalyzer/ScriptAnalyzer.Linter.ps1 @@ -0,0 +1,4 @@ +$Public = Join-Path (Split-Path(Split-Path $PSScriptRoot)) 'Public' +$Settings = Join-Path $PSScriptRoot 'PSScriptAnalyzerSettings.psd1' +Invoke-ScriptAnalyzer -Path $Public -Recurse -Settings $Settings + diff --git a/Tests/Get-DateExtended.Test.ps1 b/Tests/Get-DateExtended.Test.ps1 deleted file mode 100644 index e69de29..0000000 diff --git a/build-docs.ps1 b/build-docs.ps1 new file mode 100644 index 0000000..6459bef --- /dev/null +++ b/build-docs.ps1 @@ -0,0 +1,37 @@ +Set-Location $PSScriptRoot + +if(-not (Test-Path .\Build)){ + throw "Project must be built first" +} + +$psd1 = Get-ChildItem .\Build -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 +Import-Module $psd1.FullName -Force + +Get-ChildItem .\docs -Filter '*.md' | Remove-Item -Force + +New-MarkdownHelp -Module PSDates -OutputFolder .\docs + +$readme = Get-Content .\README.md +$docs = Get-ChildItem .\docs -Filter '*.md' | ForEach-Object{ + "* [$($_.BaseName)](docs/$($_.Name))" +} + +$commands = $false +$readmeupdate = foreach($line in $readme){ + if($line -eq '# Commands'){ + $commands = $true + $line + '' + $docs + '' + } + elseif($commands -and $line -match '^#'){ + $commands = $false + } + + if(-not $commands){ + $line + } +} + +$readmeupdate | Out-File .\README.md \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..428b1cf --- /dev/null +++ b/build.ps1 @@ -0,0 +1,30 @@ +param( + [Parameter(Mandatory = $false)] + [string]$Version = 'v1.0.0' +) + +$VersionNumber = [version]::parse($Version.Split('/')[-1].TrimStart('v')) +Set-Location $PSScriptRoot + +if(Test-Path .\Build){ + Get-ChildItem -Path .\Build | Remove-Item -Recurse -Force +} + +$linter = . '.\Source\Test\ScriptAnalyzer\ScriptAnalyzer.Linter.ps1' +if ($linter) { + $linter + throw "Failed linter tests" +} + +Build-Module -SourcePath .\Source -OutputDirectory ..\Build -Version $VersionNumber + +$psd1 = Get-ChildItem .\Build -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1 + +$ResourceFolder = Join-Path $psd1.DirectoryName 'Resources' +New-Item -Path $ResourceFolder -ItemType Directory | Out-Null +Copy-Item -Path '.\Source\Resources\ncrontab.3.3.0\lib\net35\NCrontab.dll' -Destination $ResourceFolder +Copy-Item -Path '.\Source\Resources\DateTimeExtensions.format.ps1xml' -Destination $ResourceFolder + +#$nuspec = Copy-Item -Path .\Source\PSDates.nuspec -Destination $psd1.DirectoryName -PassThru + +#.'nuget.exe' pack "$($nuspec.FullName)" -OutputDirectory .\Build -Version "$($VersionNumber)" \ No newline at end of file diff --git a/docs/Convert-TimeZone.md b/docs/Convert-TimeZone.md new file mode 100644 index 0000000..2736dac --- /dev/null +++ b/docs/Convert-TimeZone.md @@ -0,0 +1,133 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# Convert-TimeZone + +## SYNOPSIS + +Convert a datetime value from one time zone to another + +## SYNTAX + +### Default + +``` +Convert-TimeZone -ToTimeZone [-Date ] [-FromTimeZone ] [] +``` + +## DESCRIPTION + +This function will allows you to pass a date to convert from one time zone to another. +If no date is specified the local time is used. +If no FromTimeZone is passed then the +local time zone is used. +If you don't know the time zone ID you can use the Find-TimeZone cmdlet. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +Convert-TimeZone -ToTimeZone "GMT Standard Time" +``` + +Convert the local system time to GMT Standard Time + + + + + +### Example 2: EXAMPLE 2 + +``` +Convert-TimeZone -date '11/17/2017 12:34 AM' -FromTimeZone "China Standard Time" -ToTimeZone "US Mountain Standard Time" +``` + +Converts the date and time 11/17/2017 12:34 AM from 'China Standard Time' to 'US Mountain Standard Time' + + + + + + +## PARAMETERS + +### -Date + +The date to convert. +If not specified the current time will be used + +```yaml +Type: DateTime +Parameter Sets: Default +Aliases: +Accepted values: + +Required: True (None) False (Default) +Position: Named +Default value: $(Get-Date) +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -FromTimeZone + +The time zone ID of the time zone you want to convert the date from. +If not specified the local time zone will be used + +```yaml +Type: String +Parameter Sets: Default +Aliases: +Accepted values: + +Required: True (None) False (Default) +Position: Named +Default value: [System.TimeZoneInfo]::Local.Id.ToString() +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -ToTimeZone + +The time zone ID of the time zone you want to convert the date to + +```yaml +Type: String +Parameter Sets: Default +Aliases: +Accepted values: + +Required: True (Default) False (None) +Position: Named +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### A PSObject object containing the time zone conversion data + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/ConvertFrom-UnixTime.md b/docs/ConvertFrom-UnixTime.md new file mode 100644 index 0000000..2ab1133 --- /dev/null +++ b/docs/ConvertFrom-UnixTime.md @@ -0,0 +1,80 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# ConvertFrom-UnixTime + +## SYNOPSIS + +Converts a Unix Time value to a datetime value + +## SYNTAX + +### __AllParameterSets + +``` +ConvertFrom-UnixTime [-UnixTime] [] +``` + +## DESCRIPTION + +This function will return the datetime based on the unix epoch time. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +ConvertFrom-UnixTime -UnixTime 1509512400 +Gets datetime for the Unix time 1509512400 +``` + + + + + + + + +## PARAMETERS + +### -UnixTime + +The UnixTime value to return the datetime for + +```yaml +Type: Double +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (All) False (None) +Position: 0 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### The datetime value based on the unix time + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/ConvertFrom-WmiDateTime.md b/docs/ConvertFrom-WmiDateTime.md new file mode 100644 index 0000000..6996310 --- /dev/null +++ b/docs/ConvertFrom-WmiDateTime.md @@ -0,0 +1,80 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# ConvertFrom-WmiDateTime + +## SYNOPSIS + +Converts a Wmi Time value to a datetime value + +## SYNTAX + +### __AllParameterSets + +``` +ConvertFrom-WmiDateTime [-WmiTime] [] +``` + +## DESCRIPTION + +This function will return the datetime based on a WMI datetime string. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +ConvertFrom-WmiDateTime -WmiTime '20190912173652.000000-300' +Gets datetime for the Wmi time 20190912173652.000000-300 +``` + + + + + + + + +## PARAMETERS + +### -WmiTime + +The WmiTime value to return the datetime for + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (All) False (None) +Position: 0 +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### The datetime value based on the wmi time + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/ConvertTo-UnixTime.md b/docs/ConvertTo-UnixTime.md new file mode 100644 index 0000000..5a26b6d --- /dev/null +++ b/docs/ConvertTo-UnixTime.md @@ -0,0 +1,94 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# ConvertTo-UnixTime + +## SYNOPSIS + +Converts a datetime value to Unix Time + +## SYNTAX + +### __AllParameterSets + +``` +ConvertTo-UnixTime [[-date ]] [] +``` + +## DESCRIPTION + +This function will return the unix time based on the unix epoch time. +If no date is passed in the current date and time is used. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +ConvertTo-UnixTime +Gets unix time for the current time +``` + + + + + + + +### Example 2: EXAMPLE 2 + +``` +ConvertTo-UnixTime -date "11/17/2017" +Gets unix time for a specific date +``` + + + + + + + + +## PARAMETERS + +### -date + +The datetime value to return the unix time for + +```yaml +Type: DateTime +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 0 +Default value: $(Get-Date) +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### The int32 value of the unix time + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/ConvertTo-WmiDateTime.md b/docs/ConvertTo-WmiDateTime.md new file mode 100644 index 0000000..c62ed1d --- /dev/null +++ b/docs/ConvertTo-WmiDateTime.md @@ -0,0 +1,79 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# ConvertTo-WmiDateTime + +## SYNOPSIS + +Converts a datetime value to a Wmi datetime string + +## SYNTAX + +### __AllParameterSets + +``` +ConvertTo-WmiDateTime [[-Date ]] [] +``` + +## DESCRIPTION + +This function will return the WMI datetime string based on a datetime passed. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +ConvertTo-WmiDateTime -Date '06/25/2019 16:17' +``` + +Return the WMI datetime string for the datetime of "06/25/2019 16:17" + + + + + + +## PARAMETERS + +### -Date + +{{ Fill Date Description }} + +```yaml +Type: DateTime +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 0 +Default value: (Get-Date) +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### The string value based on the datetime + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/Find-TimeZone.md b/docs/Find-TimeZone.md new file mode 100644 index 0000000..b74baaa --- /dev/null +++ b/docs/Find-TimeZone.md @@ -0,0 +1,163 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# Find-TimeZone + +## SYNOPSIS + +Returns Time Zone information + +## SYNTAX + +### __AllParameterSets + +``` +Find-TimeZone [[-Name ]] [[-Offset ]] [-Local] [-OutGrid] [] +``` + +## DESCRIPTION + +This function will return the information for the system time zones. +You can search by name and/or hour offsets. +You can also return the local time zone. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +Find-TimeZone -local +Return the time zone of the local system +``` + + + + + + + +### Example 2: EXAMPLE 2 + +``` +Find-TimeZone -Name "GMT" +Search for time zones with 'GMT' in the name +``` + + + + + + + +### Example 3: EXAMPLE 3 + +``` +Find-TimeZone -Name "central" -Offset -6 +Search for time zones with 'Central' in the name and have a UTC offset of -6 hours +``` + + + + + + + + +## PARAMETERS + +### -Local + +Use to return the time zone of the current system + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Name + +All or part of the time zone name. +Will be used to perform a wildcard search on the time zones + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 0 +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Offset + +The number of hours the time zone is offset from UTC + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 1 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -OutGrid + +{{ Fill OutGrid Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### The TimeZoneInfo value or values found + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/Get-CronNextOccurrence.md b/docs/Get-CronNextOccurrence.md new file mode 100644 index 0000000..71ebf6c --- /dev/null +++ b/docs/Get-CronNextOccurrence.md @@ -0,0 +1,142 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# Get-CronNextOccurrence + +## SYNOPSIS + +Get the next occurrence for a crontab + +## SYNTAX + +### __AllParameterSets + +``` +Get-CronNextOccurrence [-Crontab] [[-StartTime ]] [[-EndTime ]] [] +``` + +## DESCRIPTION + +This function will either return the next occurrence, or if an end date is supplied, it will return +all the occurrences between the start and end date. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +Get-CronNextOccurrence -Crontab '0 17 * * *' +``` + +Will return the next occurrence of the crontab from the current time + + + + + +### Example 2: EXAMPLE 2 + +``` +$Date = Get-Date '12/14/2032' +Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date +``` + +Will return the next occurrence of the crontab from the time provided + + + + + +### Example 3: EXAMPLE 3 + +``` +Get-CronNextOccurrence -Crontab '0 17 * * *' -StartTime $Date -EndTime $Date.AddDays(3) +``` + +Will return the all occurrences of the crontab between the two times + + + + + + +## PARAMETERS + +### -Crontab + +A valid crontab string + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (All) False (None) +Position: 0 +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -EndTime + +The datetime object to stop finding occurrences for from the StartTime + +```yaml +Type: DateTime +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 2 +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -StartTime + +The datetime object to find the next occurrence from. +Uses current time if not supplied. + +```yaml +Type: DateTime +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 1 +Default value: (Get-Date) +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### A datetime object for every occurrence returned + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/Get-DateExtended.md b/docs/Get-DateExtended.md new file mode 100644 index 0000000..d3b3c19 --- /dev/null +++ b/docs/Get-DateExtended.md @@ -0,0 +1,266 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# Get-DateExtended + +## SYNOPSIS + +Gets common extended date values that are not included by default with the Get-Date cmdlet + +## SYNTAX + +### __AllParameterSets + +``` +Get-DateExtended [[-Date ]] [-Day ] [-DisplayHint ] [-FromUnixTime] [-Hour ] [-Millisecond ] [-Minute ] [-Month ] [-Second ] [-Year ] [] +``` + +## DESCRIPTION + +This function includes added values for: + FirstDayOfYear : First day of the year + LastDayOfYear : Last day of the year + StartOfWeek : First day of the week + EndOfWeek : Last day of the week + StartOfMonth : First day of the month + EndOfMonth : Last day of the month + TimeZone : Current machine timezone + Quater : The quarter of the year. + +All dates are based on the date passed. +If no date is passed in the current date and time are used. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +Get-DateExtended +Gets extended date and time information based on the current time +``` + + + + + + + +### Example 2: EXAMPLE 2 + +``` +Get-DateExtended "11/17/2017" +Gets extended date and time information for a specific date +``` + + + + + + + + +## PARAMETERS + +### -Date + +The datetime value to return the information for + +```yaml +Type: DateTime +Parameter Sets: (All) +Aliases: LastWriteTime +Accepted values: + +Required: True (None) False (All) +Position: 0 +Default value: [DateTime]::Now +Accept pipeline input: True +Accept wildcard characters: False +DontShow: False +``` + +### -Day + +{{ Fill Day Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -DisplayHint + +{{ Fill DisplayHint Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -FromUnixTime + +{{ Fill FromUnixTime Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Hour + +{{ Fill Hour Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Millisecond + +{{ Fill Millisecond Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Minute + +{{ Fill Minute Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Month + +{{ Fill Month Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Second + +{{ Fill Second Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Year + +{{ Fill Year Description }} + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### A PSObject containing extended values for the date. + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/Get-DateFormat.md b/docs/Get-DateFormat.md new file mode 100644 index 0000000..a97ef36 --- /dev/null +++ b/docs/Get-DateFormat.md @@ -0,0 +1,78 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# Get-DateFormat + +## SYNOPSIS + +{{ Fill in the Synopsis }} + +## SYNTAX + +### __AllParameterSets + +``` +Get-DateFormat [[-Date ]] [] +``` + +## DESCRIPTION + +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1: Example 1 + +``` +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -Date + +{{ Fill Date Description }} + +```yaml +Type: DateTime +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 0 +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + + + ## OUTPUTS + +### System.Object + + + ## NOTES + +{{ Fill in the Notes }} + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/Get-Easter.md b/docs/Get-Easter.md new file mode 100644 index 0000000..8dee14d --- /dev/null +++ b/docs/Get-Easter.md @@ -0,0 +1,99 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# Get-Easter + +## SYNOPSIS + +This function offers a generic Easter computing method for any given year, using Western, Orthodox or Julian algorithms. + +## SYNTAX + +### __AllParameterSets + +``` +Get-Easter [[-year ]] [[-Calendar ]] [] +``` + +## DESCRIPTION + +Shamelessly stolen from python dateutil (https://github.com/dateutil/dateutil/blob/master/src/dateutil/easter.py) + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +Get-Easter -Year 2024 +``` + + + + + + + + +## PARAMETERS + +### -Calendar + +Gregorian : is the default and valid from 1583 to 4099 +Orthodox : valid from 1583 to 4099 +Julian : valid from 326 + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 1 +Default value: Gregorian +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -year + +The year to get Easter from + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (None) False (All) +Position: 0 +Default value: (Get-Date).Year +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### System.DateTime + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/Get-PatchTuesday.md b/docs/Get-PatchTuesday.md new file mode 100644 index 0000000..f5aa849 --- /dev/null +++ b/docs/Get-PatchTuesday.md @@ -0,0 +1,163 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# Get-PatchTuesday + +## SYNOPSIS + +Returns the second Tuesday of the month + +## SYNTAX + +### Date (Default) + +``` +Get-PatchTuesday [-Date ] [] +``` + +### MonthYear + +``` +Get-PatchTuesday [-Month ] [-Year ] [] +``` + +## DESCRIPTION + +This function allow you to pass a date, or a month/year combination to find the second Tuesday (aka Patch Tuesday) of any month + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +Get-PatchTuesday +Returns the second Tuesday for the current month +``` + + + + + + + +### Example 2: EXAMPLE 2 + +``` +Get-PatchTuesday -Date "11/17/2021" +Returns the second Tuesday for November 2021 +``` + + + + + + + +### Example 3: EXAMPLE 3 + +``` +Get-PatchTuesday -Month 6 -Year 2020 +Returns the second Tuesday for June 2020 +``` + + + + + + + +### Example 4: EXAMPLE 4 + +``` +Get-PatchTuesday -Month 4 +Returns the second Tuesday for April of the current year +``` + + + + + + + + +## PARAMETERS + +### -Date + +The datetime value to return the second Tuesday for the month + +```yaml +Type: DateTime +Parameter Sets: Date +Aliases: +Accepted values: + +Required: True (None) False (Date) +Position: Named +Default value: $(Get-Date) +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Month + +The month to return the second Tuesday for. +Enter a value from 1 to 12. + +```yaml +Type: Int32 +Parameter Sets: MonthYear +Aliases: +Accepted values: + +Required: True (None) False (MonthYear) +Position: Named +Default value: $(Get-Date).Month +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Year + +The year to return the second Tuesday for. +Enter a value from 1 to 9999 + +```yaml +Type: Int32 +Parameter Sets: MonthYear +Aliases: +Accepted values: + +Required: True (None) False (MonthYear) +Position: Named +Default value: $(Get-Date).Year +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### A datetime object of the second Tuesday. + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/New-Duration.md b/docs/New-Duration.md new file mode 100644 index 0000000..6c76c25 --- /dev/null +++ b/docs/New-Duration.md @@ -0,0 +1,262 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# New-Duration + +## SYNOPSIS + +Calculates the time span between two dates and returns the duration in the ISO 8601 format + +## SYNTAX + +### datetime + +``` +New-Duration -End -Start [] +``` + +### numbers + +``` +New-Duration [-Days ] [-Hours ] [-Minutes ] [-Months ] [-Seconds ] [-Years ] [] +``` + +### week + +``` +New-Duration [-Weeks ] [] +``` + +## DESCRIPTION + +Calculates the timespan between two dates and returns the duration in the ISO 8601 format + +https://en.wikipedia.org/wiki/ISO_8601#Durations + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +New-Duration -Start '2/3/2023' -End (Get-Date) +``` + + + + + + + +### Example 2: EXAMPLE 2 + +``` +New-Duration -Days 1 -Hours 4 +``` + + + + + + + +### Example 3: EXAMPLE 3 + +``` +New-Duration -Weeks 3 +``` + + + + + + + + +## PARAMETERS + +### -Days + +{{ Fill Days Description }} + +```yaml +Type: Int32 +Parameter Sets: numbers +Aliases: +Accepted values: + +Required: True (None) False (numbers) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -End + +Specifies the end of a time span. +End date must be greater than the start date + +```yaml +Type: DateTime +Parameter Sets: datetime +Aliases: +Accepted values: + +Required: True (datetime) False (None) +Position: Named +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Hours + +{{ Fill Hours Description }} + +```yaml +Type: Int32 +Parameter Sets: numbers +Aliases: +Accepted values: + +Required: True (None) False (numbers) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Minutes + +{{ Fill Minutes Description }} + +```yaml +Type: Int32 +Parameter Sets: numbers +Aliases: +Accepted values: + +Required: True (None) False (numbers) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Months + +{{ Fill Months Description }} + +```yaml +Type: Int32 +Parameter Sets: numbers +Aliases: +Accepted values: + +Required: True (None) False (numbers) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Seconds + +{{ Fill Seconds Description }} + +```yaml +Type: Int32 +Parameter Sets: numbers +Aliases: +Accepted values: + +Required: True (None) False (numbers) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Start + +Specifies the start of a time span. + +```yaml +Type: DateTime +Parameter Sets: datetime +Aliases: +Accepted values: + +Required: True (datetime) False (None) +Position: Named +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Weeks + +{{ Fill Weeks Description }} + +```yaml +Type: Int32 +Parameter Sets: week +Aliases: +Accepted values: + +Required: True (None) False (week) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + +### -Years + +{{ Fill Years Description }} + +```yaml +Type: Int32 +Parameter Sets: numbers +Aliases: +Accepted values: + +Required: True (None) False (numbers) +Position: Named +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### System.String + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/docs/Test-CrontabSchedule.md b/docs/Test-CrontabSchedule.md new file mode 100644 index 0000000..85fe24e --- /dev/null +++ b/docs/Test-CrontabSchedule.md @@ -0,0 +1,98 @@ +--- +external help file: PSDates-help.xml +Module Name: PSDates +online version: +schema: 2.0.0 +--- + +# Test-CrontabSchedule + +## SYNOPSIS + +Tests that a crontab string is valid + +## SYNTAX + +### __AllParameterSets + +``` +Test-CrontabSchedule [-Crontab] [] +``` + +## DESCRIPTION + +This function attempts to parse a crontab string to ensure it is valid. + + +## EXAMPLES + +### Example 1: EXAMPLE 1 + +``` +Test-CrontabSchedule -crontab '0 17 * * *' +``` + +Valid schedule that returns: + Crontab Valid + ------- ----- + 0 17 * * * True + + + + + +### Example 2: EXAMPLE 2 + +``` +Test-CrontabSchedule -crontab '0 17 * 13 *' +``` + +Invalid schedule that returns: +Crontab Valid ErrorMsg +------- ----- -------- +0 17 * 13 * False 13 is higher than the maximum allowable value for the [Month] field. +Value must be between 1 and 12 (all inclusive). + + + + + + +## PARAMETERS + +### -Crontab + +The datetime value to return the second Tuesday for the month + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: + +Required: True (All) False (None) +Position: 0 +Default value: +Accept pipeline input: False +Accept wildcard characters: False +DontShow: False +``` + + +### CommonParameters + +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## OUTPUTS + +### A psobject that contains the crontable, a validation value, and any error messages returned + + + ## NOTES + + + +## RELATED LINKS + +Fill Related Links Here + diff --git a/test-build.ps1 b/test-build.ps1 new file mode 100644 index 0000000..30109f9 --- /dev/null +++ b/test-build.ps1 @@ -0,0 +1,5 @@ +$config = New-PesterConfiguration +$config.Output.Verbosity = 'Detailed' +$config.Run.Path = (Join-Path $PSScriptRoot 'Source\Test') +$config.Run.Throw = $true +Invoke-Pester -Configuration $config \ No newline at end of file