Skip to content

Commit f9d6d43

Browse files
authored
Release v1.0.4 (#7)
* update publish script * FIx Time Zones in Get-SunTime
1 parent f822808 commit f9d6d43

File tree

4 files changed

+43
-50
lines changed

4 files changed

+43
-50
lines changed

Publish/PublishToPSGallery.ps1

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,29 @@
1+
<#
2+
Run build.ps1 first
3+
#>
4+
15
# Script variables
2-
$IncludeDirectories = 'Public','Resources'
3-
$ModulesFolder = (Split-Path $PSScriptRoot)
6+
$TopLevel = (Split-Path $PSScriptRoot)
47
$NugetAPIKey = Get-Content (Join-Path $PSScriptRoot 'APIKey.json')
58

6-
# Get the module manifest
7-
$psd1File = Get-ChildItem -path $ModulesFolder -Filter "*.psd1" | Select-Object -ExpandProperty FullName
8-
$psd1 = Test-ModuleManifest $psd1File
9-
10-
# Revise the new version
11-
$Revision = $psd1.Version.Revision + 1
12-
[System.Version]$newVersion = [System.Version]::new($psd1.Version.Major, $psd1.Version.Minor, $psd1.Version.MinorRevision, $Revision)
13-
14-
Write-Verbose "New version '$version'"
15-
16-
Update-ModuleManifest -Path $psd1File -ModuleVersion $newVersion
17-
18-
# create the release folder
19-
$releaseFolder = Join-Path $PSScriptRoot "\PSDates\$($newVersion.ToString())"
20-
If (-not(Test-Path $releaseFolder)){
21-
New-Item -type Directory -Path $releaseFolder | Out-Null
22-
}
23-
24-
# Copy files to release folder
25-
Get-ChildItem $ModulesFolder -Filter '*.ps*1' | Where-Object { $_.Name -notlike '*test*' } |
26-
Copy-Item -Destination $releaseFolder
27-
28-
[System.Collections.Generic.List[PSObject]]$DirectoriesToCopy = @()
29-
foreach($folder in $IncludeDirectories){
30-
$DirectoriesToCopy.Add($folder)
31-
Get-ChildItem -Path (Join-Path $ModulesFolder $folder) -Directory -Recurse | ForEach-Object {
32-
$DirectoriesToCopy.Add($_.FullName.Replace($ModulesFolder,''))
33-
}
34-
}
35-
36-
foreach($folder in $DirectoriesToCopy){
37-
$destFolder = Join-Path $releaseFolder $folder
38-
If (-not(Test-Path $destFolder)){
39-
New-Item -type Directory -Path $destFolder | Out-Null
40-
}
41-
42-
Get-ChildItem $modFolder -File | Copy-Item -Destination $destFolder
9+
Set-Location $TopLevel
10+
11+
$testResultsXML = Join-Path $TopLevel 'Build\testResults.xml'
12+
$config = New-PesterConfiguration
13+
$config.Run.Path = (Join-Path $TopLevel 'Source\Test')
14+
$config.TestResult.Enabled = $true
15+
$config.TestResult.OutputPath = $testResultsXML
16+
Invoke-Pester -Configuration $config
17+
[xml]$testResults = Get-Content -LiteralPath $testResultsXML -Raw
18+
if($testResults.'test-results'.'test-suite'.result -eq 'Failure'){
19+
$testResults.'test-results'.'test-suite'.results.'test-suite' | Select-Object Name, result
20+
throw "Failed Pester tests"
4321
}
4422

23+
# Get the module manifest
24+
$psd1File = Get-ChildItem -Path (Join-Path $TopLevel 'Build\PSDates') -Filter 'PSDates.psd1' -Recurse | Select-Object -Last 1
25+
$psd1 = Test-ModuleManifest $psd1File
26+
Read-Host "Publish version '$($psd1.Version)'"
4527

4628
# Publish to powershell gallery
47-
Publish-Module -Path $releaseFolder -NugetAPIKey $NugetAPIKey -Verbose
29+
Publish-Module -Path $psd1File.DirectoryName -NugetAPIKey $NugetAPIKey -Verbose

Source/PSDates.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = '.\PSDates.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.0.2'
15+
ModuleVersion = '1.0.4'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

Source/Public/Get-SunTime.ps1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,30 @@ Right click a specific point on the Google map and you will see the latitude and
4040
#>
4141
[CmdletBinding()]
4242
param (
43+
[Parameter(Mandatory = $false)]
4344
[datetime]$Date = $(Get-Date),
45+
[Parameter(Mandatory = $true)]
4446
[double]$Latitude,
47+
[Parameter(Mandatory = $true)]
4548
[double]$Longitude,
49+
[Parameter(Mandatory = $false)]
4650
[double]$Elevation = 0.0,
47-
[TimeZoneInfo]$TimeZone = $null
51+
[Parameter(Mandatory = $false)]
52+
[string]$TimeZone = $null
4853
)
4954
$suntime = [SunTime]::new()
5055
$datetimeOffset = [DateTimeOffset]::new($Date)
5156
$CurrentTimestamp = $datetimeOffset.ToUniversalTime().ToUnixTimeSeconds()
5257

58+
$TimeZoneInfo = [System.TimeZoneInfo]::Local
59+
if(-not [string]::IsNullOrEmpty($TimeZone)){
60+
$TimeZoneInfo = [System.TimeZoneInfo]::FindSystemTimeZoneById($TimeZone)
61+
}
62+
63+
5364
Write-Verbose "Latitude f = $($suntime.ToDegreeString($Latitude))"
5465
Write-Verbose "Longitude l_w = $($suntime.ToDegreeString($Longitude))"
55-
Write-Verbose "Now ts = $($suntime.FromTimestamp($CurrentTimestamp, $TimeZone))"
66+
Write-Verbose "Now ts = $($suntime.FromTimestamp($CurrentTimestamp, $TimeZoneInfo))"
5667

5768

5869
$J_date = $suntime.TimestampToJulian($CurrentTimestamp)
@@ -83,7 +94,7 @@ Right click a specific point on the Google map and you will see the latitude and
8394

8495
# Solar transit (julian date)
8596
$J_transit = 2451545.0 + $J_ + 0.0053 * [math]::Sin($M_radians) - 0.0069 * [math]::Sin(2 * $Lambda_radians)
86-
Write-Verbose "Solar transit time J_trans = $($suntime.FromTimestamp( $suntime.JulianToTimestamp($J_transit), $TimeZone))"
97+
Write-Verbose "Solar transit time J_trans = $($suntime.FromTimestamp( $suntime.JulianToTimestamp($J_transit), $TimeZoneInfo))"
8798

8899
# Declination of the Sun
89100
$sin_d = [math]::Sin($Lambda_radians) * [math]::Sin((23.4397 * ([math]::PI / 180)))
@@ -100,8 +111,8 @@ Right click a specific point on the Google map and you will see the latitude and
100111
$j_rise = $J_transit - $w0_degrees / 360
101112
$j_set = $J_transit + $w0_degrees / 360
102113

103-
Write-Verbose "Sunrise j_rise = $($suntime.FromTimestamp( $suntime.JulianToTimestamp($j_rise), $TimeZone))"
104-
Write-Verbose "Sunset j_set = $($suntime.JulianToTimestamp($j_rise)) = $($suntime.FromTimestamp($suntime.JulianToTimestamp($j_set), $TimeZone))"
114+
Write-Verbose "Sunrise j_rise = $($suntime.FromTimestamp( $suntime.JulianToTimestamp($j_rise), $TimeZoneInfo))"
115+
Write-Verbose "Sunset j_set = $($suntime.JulianToTimestamp($j_rise)) = $($suntime.FromTimestamp($suntime.JulianToTimestamp($j_set), $TimeZoneInfo))"
105116
Write-Verbose ("Day length {0:N3} hours" -f ($w0_degrees / (180 / 24)))
106117

107118
[SunTime]@{
@@ -116,9 +127,9 @@ Right click a specific point on the Google map and you will see the latitude and
116127
EclipticLongitude = $L_degrees
117128
SolarTransitTime = $J_transit
118129
HourAngle = $w0_degrees
119-
Sunrise = (Get-Date $($suntime.FromTimestamp($suntime.JulianToTimestamp($j_rise), $TimeZone)))
120-
Sunset = (Get-Date $($suntime.FromTimestamp($suntime.JulianToTimestamp($j_set), $TimeZone)))
130+
Sunrise = (Get-Date $($suntime.FromTimestamp($suntime.JulianToTimestamp($j_rise), $TimeZoneInfo)))
131+
Sunset = (Get-Date $($suntime.FromTimestamp($suntime.JulianToTimestamp($j_set), $TimeZoneInfo)))
121132
DayLength = ($w0_degrees / (180 / 24))
122-
TimeZone = $TimeZone
133+
TimeZone = $TimeZoneInfo
123134
}
124135
}

Source/Test/Public/Get-SunTime.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Describe 'Get-SunTime Tests' {
2323
@{Name = 'The Colosseum'; Latitude = 41.8902101; Longitude = 12.48736; Elevation = 0; Sunrise = '03:42'; Sunset = '18:49' }
2424
@{Name = 'Times Square'; Latitude = 40.7579747; Longitude = -73.9881175; Elevation = 0; Sunrise = '09:31'; Sunset = '00:31' }
2525
) {
26-
$TimeZone = [System.TimeZoneInfo]::Utc
26+
$TimeZone = [System.TimeZoneInfo]::Utc.Id
2727
$Date = Get-Date '2024-07-05'
2828
$CalculateSunTimesParam = @{
2929
Date = $Date

0 commit comments

Comments
 (0)