Display rural date names

This commit is contained in:
Quantum 2022-02-13 00:02:01 -05:00
parent 1d05142cb7
commit 3971d2d16c
4 changed files with 37 additions and 2 deletions

View file

@ -1,7 +1,7 @@
import React from 'react';
import './Calendar.scss';
import {
dateName,
dateName, dateRuralName,
Day,
decadeNames,
endYear,
@ -37,9 +37,11 @@ function DayDetail({jdn}: { jdn: number }): JSX.Element {
function NormalDay({year, month, day, todayJDN}: DateProps & { todayJDN: number }): JSX.Element {
const jdn = frJDN(year, month, day);
const rural = dateRuralName(month, day)!;
return <div className={`Day NormalDay ${jdn === todayJDN ? 'Day-today' : ''}`}>
<div className="Day-name">{day}</div>
<div className="Day-decade">{decadeNames[(day - 1) % 10]}</div>
<div className="Day-rural" title={rural.title}>{rural.name}</div>
<DayDetail jdn={jdn}/>
</div>;
}

View file

@ -1,4 +1,14 @@
import {dateName, frIsLeap, frJDN, gregorianJDN, jdnFrench, jdnGregorian, jdnLongCount, monthName} from './dates';
import {
dateName,
dateRuralName,
frIsLeap,
frJDN,
gregorianJDN,
jdnFrench,
jdnGregorian,
jdnLongCount,
monthName
} from './dates';
describe('gregorianJDN', () => {
it('works', () => {
@ -170,3 +180,16 @@ describe('dateName', () => {
expect(dateName(13, 7)).toBeNull();
});
});
describe('dateRuralName', () => {
it('works', () => {
expect(dateRuralName(1, 1)).toEqual({name: 'Raisin', title: 'Grape'});
expect(dateRuralName(1, 30)).toEqual({name: 'Tonneau', title: 'Barrel'});
expect(dateRuralName(12, 1)).toEqual({name: 'Prune', title: 'Plum'});
expect(dateRuralName(12, 30)).toEqual({name: 'Panier', title: 'Pack Basket'});
});
it('returns null for complimentary days', () => {
expect(dateRuralName(13, 1)).toBeNull();
});
});

View file

@ -1,4 +1,5 @@
import data from './cal.json';
import ruralName from './rural-days.json';
// Month 13 is for the complementary days
export type Month = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13;
@ -170,3 +171,11 @@ export function dateName(month: Month, day: Day): string | null {
}
return `${day} ${monthNames[month]}`;
}
export function dateRuralName(month: Month, day: Day): {name: string, title: string} | null {
const rural = ruralName[month * 30 + day - 31];
if (!rural)
return null;
const [name, title] = rural;
return {name, title};
}

1
src/rural-days.json Normal file

File diff suppressed because one or more lines are too long