Coder Social home page Coder Social logo

Comments (1)

ceeK avatar ceeK commented on August 20, 2024

Hi Tal! Thanks for the report and including a test, super helpful! Apologies for the delay.

I've had a look at your test and as far as I can tell it seems to be working as expected, in that it always returns a UTC date that you have to format 🤔 maybe I am misunderstanding though. I've added a little debug code to the bottom of your test. Can you check my logic:

func testLateTimeCorrectReturnDate() {
        let lateTime = Date(timeIntervalSince1970: 1499130000) // Tuesday, 4 July 2017 01:00:00 UTC
        let city = cities.first(where: { $0.name == "Washington, D. C." })!
        
        let calendar: Calendar = {
            var calendar = Calendar.current
            calendar.timeZone = TimeZone(identifier: "EST")!
            return calendar
        }()
        
        guard let solar = Solar(for: lateTime, latitude: city.latitude, longitude: city.longitude) else {
            XCTFail("Cannot get solar")
            return
        }
        
        let sameDate = calendar.compare(lateTime, to: solar.sunset!, toGranularity: .day)
        
        XCTAssertTrue(sameDate == .orderedSame, "The sunset given \(solar.sunset!) is not same day as given date \(lateTime)")
        
        let dateFormatter = DateFormatter()
        dateFormatter.dateStyle = .full
        dateFormatter.timeStyle = .full
        dateFormatter.timeZone = TimeZone(identifier: "EST")!
        let string = dateFormatter.string(from: solar.sunset!)
        print("Date: \(string)")
    }

This outputs Date: Tuesday, July 4, 2017 at 7:36:56 PM GMT-05:00. I've had a look this reference website and can see that the local sunset is July 4th 8:36pm GMT-04:00 (EDT). This looks to me that it's producing the correct sunset date given the 1 hour DST difference between EST and EDT.

After running your pull request test and checking Solar's date, I get:
2017-07-04 00:37:07 +0000. The timezone here is UTC, so when we format this date to EST we actually get a date on 2017-07-03.

Tell me if I'm missing something! 🙈

from solar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.