For AI agents: the complete documentation index is available at https://open-spaced-repetition.github.io/ts-fsrs/zh-CN/llms.txt, the full documentation bundle is available at https://open-spaced-repetition.github.io/ts-fsrs/zh-CN/llms-full.txt, and this page is available as Markdown at https://open-spaced-repetition.github.io/ts-fsrs/zh-CN/guide/chrono/date.md.
  • 简体中文
  • Date

    DefaultScheduler 使用 dateChrono。它的时间 schema 接受有效的 Date 对象,因此调用调度器前,应先将存储的字符串或时间戳转换为 Date。当前 schema 也会拒绝 new Date(0)(Unix 纪元起点)和无效日期。

    在调度器 config 顶层设置 fractionalDays(默认 false)。直接调用时需传入 dateChrono.create({ config: { fractionalDays: false } })。设为 false 时,同一 UTC 日期内的时间差为零,23:00 到次日 01:00 的日期差为一天;设为 true 时,这两小时得到 2 / 24 天。add(from, 0.5) 始终增加十二小时。精确比较先后请使用 compare。

    normalize 如何参与调度

    normalize 将 card 或 revlog 的字段转换为 { previous, current }。对于 Date 和 Temporal 预设:

    • 复习时,normalize 返回 previous: card.lastReviewAt 和 current: card.dueAt。
    • 经过天数为 difference(previous ?? current, now);New 卡片始终为零。
    • 新 card 保存 dueAt: add(now, interval) 和 lastReviewAt: now。
    • revlog 保存复习前 card 的 dueAt、lastReviewAt,以及本次复习的 reviewTime: now。
    • 撤销时,normalize 返回 previous: revlog.lastReviewAt 和 current: revlog.dueAt,用于还原复习前 card 的时间字段;New 卡片还原为 lastReviewAt: null。

    运行预设

    import { 
    const dateChrono: Chrono<{
        readonly time: SRSSchema<{
            input: Date;
            output: Date;
        }>;
        readonly config: SRSSchema<{
            input: {
                readonly fractionalDays?: boolean | undefined;
            };
            output: {
                readonly fractionalDays: boolean;
            };
        }>;
        readonly fields: {
            readonly card: SRSSchema<{
                input: {
                    dueAt: Date;
                    lastReviewAt?: (Date | null) | undefined;
                };
                output: {
                    dueAt: Date;
                    lastReviewAt: Date | null;
                };
            }>;
            readonly revlog: SRSSchema<{
                input: {
                    dueAt: Date;
                    lastReviewAt?: (Date | null) | undefined;
                    reviewTime: Date;
                };
                output: {
                    dueAt: Date;
                    lastReviewAt: Date | null;
                    reviewTime: Date;
                };
            }>;
        };
    }>
    dateChrono
    } from 'ts-fsrs'
    const
    const clock: ChronoCore<Date>
    clock
    =
    const dateChrono: Chrono<{
        readonly time: SRSSchema<{
            input: Date;
            output: Date;
        }>;
        readonly config: SRSSchema<{
            input: {
                readonly fractionalDays?: boolean | undefined;
            };
            output: {
                readonly fractionalDays: boolean;
            };
        }>;
        readonly fields: {
            readonly card: SRSSchema<{
                input: {
                    dueAt: Date;
                    lastReviewAt?: (Date | null) | undefined;
                };
                output: {
                    dueAt: Date;
                    lastReviewAt: Date | null;
                };
            }>;
            readonly revlog: SRSSchema<{
                input: {
                    dueAt: Date;
                    lastReviewAt?: (Date | null) | undefined;
                    reviewTime: Date;
                };
                output: {
                    dueAt: Date;
                    lastReviewAt: Date | null;
                    reviewTime: Date;
                };
            }>;
        };
    }>
    dateChrono
    .
    Chrono<{ readonly time: SRSSchema<{ input: Date; output: Date; }>; readonly config: SRSSchema<{ input: { readonly fractionalDays?: boolean | undefined; }; output: { readonly fractionalDays: boolean; }; }>; readonly fields: { readonly card: SRSSchema<{ input: { dueAt: Date; lastReviewAt?: (Date | null) | undefined; }; output: { dueAt: Date; lastReviewAt: Date | null; }; }>; readonly revlog: SRSSchema<{ input: { dueAt: Date; lastReviewAt?: (Date | null) | undefined; reviewTime: Date; }; output: { dueAt: Date; lastReviewAt: Date | null; reviewTime: Date; }; }>; }; }>.create: (ctx: {
        readonly config: {
            readonly fractionalDays: boolean;
        };
    }) => ChronoCore<Date>
    create
    ({ config: { fractionalDays: false } })
    const from = new Date('2026-01-01T23:00:00.000Z') const to = new Date('2026-01-02T01:00:00.000Z') console.log( JSON.stringify({ elapsedDays:
    const clock: ChronoCore<Date>
    clock
    .
    ChronoCore<Date>.difference: (from: Date, to: Date) => number

    Returns the distance from the previous review time to the current time.

    difference
    (from, to),
    halfDayLater:
    const clock: ChronoCore<Date>
    clock
    .
    ChronoCore<Date>.add: (from: Date, days: number) => Date
    add
    (from, 0.5).toISOString(),
    order:
    const clock: ChronoCore<Date>
    clock
    .
    ChronoCore<Date>.compare?: ((left: Date, right: Date) => number) | undefined

    Compares two time values in chronological order.

    Returns a negative number when left is earlier than right, zero when they are equal, and a positive number when left is later than right. Callers decide how to compare values when a chronology omits this method.

    compare
    ?.(from, to),
    }) )

    跨过午夜时,UTC 日期差为一天;增加半天则让时间向后移动十二小时。