# SunCalc returning times for wrong day

**URL:** <https://discourse.julialang.org/t/suncalc-returning-times-for-wrong-day/134733>\
**Category:** General Usage\
**Created:** [December 25, 2025, 1:46pm UTC](https://discourse.julialang.org/t/suncalc-returning-times-for-wrong-day/134733 "2025-12-25T13:46:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)\
**Post date:** [December 25, 2025, 1:46pm UTC](https://discourse.julialang.org/t/suncalc-returning-times-for-wrong-day/134733/1 "2025-12-25T13:46:43Z")

</div>

Is my use of SunCalc below correct? It’s reporting sunrise/sunset for the day before I specified. Is it a timezone issue?

Many thanks.

```julia
julia> s=Date(2025,1,5)
2025-01-05

julia> lat,lon = (52.9335, -9.3441)
(52.9335, -9.3441)

julia> times = SunCalc.getTimes(s, lat, lon);

julia> sr,ss = times.sunrise,times.sunset
(DateTime("2025-01-04T08:50:53"), DateTime("2025-01-04T16:36:03"))

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [December 26, 2025, 12:50am UTC](https://discourse.julialang.org/t/suncalc-returning-times-for-wrong-day/134733/2 "2025-12-26T00:50:25Z")

</div>

I get 3pm yesterday for sunrise and 1am today for sunset, which is obviously ridiculous. This isn’t an issue with displays based on host system time zones, the internal UTC epoch millisecond count for the reported sunset time is actually ~15 hours before `now()`, which is almost my local sunset at time of writing. The original Javascript implementation gives me the correct times, though a brief search shows an [open Github issue #107](https://github.com/mourner/suncalc/issues/107) there about conditional off-by-one problems, so I encourage you to check that for your location.

To answer your first question, your usage is technically incorrect because you’re using an internal function instead of the documented API `getSunlightTimes` (ALWAYS check documentation for the specific library, no matter what it claims to be based on), but it was weird for the API to diverge like that from the reference Javascript implementation’s API to begin with and it gives the same wrong numbers for me anyway. You can open an issue on the SunCalc.jl Github repo about the wrong times, but it’s been over 2 years since the last release with no community interaction so I wouldn’t expect anything.

---

<div class="post-metadata">

**Author:** ![langestefan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/langestefan/32/207923_2.png) [@langestefan](https://discourse.julialang.org/u/langestefan)\
**Post date:** [January 5, 2026, 9:26pm UTC](https://discourse.julialang.org/t/suncalc-returning-times-for-wrong-day/134733/3 "2026-01-05T21:26:23Z")

</div>

Maybe you can give SolarPosition.jl v0.4.0 a try?

```julia
julia> using SolarPosition, Dates

julia> dt = Date(2025,1,5)
2025-01-05

julia> obs = Observer(52.9335, -9.3441)
Observer(latitude=52.9335°, longitude=-9.3441°, altitude=0.0m, horizon=0.0°)

julia> next_sunrise(obs, dt)
2025-01-05T08:49:14

julia> next_sunset(obs, dt)
2025-01-05T16:36:51

```

---

<div class="post-metadata">

**Author:** ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)\
**Post date:** [January 6, 2026, 8:46am UTC](https://discourse.julialang.org/t/suncalc-returning-times-for-wrong-day/134733/4 "2026-01-06T08:46:50Z")

</div>

Thank you! I definitely will 🙂

I had been following the discussion in a parallel thread so I’m delighted to read you’ve implemented this feature.

Thanks again.
