Browse Source

Fix dates that go beyond month/year end

master
Nathan Bergey 6 years ago
parent
commit
6b0c752a94
  1. 13
      src/render.js

13
src/render.js

@ -101,6 +101,7 @@ class Chart {
* Draw days to show time * Draw days to show time
*/ */
export function render_calendar(canvas, width, height, offset, data) { export function render_calendar(canvas, width, height, offset, data) {
const margin = { const margin = {
top: 0, top: 0,
left: leftMargin, left: leftMargin,
@ -120,7 +121,9 @@ export function render_calendar(canvas, width, height, offset, data) {
let days = [] let days = []
const year = data.beginTime.getFullYear() const year = data.beginTime.getFullYear()
const month = data.beginTime.getMonth() const month = data.beginTime.getMonth()
for (var day = data.beginTime.getDate(); day <= data.endTime.getDate(); day++) {
const n_days = Math.ceil((data.endTime- data.beginTime) / (1000 * 60 * 60 * 24))
for (var day = data.beginTime.getDate(); day <= (data.beginTime.getDate() + n_days); day++) {
const dayBegin = new Date(year, month, day, 0, 1, 0) const dayBegin = new Date(year, month, day, 0, 1, 0)
const noon = new Date(year, month, day, 12, 0, 0) const noon = new Date(year, month, day, 12, 0, 0)
noons.push(noon) noons.push(noon)
@ -183,7 +186,9 @@ export function render_nights(canvas, width, height, offset, data) {
const year = data.beginTime.getFullYear() const year = data.beginTime.getFullYear()
const month = data.beginTime.getMonth() const month = data.beginTime.getMonth()
for (var day = data.beginTime.getDate(); day <= data.endTime.getDate(); day++) {
const n_days = Math.ceil((data.endTime- data.beginTime) / (1000 * 60 * 60 * 24))
for (var day = data.beginTime.getDate(); day <= (data.beginTime.getDate() + n_days); day++) {
const midnight = new Date(year, month, day, 0, 0, 0) const midnight = new Date(year, month, day, 0, 0, 0)
const sunEphem = SunCalc.getTimes(new Date(year, month, day, 12, 0, 0), lat, lon) const sunEphem = SunCalc.getTimes(new Date(year, month, day, 12, 0, 0), lat, lon)
draw_box(midnight, sunEphem.nauticalDawn, 'night') draw_box(midnight, sunEphem.nauticalDawn, 'night')
@ -223,7 +228,9 @@ export function render_astronomy(canvas, width, height, offset, data) {
let sunData = [] let sunData = []
const year = data.beginTime.getFullYear() const year = data.beginTime.getFullYear()
const month = data.beginTime.getMonth() const month = data.beginTime.getMonth()
for (var day = data.beginTime.getDate(); day <= data.endTime.getDate(); day++) {
const n_days = Math.ceil((data.endTime- data.beginTime) / (1000 * 60 * 60 * 24))
for (var day = data.beginTime.getDate(); day <= (data.beginTime.getDate() + n_days); day++) {
const midnight = new Date(year, month, day, 0, 0, 0) const midnight = new Date(year, month, day, 0, 0, 0)
// Solar Ephemeris // Solar Ephemeris

Loading…
Cancel
Save