forked from mirrors/misskey
fix(frontend): 2月29日を誕生日に設定している場合、平年は3月1日を誕生日として扱うように (#17072)
* fix(frontend): 2月29日を誕生日に設定している場合、平年は3月1日を誕生日として扱うように * Update Changelog * add tests * spdx
This commit is contained in:
@@ -29,6 +29,7 @@ import { prefer } from '@/preferences.js';
|
||||
import { updateCurrentAccountPartial } from '@/accounts.js';
|
||||
import { migrateOldSettings } from '@/pref-migrate.js';
|
||||
import { unisonReload } from '@/utility/unison-reload.js';
|
||||
import { isBirthday } from '@/utility/is-birthday.js';
|
||||
|
||||
export async function mainBoot() {
|
||||
const { isClientUpdated, lastVersion } = await common(async () => {
|
||||
@@ -144,12 +145,8 @@ export async function mainBoot() {
|
||||
const m = now.getMonth() + 1;
|
||||
const d = now.getDate();
|
||||
|
||||
if ($i.birthday) {
|
||||
const bm = parseInt($i.birthday.split('-')[1]);
|
||||
const bd = parseInt($i.birthday.split('-')[2]);
|
||||
if (m === bm && d === bd) {
|
||||
claimAchievement('loggedInOnBirthday');
|
||||
}
|
||||
if (isBirthday($i, now)) {
|
||||
claimAchievement('loggedInOnBirthday');
|
||||
}
|
||||
|
||||
if (m === 1 && d === 1) {
|
||||
|
||||
@@ -186,6 +186,7 @@ import { getStaticImageUrl } from '@/utility/media-proxy.js';
|
||||
import MkSparkle from '@/components/MkSparkle.vue';
|
||||
import { prefer } from '@/preferences.js';
|
||||
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
|
||||
import { isBirthday } from '@/utility/is-birthday.js';
|
||||
|
||||
function calcAge(birthdate: string): number {
|
||||
const date = new Date(birthdate);
|
||||
@@ -319,16 +320,10 @@ function disposeBannerParallaxResizeObserver() {
|
||||
onMounted(() => {
|
||||
narrow.value = rootEl.value!.clientWidth < 1000;
|
||||
|
||||
if (props.user.birthday) {
|
||||
const m = new Date().getMonth() + 1;
|
||||
const d = new Date().getDate();
|
||||
const bm = parseInt(props.user.birthday.split('-')[1]);
|
||||
const bd = parseInt(props.user.birthday.split('-')[2]);
|
||||
if (m === bm && d === bd) {
|
||||
confetti({
|
||||
duration: 1000 * 4,
|
||||
});
|
||||
}
|
||||
if (isBirthday(user.value)) {
|
||||
confetti({
|
||||
duration: 1000 * 4,
|
||||
});
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
|
||||
28
packages/frontend/src/utility/is-birthday.ts
Normal file
28
packages/frontend/src/utility/is-birthday.ts
Normal file
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user