function setSunlight(map, time) {
    const center = map.getCenter(),
        {sunrise, sunset} = SunCalc.getTimes(time, center.lat, center.lng),
        sunriseTime = sunrise.getTime(),
        sunsetTime = sunset.getTime(),
        {azimuth, altitude} = SunCalc.getPosition(time, center.lat, center.lng),
        sunAzimuth = 180 + azimuth * RADIAN_TO_DEGREE,
        sunAltitude = 90 - altitude * RADIAN_TO_DEGREE;
    let t, ambient, directional, sun;

    if (time >= sunriseTime - HOUR / 2 && time < sunriseTime) {
        // Night to sunrise
        const sunrisePosition = SunCalc.getPosition(sunriseTime, center.lat, center.lng);

        t = (time - sunriseTime) / (HOUR / 2) + 1;
        ambient = {
            r: lerp(0, 153, t),
            g: lerp(22, 179, t),
            b: lerp(56, 204, t),
            i: lerp(.5, .65, t)
        };
        directional = {
            r: 74,
            g: 74,
            b: 74,
            i: lerp(.5, .6, t),
            w: .5
        };
        sun = {
            azimuth: lerp(210, 180 + sunrisePosition.azimuth * RADIAN_TO_DEGREE, t),
            altitude: 20
        };
    } else if (time >= sunriseTime && time < sunriseTime + HOUR) {
        // Sunrise to day
        t = (time - sunriseTime) / HOUR;
        ambient = {
            r: lerp(153, 255, t),
            g: lerp(179, 255, t),
            b: lerp(204, 255, t),
            i: lerp(.65, .7, t)
        };
        directional = {
            r: lerp(254, 255, t),
            g: lerp(202, 255, t),
            b: lerp(139, 255, t),
            i: lerp(.6, .3, t),
            w: 1
        };
        sun = {
            azimuth: sunAzimuth,
            altitude: sunAltitude
        };
    } else if (time >= sunriseTime + HOUR && time < sunsetTime - HOUR) {
        // Day
        ambient = {
            r: 255,
            g: 255,
            b: 255,
            i: .7
        };
        directional = {
            r: 255,
            g: 255,
            b: 255,
            i: .3,
            w: 1
        };
        sun = {
            azimuth: sunAzimuth,
            altitude: sunAltitude
        };
    } else if (time >= sunsetTime - HOUR && time < sunsetTime) {
        // Day to sunset
        t = (time - sunsetTime) / HOUR + 1;
        ambient = {
            r: lerp(255, 204, t),
            g: lerp(255, 179, t),
            b: lerp(255, 153, t),
            i: lerp(.7, .65, t)
        };
        directional = {
            r: lerp(255, 254, t),
            g: lerp(255, 194, t),
            b: lerp(255, 134, t),
            i: lerp(.3, .6, t),
            w: 1
        };
        sun = {
            azimuth: sunAzimuth,
            altitude: sunAltitude
        };
    } else if (time >= sunsetTime && time < sunsetTime + HOUR / 2) {
        // Sunset to night
        const sunsetPosition = SunCalc.getPosition(sunsetTime, center.lat, center.lng);

        t = (time - sunsetTime) / (HOUR / 2);
        ambient = {
            r: lerp(204, 0, t),
            g: lerp(179, 22, t),
            b: lerp(153, 56, t),
            i: lerp(.65, .5, t)
        };
        directional = {
            r: 74,
            g: 74,
            b: 74,
            i: lerp(.6, .5, t),
            w: .5
        };
        sun = {
            azimuth: lerp(180 + sunsetPosition.azimuth * RADIAN_TO_DEGREE, 210, t),
            altitude: 20
        };
    } else {
        // Night
        ambient = {
            r: 0,
            g: 22,
            b: 56,
            i: .5
        };
        directional = {
            r: 74,
            g: 74,
            b: 74,
            i: .5,
            w: .5
        };
        sun = {
            azimuth: 210,
            altitude: 20
        };
    }

    map.setLights([{
        id: 'ambient',
        type: 'ambient',
        properties: {
            color: `rgb(${ambient.r}, ${ambient.g}, ${ambient.b})`,
            intensity: ambient.i
        }
    }, {
        id: 'directional',
        type: 'directional',
        properties: {
            direction: ['literal', [sun.azimuth, sun.altitude]],
            color: `rgb(${directional.r}, ${directional.g}, ${directional.b})`,
            intensity: directional.i,
            'cast-shadows': true,
            'shadow-intensity': directional.w
        }
    }]);

    map.setPaintProperty('sky', 'sky-atmosphere-sun', [sunAzimuth, sunAltitude]);
}
Sets the sunlight at a specific time to the map
@param {mapboxgl.Map} map - Mapbox's Map object
@param {number} time - The number of milliseconds elapsed since January 1,
    1970 00:00:00 UTC