Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sunrise and Sunset dates off by 1 day. #40

Open
neilt opened this issue May 3, 2019 · 3 comments · May be fixed by #48
Open

Sunrise and Sunset dates off by 1 day. #40

neilt opened this issue May 3, 2019 · 3 comments · May be fixed by #48

Comments

@neilt
Copy link

neilt commented May 3, 2019

It seems that the dates are 1 day in the future if the local time is the next day UTC.

Not sure if this is the same problem as reported in #24?

Here is a complete test. Note that the reported times are one day in the future from the correct times.

    ///    Sun and Moon Data for One Day
    ///
    ///    U.S. Naval Observatory
    ///    Astronomical Applications Department
    ///
    ///    (Longitude W 94° 0', Latitude N 39° 0')
    ///
    ///    Friday, May 3, 2019    Universal Time - 5h
    ///    Sun
    ///    Begin civil twilight    05:47
    ///    Sunrise    06:16
    ///    Sun transit    13:13
    ///    Sunset    20:11
    ///    End civil twilight    20:40
    ///    Moon
    ///    Moonrise    05:56
    ///    Moon transit    12:24
    ///    Moonset    19:00
    ///
    /// [https://aa.usno.navy.mil/data/docs/RS_OneDay.php](https://aa.usno.navy.mil/data/docs/RS_OneDay.php)
    func testPlainLatLon() {
        var tdf: DateFormatter = {
            let df = DateFormatter()
            df.dateFormat = "MM/dd/yyyy HH:mm zzz"
            return df
        }()
        let testCriticalEvening = tdf.date(from: "05/03/2019 19:20 CDT")!
        let testLocation: CLLocation = CLLocation(latitude: 39.00, longitude: -94.0)
        let expectedSunrise = "05/03/2019 06:16 CDT"
        let expectedSunset = "05/03/2019 20:11 CDT"
        let solar = Solar(for: testCriticalEvening, coordinate: testLocation.coordinate)

        XCTAssert(tdf.string(from: solar!.sunrise!) == expectedSunrise,
                  "Expected: \(expectedSunrise), Received: \(tdf.string(from: solar!.sunrise!))")
        XCTAssert(tdf.string(from: solar!.sunset!) == expectedSunset,
                  "Expected: \(expectedSunset), Received: \(tdf.string(from: solar!.sunset!))")
    }

The results of the test are:

UI Test Activity: 
Assertion Failure: Solar_iOSTests.swift:198: XCTAssertTrue failed - Expected: 05/03/2019 06:16 CDT, Received: 05/04/2019 06:14 CDT

UI Test Activity: 
Assertion Failure: Solar_iOSTests.swift:200: XCTAssertTrue failed - Expected: 05/03/2019 20:11 CDT, Received: 05/04/2019 20:11 CDT
@wbrannock
Copy link

I am also having this same issue

@neilt
Copy link
Author

neilt commented Jun 16, 2019

Yep, I ended up not using this lib because the API is IMO wrong to determine accurate local sunrise and sunset. The API needs to know the original time zone which corresponds to the lat and lon. This is not available using just a Date object.

I ended up converting http://stjarnhimlen.se/comp/sunriset.c to swift. It works like a charm.

I just added the converted code here https://gist.github.com/neilt/6bc284ac7ce00d566002bc45bc0d86dd

@dasmer
Copy link

dasmer commented Feb 26, 2022

Any updates on this issue?
It seems like @aaronfreimark's solution also has a bug and was not merged.

Was this issue ever fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants