From 5f07d7df02954bc47048e6b4f423c1681fdeee8c Mon Sep 17 00:00:00 2001 From: "Michael J. Roberts" Date: Mon, 20 Jun 2022 20:11:17 +0100 Subject: [PATCH] fix: Ensure GetObjectRiseObjectSetTimesInUTCForDay returns correct transit with datetime offsets. fix: Ensure GetObjectRiseObjectSetTimesInUTCForDay returns correct transit with datetime offsets (normalize to time.UTC midnight for datetime provided). Includes associated test suite addition for expected output. --- coverage.txt | 168 ++++++++++++++++++++++---------------------- pkg/dusk/transit.go | 8 ++- 2 files changed, 89 insertions(+), 87 deletions(-) diff --git a/coverage.txt b/coverage.txt index 5eb9b3c..a6c4036 100644 --- a/coverage.txt +++ b/coverage.txt @@ -1,6 +1,90 @@ mode: atomic +github.com/observerly/dusk/pkg/dusk/astrometry.go:14.52,18.12 2 16490 +github.com/observerly/dusk/pkg/dusk/astrometry.go:22.2,22.11 1 16490 +github.com/observerly/dusk/pkg/dusk/astrometry.go:18.12,20.3 1 3388 +github.com/observerly/dusk/pkg/dusk/astrometry.go:34.73,42.2 4 4 github.com/observerly/dusk/pkg/dusk/coordinates.go:101.108,124.2 10 12982 github.com/observerly/dusk/pkg/dusk/coordinates.go:136.149,151.2 6 16488 +github.com/observerly/dusk/pkg/dusk/lawrence.go:15.59,24.12 3 3 +github.com/observerly/dusk/pkg/dusk/lawrence.go:28.2,28.11 1 3 +github.com/observerly/dusk/pkg/dusk/lawrence.go:24.12,26.3 1 0 +github.com/observerly/dusk/pkg/dusk/lawrence.go:37.62,50.11 5 12991 +github.com/observerly/dusk/pkg/dusk/lawrence.go:54.2,54.10 1 12991 +github.com/observerly/dusk/pkg/dusk/lawrence.go:50.11,52.3 1 12991 +github.com/observerly/dusk/pkg/dusk/lawrence.go:64.78,80.11 7 12980 +github.com/observerly/dusk/pkg/dusk/lawrence.go:85.2,92.3 3 12980 +github.com/observerly/dusk/pkg/dusk/lawrence.go:80.11,82.3 1 4328 +github.com/observerly/dusk/pkg/dusk/lawrence.go:101.82,111.12 5 0 +github.com/observerly/dusk/pkg/dusk/lawrence.go:116.2,121.3 2 0 +github.com/observerly/dusk/pkg/dusk/lawrence.go:111.12,113.3 1 0 +github.com/observerly/dusk/pkg/dusk/lawrence.go:130.62,144.2 5 25984 +github.com/observerly/dusk/pkg/dusk/lawrence.go:152.58,160.2 3 12996 +github.com/observerly/dusk/pkg/dusk/lawrence.go:170.70,178.14 3 12995 +github.com/observerly/dusk/pkg/dusk/lawrence.go:182.2,182.11 1 12995 +github.com/observerly/dusk/pkg/dusk/lawrence.go:178.14,180.3 1 0 +github.com/observerly/dusk/pkg/dusk/solar.go:23.45,26.2 1 42 +github.com/observerly/dusk/pkg/dusk/solar.go:35.50,38.2 1 32 +github.com/observerly/dusk/pkg/dusk/solar.go:47.62,50.2 1 31 +github.com/observerly/dusk/pkg/dusk/solar.go:60.74,62.2 1 27 +github.com/observerly/dusk/pkg/dusk/solar.go:73.46,75.2 1 28 +github.com/observerly/dusk/pkg/dusk/solar.go:83.47,88.11 2 12990 +github.com/observerly/dusk/pkg/dusk/solar.go:92.2,92.10 1 12990 +github.com/observerly/dusk/pkg/dusk/solar.go:88.11,90.3 1 10 +github.com/observerly/dusk/pkg/dusk/solar.go:108.110,114.2 2 27 +github.com/observerly/dusk/pkg/dusk/solar.go:125.146,133.16 4 3 +github.com/observerly/dusk/pkg/dusk/solar.go:137.2,141.8 1 3 +github.com/observerly/dusk/pkg/dusk/solar.go:133.16,135.3 1 0 +github.com/observerly/dusk/pkg/dusk/solar.go:153.142,181.2 12 26 +github.com/observerly/dusk/pkg/dusk/solar.go:189.70,200.2 4 4 +github.com/observerly/dusk/pkg/dusk/solar.go:208.74,222.12 6 2 +github.com/observerly/dusk/pkg/dusk/solar.go:226.2,229.3 1 2 +github.com/observerly/dusk/pkg/dusk/solar.go:222.12,224.3 1 2 +github.com/observerly/dusk/pkg/dusk/transit.go:23.77,31.2 3 31 +github.com/observerly/dusk/pkg/dusk/transit.go:42.135,43.43 1 12 +github.com/observerly/dusk/pkg/dusk/transit.go:51.2,77.3 10 12 +github.com/observerly/dusk/pkg/dusk/transit.go:43.43,49.3 1 0 +github.com/observerly/dusk/pkg/dusk/transit.go:89.164,98.16 4 1 +github.com/observerly/dusk/pkg/dusk/transit.go:102.2,107.39 3 1 +github.com/observerly/dusk/pkg/dusk/transit.go:131.2,131.43 1 1 +github.com/observerly/dusk/pkg/dusk/transit.go:98.16,100.3 1 0 +github.com/observerly/dusk/pkg/dusk/transit.go:107.39,110.12 2 1442 +github.com/observerly/dusk/pkg/dusk/transit.go:128.3,128.25 1 1442 +github.com/observerly/dusk/pkg/dusk/transit.go:110.12,118.4 1 1441 +github.com/observerly/dusk/pkg/dusk/transit.go:118.9,126.4 1 1 +github.com/observerly/dusk/pkg/dusk/transit.go:143.129,144.43 1 7 +github.com/observerly/dusk/pkg/dusk/transit.go:152.2,155.62 2 6 +github.com/observerly/dusk/pkg/dusk/transit.go:160.2,164.3 1 6 +github.com/observerly/dusk/pkg/dusk/transit.go:144.43,150.3 1 1 +github.com/observerly/dusk/pkg/dusk/transit.go:155.62,158.3 2 6 +github.com/observerly/dusk/pkg/dusk/transit.go:176.134,177.43 1 8 +github.com/observerly/dusk/pkg/dusk/transit.go:186.2,191.16 3 5 +github.com/observerly/dusk/pkg/dusk/transit.go:195.2,205.8 4 5 +github.com/observerly/dusk/pkg/dusk/transit.go:177.43,183.3 1 3 +github.com/observerly/dusk/pkg/dusk/transit.go:191.16,193.3 1 0 +github.com/observerly/dusk/pkg/dusk/transit.go:217.135,220.16 2 2 +github.com/observerly/dusk/pkg/dusk/transit.go:224.2,224.47 1 2 +github.com/observerly/dusk/pkg/dusk/transit.go:229.2,238.39 5 1 +github.com/observerly/dusk/pkg/dusk/transit.go:257.2,257.20 1 1 +github.com/observerly/dusk/pkg/dusk/transit.go:220.16,222.3 1 0 +github.com/observerly/dusk/pkg/dusk/transit.go:224.47,226.3 1 1 +github.com/observerly/dusk/pkg/dusk/transit.go:238.39,251.91 4 424 +github.com/observerly/dusk/pkg/dusk/transit.go:251.91,253.9 2 1 +github.com/observerly/dusk/pkg/dusk/transit.go:269.123,272.16 2 3 +github.com/observerly/dusk/pkg/dusk/transit.go:276.2,276.47 1 3 +github.com/observerly/dusk/pkg/dusk/transit.go:286.2,293.39 4 2 +github.com/observerly/dusk/pkg/dusk/transit.go:311.2,316.8 1 2 +github.com/observerly/dusk/pkg/dusk/transit.go:272.16,274.3 1 0 +github.com/observerly/dusk/pkg/dusk/transit.go:276.47,283.3 1 1 +github.com/observerly/dusk/pkg/dusk/transit.go:293.39,306.91 4 1639 +github.com/observerly/dusk/pkg/dusk/transit.go:306.91,308.4 1 464 +github.com/observerly/dusk/pkg/dusk/trigonometry.go:10.30,12.2 1 291239 +github.com/observerly/dusk/pkg/dusk/trigonometry.go:14.30,16.2 1 212437 +github.com/observerly/dusk/pkg/dusk/trigonometry.go:18.44,20.2 1 541 +github.com/observerly/dusk/pkg/dusk/trigonometry.go:22.30,24.2 1 13105 +github.com/observerly/dusk/pkg/dusk/trigonometry.go:26.31,28.2 1 42489 +github.com/observerly/dusk/pkg/dusk/trigonometry.go:30.31,32.2 1 16543 +github.com/observerly/dusk/pkg/dusk/trigonometry.go:34.31,36.2 1 1 +github.com/observerly/dusk/pkg/dusk/trigonometry.go:38.36,40.2 1 25976 github.com/observerly/dusk/pkg/dusk/epoch.go:31.56,33.2 1 26 github.com/observerly/dusk/pkg/dusk/epoch.go:41.48,46.2 2 124040 github.com/observerly/dusk/pkg/dusk/epoch.go:53.45,55.2 1 79 @@ -31,23 +115,6 @@ github.com/observerly/dusk/pkg/dusk/epoch.go:328.2,328.21 1 25 github.com/observerly/dusk/pkg/dusk/epoch.go:312.12,314.3 1 25 github.com/observerly/dusk/pkg/dusk/epoch.go:317.13,319.3 1 0 github.com/observerly/dusk/pkg/dusk/epoch.go:324.11,326.3 1 1 -github.com/observerly/dusk/pkg/dusk/lawrence.go:15.59,24.12 3 3 -github.com/observerly/dusk/pkg/dusk/lawrence.go:28.2,28.11 1 3 -github.com/observerly/dusk/pkg/dusk/lawrence.go:24.12,26.3 1 0 -github.com/observerly/dusk/pkg/dusk/lawrence.go:37.62,50.11 5 12991 -github.com/observerly/dusk/pkg/dusk/lawrence.go:54.2,54.10 1 12991 -github.com/observerly/dusk/pkg/dusk/lawrence.go:50.11,52.3 1 12991 -github.com/observerly/dusk/pkg/dusk/lawrence.go:64.78,80.11 7 12980 -github.com/observerly/dusk/pkg/dusk/lawrence.go:85.2,92.3 3 12980 -github.com/observerly/dusk/pkg/dusk/lawrence.go:80.11,82.3 1 4328 -github.com/observerly/dusk/pkg/dusk/lawrence.go:101.82,111.12 5 0 -github.com/observerly/dusk/pkg/dusk/lawrence.go:116.2,121.3 2 0 -github.com/observerly/dusk/pkg/dusk/lawrence.go:111.12,113.3 1 0 -github.com/observerly/dusk/pkg/dusk/lawrence.go:130.62,144.2 5 25984 -github.com/observerly/dusk/pkg/dusk/lawrence.go:152.58,160.2 3 12996 -github.com/observerly/dusk/pkg/dusk/lawrence.go:170.70,178.14 3 12995 -github.com/observerly/dusk/pkg/dusk/lawrence.go:182.2,182.11 1 12995 -github.com/observerly/dusk/pkg/dusk/lawrence.go:178.14,180.3 1 0 github.com/observerly/dusk/pkg/dusk/lunar.go:32.47,37.11 2 13006 github.com/observerly/dusk/pkg/dusk/lunar.go:41.2,41.10 1 13006 github.com/observerly/dusk/pkg/dusk/lunar.go:37.11,39.3 1 16 @@ -126,73 +193,6 @@ github.com/observerly/dusk/pkg/dusk/lunar.go:855.30,857.4 1 4 github.com/observerly/dusk/pkg/dusk/lunar.go:874.106,877.16 2 2 github.com/observerly/dusk/pkg/dusk/lunar.go:881.2,884.8 1 2 github.com/observerly/dusk/pkg/dusk/lunar.go:877.16,879.3 1 0 -github.com/observerly/dusk/pkg/dusk/transit.go:23.77,31.2 3 31 -github.com/observerly/dusk/pkg/dusk/transit.go:42.135,43.43 1 12 -github.com/observerly/dusk/pkg/dusk/transit.go:52.2,75.3 9 12 -github.com/observerly/dusk/pkg/dusk/transit.go:43.43,49.3 1 0 -github.com/observerly/dusk/pkg/dusk/transit.go:87.164,96.16 4 1 -github.com/observerly/dusk/pkg/dusk/transit.go:100.2,105.39 3 1 -github.com/observerly/dusk/pkg/dusk/transit.go:129.2,129.43 1 1 -github.com/observerly/dusk/pkg/dusk/transit.go:96.16,98.3 1 0 -github.com/observerly/dusk/pkg/dusk/transit.go:105.39,108.12 2 1442 -github.com/observerly/dusk/pkg/dusk/transit.go:126.3,126.25 1 1442 -github.com/observerly/dusk/pkg/dusk/transit.go:108.12,116.4 1 1441 -github.com/observerly/dusk/pkg/dusk/transit.go:116.9,124.4 1 1 -github.com/observerly/dusk/pkg/dusk/transit.go:141.129,142.43 1 7 -github.com/observerly/dusk/pkg/dusk/transit.go:150.2,153.62 2 6 -github.com/observerly/dusk/pkg/dusk/transit.go:158.2,162.3 1 6 -github.com/observerly/dusk/pkg/dusk/transit.go:142.43,148.3 1 1 -github.com/observerly/dusk/pkg/dusk/transit.go:153.62,156.3 2 6 -github.com/observerly/dusk/pkg/dusk/transit.go:174.134,175.43 1 8 -github.com/observerly/dusk/pkg/dusk/transit.go:184.2,189.16 3 5 -github.com/observerly/dusk/pkg/dusk/transit.go:193.2,203.8 4 5 -github.com/observerly/dusk/pkg/dusk/transit.go:175.43,181.3 1 3 -github.com/observerly/dusk/pkg/dusk/transit.go:189.16,191.3 1 0 -github.com/observerly/dusk/pkg/dusk/transit.go:215.135,218.16 2 2 -github.com/observerly/dusk/pkg/dusk/transit.go:222.2,222.47 1 2 -github.com/observerly/dusk/pkg/dusk/transit.go:227.2,236.39 5 1 -github.com/observerly/dusk/pkg/dusk/transit.go:255.2,255.20 1 1 -github.com/observerly/dusk/pkg/dusk/transit.go:218.16,220.3 1 0 -github.com/observerly/dusk/pkg/dusk/transit.go:222.47,224.3 1 1 -github.com/observerly/dusk/pkg/dusk/transit.go:236.39,249.91 4 424 -github.com/observerly/dusk/pkg/dusk/transit.go:249.91,251.9 2 1 -github.com/observerly/dusk/pkg/dusk/transit.go:267.123,270.16 2 3 -github.com/observerly/dusk/pkg/dusk/transit.go:274.2,274.47 1 3 -github.com/observerly/dusk/pkg/dusk/transit.go:284.2,291.39 4 2 -github.com/observerly/dusk/pkg/dusk/transit.go:309.2,314.8 1 2 -github.com/observerly/dusk/pkg/dusk/transit.go:270.16,272.3 1 0 -github.com/observerly/dusk/pkg/dusk/transit.go:274.47,281.3 1 1 -github.com/observerly/dusk/pkg/dusk/transit.go:291.39,304.91 4 1639 -github.com/observerly/dusk/pkg/dusk/transit.go:304.91,306.4 1 464 -github.com/observerly/dusk/pkg/dusk/astrometry.go:14.52,18.12 2 16490 -github.com/observerly/dusk/pkg/dusk/astrometry.go:22.2,22.11 1 16490 -github.com/observerly/dusk/pkg/dusk/astrometry.go:18.12,20.3 1 3388 -github.com/observerly/dusk/pkg/dusk/astrometry.go:34.73,42.2 4 4 -github.com/observerly/dusk/pkg/dusk/solar.go:23.45,26.2 1 42 -github.com/observerly/dusk/pkg/dusk/solar.go:35.50,38.2 1 32 -github.com/observerly/dusk/pkg/dusk/solar.go:47.62,50.2 1 31 -github.com/observerly/dusk/pkg/dusk/solar.go:60.74,62.2 1 27 -github.com/observerly/dusk/pkg/dusk/solar.go:73.46,75.2 1 28 -github.com/observerly/dusk/pkg/dusk/solar.go:83.47,88.11 2 12990 -github.com/observerly/dusk/pkg/dusk/solar.go:92.2,92.10 1 12990 -github.com/observerly/dusk/pkg/dusk/solar.go:88.11,90.3 1 10 -github.com/observerly/dusk/pkg/dusk/solar.go:108.110,114.2 2 27 -github.com/observerly/dusk/pkg/dusk/solar.go:125.146,133.16 4 3 -github.com/observerly/dusk/pkg/dusk/solar.go:137.2,141.8 1 3 -github.com/observerly/dusk/pkg/dusk/solar.go:133.16,135.3 1 0 -github.com/observerly/dusk/pkg/dusk/solar.go:153.142,181.2 12 26 -github.com/observerly/dusk/pkg/dusk/solar.go:189.70,200.2 4 4 -github.com/observerly/dusk/pkg/dusk/solar.go:208.74,222.12 6 2 -github.com/observerly/dusk/pkg/dusk/solar.go:226.2,229.3 1 2 -github.com/observerly/dusk/pkg/dusk/solar.go:222.12,224.3 1 2 -github.com/observerly/dusk/pkg/dusk/trigonometry.go:10.30,12.2 1 291239 -github.com/observerly/dusk/pkg/dusk/trigonometry.go:14.30,16.2 1 212437 -github.com/observerly/dusk/pkg/dusk/trigonometry.go:18.44,20.2 1 541 -github.com/observerly/dusk/pkg/dusk/trigonometry.go:22.30,24.2 1 13105 -github.com/observerly/dusk/pkg/dusk/trigonometry.go:26.31,28.2 1 42489 -github.com/observerly/dusk/pkg/dusk/trigonometry.go:30.31,32.2 1 16543 -github.com/observerly/dusk/pkg/dusk/trigonometry.go:34.31,36.2 1 1 -github.com/observerly/dusk/pkg/dusk/trigonometry.go:38.36,40.2 1 25976 github.com/observerly/dusk/pkg/dusk/twilight.go:38.163,49.16 5 9 github.com/observerly/dusk/pkg/dusk/twilight.go:53.2,57.18 1 9 github.com/observerly/dusk/pkg/dusk/twilight.go:49.16,51.3 1 0 diff --git a/pkg/dusk/transit.go b/pkg/dusk/transit.go index 7958e3f..9e64cef 100644 --- a/pkg/dusk/transit.go +++ b/pkg/dusk/transit.go @@ -48,6 +48,8 @@ func GetObjectRiseObjectSetTimesInUTCForDay(datetime time.Time, eq EquatorialCoo } } + var d = time.Date(datetime.Year(), datetime.Month(), datetime.Day(), 0, 0, 0, 0, time.UTC) + // see p.117 of Lawrence, J.L. 2015. Celestial Calculations - A Gentle Introduction To Computational Astronomy. Cambridge, Ma: The MIT Press LSTr := 24 + eq.RightAscension/15 - GetArgumentOfLocalSiderealTimeForTransit(latitude, eq.Declination)/15 @@ -56,17 +58,17 @@ func GetObjectRiseObjectSetTimesInUTCForDay(datetime time.Time, eq EquatorialCoo UTr := ConvertGreenwhichSiderealTimeToUniversalTime(datetime, GSTr) // for highest accuracy, convert hours to milliseconds to add: - rise := datetime.Add(time.Duration(UTr*3600000) * time.Millisecond) + rise := d.Add(time.Duration(UTr*3600000) * time.Millisecond) // see p.117 of Lawrence, J.L. 2015. Celestial Calculations - A Gentle Introduction To Computational Astronomy. Cambridge, Ma: The MIT Press LSTs := eq.RightAscension/15 + GetArgumentOfLocalSiderealTimeForTransit(latitude, eq.Declination)/15 GSTs := ConvertLocalSiderealTimeToGreenwhichSiderealTime(LSTs, longitude) - UTs := ConvertGreenwhichSiderealTimeToUniversalTime(datetime, GSTs) + UTs := ConvertGreenwhichSiderealTimeToUniversalTime(d, GSTs) // for highest accuracy, convert hours to milliseconds to add: - set := datetime.Add(time.Duration(UTs*3600000) * time.Millisecond) + set := d.Add(time.Duration(UTs*3600000) * time.Millisecond) return Transit{ Rise: &rise,