feat: implement Sleepy sleep diary

This commit is contained in:
2026-10-11 12:45:09 +07:00
commit a0fa0e0e56
27 changed files with 8356 additions and 0 deletions

18
lib/sleep.test.ts Normal file
View File

@@ -0,0 +1,18 @@
import { describe, expect, it } from 'vitest';
import { calculateMetrics, formatDuration } from './sleep';
describe('sleep calculations', () => {
it('calculates overnight time in bed, total sleep, and efficiency', () => {
expect(calculateMetrics({
bedtime: '23:40',
riseTime: '07:10',
sleepLatencyMinutes: 30,
wasoMinutes: 40,
})).toEqual({ timeInBedMinutes: 450, totalSleepMinutes: 380, efficiency: 84 });
});
it('formats a duration for the summary', () => {
expect(formatDuration(380)).toBe('6 ч 20 мин');
expect(formatDuration(5)).toBe('5 мин');
});
});