@@ -40,19 +40,30 @@ Right click a specific point on the Google map and you will see the latitude and
40
40
#>
41
41
[CmdletBinding ()]
42
42
param (
43
+ [Parameter (Mandatory = $false )]
43
44
[datetime ]$Date = $ (Get-Date ),
45
+ [Parameter (Mandatory = $true )]
44
46
[double ]$Latitude ,
47
+ [Parameter (Mandatory = $true )]
45
48
[double ]$Longitude ,
49
+ [Parameter (Mandatory = $false )]
46
50
[double ]$Elevation = 0.0 ,
47
- [TimeZoneInfo ]$TimeZone = $null
51
+ [Parameter (Mandatory = $false )]
52
+ [string ]$TimeZone = $null
48
53
)
49
54
$suntime = [SunTime ]::new()
50
55
$datetimeOffset = [DateTimeOffset ]::new($Date )
51
56
$CurrentTimestamp = $datetimeOffset.ToUniversalTime ().ToUnixTimeSeconds()
52
57
58
+ $TimeZoneInfo = [System.TimeZoneInfo ]::Local
59
+ if (-not [string ]::IsNullOrEmpty($TimeZone )){
60
+ $TimeZoneInfo = [System.TimeZoneInfo ]::FindSystemTimeZoneById($TimeZone )
61
+ }
62
+
63
+
53
64
Write-Verbose " Latitude f = $ ( $suntime.ToDegreeString ($Latitude )) "
54
65
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 )) "
56
67
57
68
58
69
$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
83
94
84
95
# Solar transit (julian date)
85
96
$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 )) "
87
98
88
99
# Declination of the Sun
89
100
$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
100
111
$j_rise = $J_transit - $w0_degrees / 360
101
112
$j_set = $J_transit + $w0_degrees / 360
102
113
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 )) "
105
116
Write-Verbose (" Day length {0:N3} hours" -f ($w0_degrees / (180 / 24 )))
106
117
107
118
[SunTime ]@ {
@@ -116,9 +127,9 @@ Right click a specific point on the Google map and you will see the latitude and
116
127
EclipticLongitude = $L_degrees
117
128
SolarTransitTime = $J_transit
118
129
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 )))
121
132
DayLength = ($w0_degrees / (180 / 24 ))
122
- TimeZone = $TimeZone
133
+ TimeZone = $TimeZoneInfo
123
134
}
124
135
}
0 commit comments