feat: countdown anniversaries and birthdays like ticktick
ci / docker (push) Successful in 6m18s

This commit is contained in:
2026-09-06 15:36:42 +08:00
parent 3e20943d1e
commit afc78dba6c
17 changed files with 561 additions and 13 deletions
+10 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { dateKey, defaultView, habitWeek, isHabitComplete, isHabitScheduledToday, isTaskView, nextHabitSwipeValue, numericHabitInputValue, previousHabitSwipeValue, quickTaskFields, shouldToggleRowSwipe } from './mvp-utils'
import { countdownDayText, countdownKindLabel, dateKey, defaultView, habitWeek, isHabitComplete, isHabitScheduledToday, isTaskView, nextHabitSwipeValue, numericHabitInputValue, previousHabitSwipeValue, quickTaskFields, shouldToggleRowSwipe } from './mvp-utils'
describe('MVP view utilities', () => {
it('formats a local date as YYYY-MM-DD', () => {
@@ -63,6 +63,15 @@ describe('MVP view utilities', () => {
expect(previousHabitSwipeValue('numeric', 0)).toBe(0)
})
it('renders countdown labels from date-only day values', () => {
expect(countdownDayText(8)).toBe('还有 8 天')
expect(countdownDayText(0)).toBe('就是今天')
expect(countdownDayText(-12)).toBe('已经 12 天')
expect(countdownKindLabel('countdown')).toBe('倒数日')
expect(countdownKindLabel('anniversary')).toBe('纪念日')
expect(countdownKindLabel('birthday')).toBe('生日')
})
it('toggles a row for a deliberate mostly-horizontal swipe', () => {
expect(shouldToggleRowSwipe(78, 8)).toBe(true)
expect(shouldToggleRowSwipe(88, 28)).toBe(true)
+10
View File
@@ -76,6 +76,16 @@ export function numericHabitInputValue(input: number | string | undefined) {
return Number.isFinite(value) && value >= 0 ? value : null
}
export function countdownDayText(days: number) {
if (days > 0) return `还有 ${days}`
if (days === 0) return '就是今天'
return `已经 ${Math.abs(days)}`
}
export function countdownKindLabel(kind: string) {
return ({ countdown: '倒数日', anniversary: '纪念日', birthday: '生日' } as Record<string, string>)[kind] ?? '倒数日'
}
export function shouldToggleRowSwipe(deltaX: number, deltaY: number) {
return deltaX >= 64 && deltaX > Math.abs(deltaY) * 1.5
}