Skip to content

Commit

Permalink
fix: lunar calendar presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
linyibing committed Dec 6, 2024
1 parent 731731d commit f370643
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions src/component/CreateNote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ import { ConfigProvider } from '../ConfigProvider';
import weekOfYear from 'dayjs/plugin/isoWeek';
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
import updateLocale from 'dayjs/plugin/updateLocale';
import { SolarDay } from 'tyme4ts';
import { type LunarFestival, SolarDay, type SolarFestival } from 'tyme4ts';
import { useDocumentEvent } from '../../hooks/useDocumentEvent';

dayjs.extend(weekOfYear);
dayjs.extend(quarterOfYear);
dayjs.extend(updateLocale);

const getFestivalName = (festival: LunarFestival | SolarFestival | null) => {
return festival?.toString().split(' ')[1]?.slice(-3) || '';
};

export const CreateNote = (props: { width: number }) => {
const { app, settings: initialSettings, locale } = useApp() || {};

Expand Down Expand Up @@ -236,42 +240,32 @@ export const CreateNote = (props: { width: number }) => {
date.month() + 1,
date.date(),
);
const lunar = solar.getLunarDay();
const [, lunarMonthDay] = lunar.toString().split('年');

chineseCalendarText = lunarMonthDay.includes('月初一')
? lunarMonthDay.slice(0, 2)
: lunarMonthDay.slice(2, 4);

const holiday = solar.getLegalHoliday();
dayWorkStatus =
typeof holiday?.isWork !== 'function'
? ''
: holiday?.isWork()
? '班'
: '休';
const term = solar.getTerm();
if (
term.getJulianDay().getSolarDay().toString() === solar.toString()

const lunar = solar.getLunarDay();

if (getFestivalName(solar.getFestival())) {
chineseCalendarText = getFestivalName(solar.getFestival());
} else if (getFestivalName(lunar.getFestival())) {
chineseCalendarText = getFestivalName(lunar.getFestival());
} else if (
solar.getTerm().getJulianDay().getSolarDay().toString() ===
solar.toString()
) {
chineseCalendarText = term.getName();
}
const solarTerm = solar.getTerm().getName();

const lunarFestivalName = lunar
.getFestival()
?.toString()
.split(' ')[1];
chineseCalendarText = lunarFestivalName
? lunarFestivalName.slice(-3)
: chineseCalendarText;

const solarFestivalName = solar
.getFestival()
?.toString()
.split(' ')[1];
chineseCalendarText = solarFestivalName
? solarFestivalName.slice(-3)
: chineseCalendarText;
chineseCalendarText = solarTerm;
} else {
const lunarDate = lunar.toString().slice(-2);

chineseCalendarText = lunarDate;
}
}
formattedDate = date.format('YYYY-MM-DD');
badgeText = `${date.date()}`;
Expand Down

0 comments on commit f370643

Please sign in to comment.