Skip to content

getTimes off by a dayΒ #107

@ianvonseggern1

Description

@ianvonseggern1

I was doing some investigation of sunsets and I noticed something strange:

SunCalc.getTimes(new Date(2017, 6, 11), 40.7128, -74.0060).sunset
Mon Jul 10 2017 20:29:46 GMT-0400 (EDT)

SunCalc.getTimes(new Date(2017, 6, 11), 40.7128, -74.0060).sunsetStart
Mon Jul 10 2017 20:26:30 GMT-0400 (EDT)

I was expecting it to return the sunset times for July 11th.

A little more digging and I found

SunCalc.getTimes(new Date(2017, 4, 3, 0, 0), 40.7128, -74.0060).sunsetStart
Tue May 02 2017 19:51:05 GMT-0400 (EDT)

SunCalc.getTimes(new Date(2017, 3, 3, 0, 0), 40.7128, -74.0060).sunsetStart
Sun Apr 02 2017 19:19:46 GMT-0400 (EDT)

SunCalc.getTimes(new Date(2017, 2, 3, 0, 0), 40.7128, -74.0060).sunsetStart
Fri Mar 03 2017 17:47:52 GMT-0500 (EST)

SunCalc.getTimes(new Date(2017, 3, 3, 1, 0), 40.7128, -74.0060).sunsetStart
Mon Apr 03 2017 19:20:48 GMT-0400 (EDT)

It looks like during daylight savings time it interperpates midnight to be the prior day. A little more specifically I checked:

SunCalc.getTimes(new Date(2017, 2, 11, 0, 0), 40.7128, -74.0060).sunsetStart
Sat Mar 11 2017 17:56:41 GMT-0500 (EST)

SunCalc.getTimes(new Date(2017, 2, 13, 0, 0), 40.7128, -74.0060).sunsetStart
Sun Mar 12 2017 18:57:46 GMT-0400 (EDT)

SunCalc.getTimes(new Date(2017, 10, 5, 0, 0), 40.7128, -74.0060).sunsetStart
Sat Nov 04 2017 17:47:23 GMT-0400 (EDT)

SunCalc.getTimes(new Date(2017, 10, 7, 0, 0), 40.7128, -74.0060).sunsetStart
Tue Nov 07 2017 16:44:06 GMT-0500 (EST)

I figured adding an hour would fix it and it did, but strangely the cut off seems to be 58 minutes:

SunCalc.getTimes(new Date(2017, 3, 3, 0, 57), 40.7128, -74.0060).sunsetStart
Sun Apr 02 2017 19:19:46 GMT-0400 (EDT)

SunCalc.getTimes(new Date(2017, 3, 3, 0, 58), 40.7128, -74.0060).sunsetStart
Mon Apr 03 2017 19:20:48 GMT-0400 (EDT)

SunCalc.getTimes(new Date(2017, 7, 3, 0, 57), 40.7128, -74.0060).sunsetStart
Wed Aug 02 2017 20:08:51 GMT-0400 (EDT)

SunCalc.getTimes(new Date(2017, 7, 3, 0, 58), 40.7128, -74.0060).sunsetStart
Thu Aug 03 2017 20:07:45 GMT-0400 (EDT)

Anyway, as a decent workaround I can just use noon on the day I'm curious about, but I think in general people probably assume Date without hours or minutes would work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions