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

Getting the day component of a DateInRegion always returned the day in UTC #785

Open
Bawenang opened this issue Aug 29, 2021 · 0 comments
Open

Comments

@Bawenang
Copy link

I was under the impression the DateInRegion.day will return the day of the date in a certain region. However, when I tried it, it always returned the day in UTC, similar to Date.day. I have a need to get the current local day in my unit test. In my test, I need to compare the current date to the date of the end of the day (approx. 23:59). Here's the code:

    func testCreate_FromAppointment_WithStartDateIsTomorrow_ShouldMapStartTimeCounterAccordingly() throws {
        let dateTomorrow = DateInRegion() + 1.days
        let startDateTomorrow = DateInRegion(
            year: dateTomorrow.year, month: dateTomorrow.month, day: dateTomorrow.day,
            hour: 0, minute: 1, second: 0,
            region: Region.current)
        let entity = Appointment.sample(startDate: startDateTomorrow)
        
        XCTAssertEqual("Tomorrow", AppointmentStartTimerContent.create(from: entity))
    }

This test works only 17 hours of the day. Because I am at UTC+7 TimeZone, It always fails at 17.00 UTC - 24.00 UTC because the dateTomorrow.day always returns today's day component.

Is this by design? If it is, it seems useless and can deceive the developers (like what I experienced myself). Is there another way for me to get the day component in a certain region?

Thanks.

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

No branches or pull requests

1 participant