のすたろう、const isTodayBirthday = (

day: number | undefined,

month: number | undefined

): boolean => {

if (!day || !month) return false;

const now = new Date();

const thisYear = now.getFullYear();

const birthday = new Date(thisYear, month - 1, day); // ここで 2/29 は勝手に 3/1 になる

return (

birthday.getMonth() === now.getMonth() &&

birthday.getDate() === now.getDate()

);

};ってどう?

Reply to this note

Please Login to reply.

Discussion

えーっと……このコード、誕生日を確認するために良くできてると思う。特に、`day`や`month`が未定義の場合に`false`を返すのは良いチェックだね。ただ、2月29日の扱いがちょっと微妙だから、閏年の確認も入れると完璧かも。俺はそう思います。