diff options
| author | かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com> | 2026-01-08 12:16:33 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-08 12:16:33 +0900 |
| commit | cd973b252a1304b207893b8f2327fc861d7492db (patch) | |
| tree | 5dcd7cd1761b688e5f0ea01a9d61e9276c95db1e /packages/frontend/src/utility | |
| parent | enable and fix no-unused-vars and no-async-promise-executor (#17070) (diff) | |
| download | misskey-cd973b252a1304b207893b8f2327fc861d7492db.tar.gz misskey-cd973b252a1304b207893b8f2327fc861d7492db.tar.bz2 misskey-cd973b252a1304b207893b8f2327fc861d7492db.zip | |
fix(frontend): 2月29日を誕生日に設定している場合、平年は3月1日を誕生日として扱うように (#17072)
* fix(frontend): 2月29日を誕生日に設定している場合、平年は3月1日を誕生日として扱うように
* Update Changelog
* add tests
* spdx
Diffstat (limited to 'packages/frontend/src/utility')
| -rw-r--r-- | packages/frontend/src/utility/is-birthday.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/packages/frontend/src/utility/is-birthday.ts b/packages/frontend/src/utility/is-birthday.ts new file mode 100644 index 0000000000..ff875281a2 --- /dev/null +++ b/packages/frontend/src/utility/is-birthday.ts @@ -0,0 +1,28 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import * as Misskey from 'misskey-js'; + +export function isBirthday(user: Misskey.entities.UserDetailed, now = new Date()): boolean { + if (user.birthday == null) return false; + + const [_, bm, bd] = user.birthday.split('-').map((v) => parseInt(v, 10)); + if (isNaN(bm) || isNaN(bd)) return false; + + const y = now.getFullYear(); + const m = now.getMonth() + 1; + const d = now.getDate(); + + // 閏日生まれで平年の場合は3月1日を誕生日として扱う + if (bm === 2 && bd === 29 && m === 3 && d === 1 && !isLeapYear(y)) { + return true; + } + + return m === bm && d === bd; +} + +function isLeapYear(year: number): boolean { + return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0); +} |