Avoid going out of bounds via navigation

This commit is contained in:
Quantum 2022-02-14 02:13:25 -05:00
parent c4b2f56772
commit 2a961f2d44
2 changed files with 5 additions and 4 deletions

View file

@ -1,6 +1,6 @@
import React, {FormEvent} from 'react';
import {Calendar} from './Calendar';
import {endGregorian, frSupportedYear, gregorianJDN, jdnFrench, Month, startGregorian} from './dates';
import {endGregorian, endJD, frSupportedYear, gregorianJDN, jdnFrench, Month, startGregorian, startJD} from './dates';
type YearMonth = {
year: number;
@ -92,7 +92,7 @@ class App extends React.Component<{}, AppState> {
return;
const jdn = gregorianJDN(+this.state.goYear, +this.state.goMonth, +this.state.goDay);
const {year, month} = jdnFrench(jdn);
const {year, month} = jdnFrench(Math.min(Math.max(startJD, jdn), endJD));
this.setState({year, month});
}

View file

@ -63,7 +63,7 @@ export const decadeNames = [
'primidi', 'duodi', 'tridi', 'quartidi', 'quintidi', 'sextidi', 'septidi', 'octidi', 'nonidi', 'décadi',
];
const startJD = data.start_jd;
export const startJD = data.start_jd;
export const startYear = data.start_year;
const leaps: Array<number> = [0];
@ -107,8 +107,9 @@ export function jdnGregorian(jdn: number): Date {
return new Date(year, month - 1, day);
}
export const endJD = frJDN(endYear, 13, frIsLeap(endYear) ? 6: 5);
export const startGregorian = jdnGregorian(startJD);
export const endGregorian = jdnGregorian(frJDN(endYear, 13, frIsLeap(endYear) ? 6: 5));
export const endGregorian = jdnGregorian(endJD);
export function jdnFrench(jdn: number): FrenchDate {
let lo = 0;