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/temporal-instant.md.
  • 简体中文
  • Temporal Instant

    将 timezone 和 fractionalDays 直接放在调度器 config 顶层,例如 config: { ...modelConfig, timezone: 'Asia/Tokyo', fractionalDays: false }。省略这两个字段时使用默认值 'UTC' 和 false。直接调用预设需要完整配置:temporalInstantChrono.create({ config: { timezone: 'Asia/Tokyo', fractionalDays: false } });通过调度器创建实例时会校验配置并补齐默认值。

    fractionalDays: false 表示按指定时区计算日历日期差;设为 true 时,时间差包含该时区下的小数天数。add 在 UTC 下使用固定 24 小时,在其他时区下按日历天计算;跨越夏令时切换时,当地的一天可能短于或长于 24 小时。增加小数天数时,使用相邻当地日的实际长度。此预设不提供自定义每日换日时间。

    运行预设

    在应用中安装 temporal-polyfill。示例在创建 Chrono 前导入全局入口,仅在执行环境没有原生 Temporal 时安装 polyfill;第二条 import 提供全局 TypeScript 类型声明。

    npm
    yarn
    pnpm
    bun
    deno
    npm install temporal-polyfill
    import 'temporal-polyfill/global'
    import 'temporal-polyfill/types/global'
    import { 
    const temporalInstantChrono: Chrono<{
        readonly time: SRSSchema<{
            input: Temporal.Instant;
            output: Temporal.Instant;
        }>;
        readonly config: SRSSchema<{
            input: {
                readonly timezone?: string | undefined;
                readonly fractionalDays?: boolean | undefined;
            };
            output: {
                readonly timezone: string;
                readonly fractionalDays: boolean;
            };
        }>;
        readonly fields: {
            readonly card: SRSSchema<{
                input: {
                    dueAt: Temporal.Instant;
                    lastReviewAt?: (Temporal.Instant | null) | undefined;
                };
                output: {
                    dueAt: Temporal.Instant;
                    lastReviewAt: Temporal.Instant | null;
                };
            }>;
            readonly revlog: SRSSchema<{
                input: {
                    dueAt: Temporal.Instant;
                    lastReviewAt?: (Temporal.Instant | null) | undefined;
                    reviewTime: Temporal.Instant;
                };
                output: {
                    dueAt: Temporal.Instant;
                    lastReviewAt: Temporal.Instant | null;
                    reviewTime: Temporal.Instant;
                };
            }>;
        };
    }>
    temporalInstantChrono
    } from 'ts-fsrs'
    const
    const clock: ChronoCore<Temporal.Instant>
    clock
    =
    const temporalInstantChrono: Chrono<{
        readonly time: SRSSchema<{
            input: Temporal.Instant;
            output: Temporal.Instant;
        }>;
        readonly config: SRSSchema<{
            input: {
                readonly timezone?: string | undefined;
                readonly fractionalDays?: boolean | undefined;
            };
            output: {
                readonly timezone: string;
                readonly fractionalDays: boolean;
            };
        }>;
        readonly fields: {
            readonly card: SRSSchema<{
                input: {
                    dueAt: Temporal.Instant;
                    lastReviewAt?: (Temporal.Instant | null) | undefined;
                };
                output: {
                    dueAt: Temporal.Instant;
                    lastReviewAt: Temporal.Instant | null;
                };
            }>;
            readonly revlog: SRSSchema<{
                input: {
                    dueAt: Temporal.Instant;
                    lastReviewAt?: (Temporal.Instant | null) | undefined;
                    reviewTime: Temporal.Instant;
                };
                output: {
                    dueAt: Temporal.Instant;
                    lastReviewAt: Temporal.Instant | null;
                    reviewTime: Temporal.Instant;
                };
            }>;
        };
    }>
    temporalInstantChrono
    .
    Chrono<{ readonly time: SRSSchema<{ input: Temporal.Instant; output: Temporal.Instant; }>; readonly config: SRSSchema<{ input: { readonly timezone?: string | undefined; readonly fractionalDays?: boolean | undefined; }; output: { readonly timezone: string; readonly fractionalDays: boolean; }; }>; readonly fields: { readonly card: SRSSchema<{ input: { dueAt: Temporal.Instant; lastReviewAt?: (Temporal.Instant | null) | undefined; }; output: { dueAt: Temporal.Instant; lastReviewAt: Temporal.Instant | null; }; }>; readonly revlog: SRSSchema<{ input: { dueAt: Temporal.Instant; lastReviewAt?: (Temporal.Instant | null) | undefined; reviewTime: Temporal.Instant; }; output: { dueAt: Temporal.Instant; lastReviewAt: Temporal.Instant | null; reviewTime: Temporal.Instant; }; }>; }; }>.create: (ctx: {
        readonly config: {
            readonly timezone: string;
            readonly fractionalDays: boolean;
        };
    }) => ChronoCore<Temporal.Instant>
    create
    ({
    config: { timezone: 'America/New_York', fractionalDays: false }, }) const
    const fractionalClock: ChronoCore<Temporal.Instant>
    fractionalClock
    =
    const temporalInstantChrono: Chrono<{
        readonly time: SRSSchema<{
            input: Temporal.Instant;
            output: Temporal.Instant;
        }>;
        readonly config: SRSSchema<{
            input: {
                readonly timezone?: string | undefined;
                readonly fractionalDays?: boolean | undefined;
            };
            output: {
                readonly timezone: string;
                readonly fractionalDays: boolean;
            };
        }>;
        readonly fields: {
            readonly card: SRSSchema<{
                input: {
                    dueAt: Temporal.Instant;
                    lastReviewAt?: (Temporal.Instant | null) | undefined;
                };
                output: {
                    dueAt: Temporal.Instant;
                    lastReviewAt: Temporal.Instant | null;
                };
            }>;
            readonly revlog: SRSSchema<{
                input: {
                    dueAt: Temporal.Instant;
                    lastReviewAt?: (Temporal.Instant | null) | undefined;
                    reviewTime: Temporal.Instant;
                };
                output: {
                    dueAt: Temporal.Instant;
                    lastReviewAt: Temporal.Instant | null;
                    reviewTime: Temporal.Instant;
                };
            }>;
        };
    }>
    temporalInstantChrono
    .
    Chrono<{ readonly time: SRSSchema<{ input: Temporal.Instant; output: Temporal.Instant; }>; readonly config: SRSSchema<{ input: { readonly timezone?: string | undefined; readonly fractionalDays?: boolean | undefined; }; output: { readonly timezone: string; readonly fractionalDays: boolean; }; }>; readonly fields: { readonly card: SRSSchema<{ input: { dueAt: Temporal.Instant; lastReviewAt?: (Temporal.Instant | null) | undefined; }; output: { dueAt: Temporal.Instant; lastReviewAt: Temporal.Instant | null; }; }>; readonly revlog: SRSSchema<{ input: { dueAt: Temporal.Instant; lastReviewAt?: (Temporal.Instant | null) | undefined; reviewTime: Temporal.Instant; }; output: { dueAt: Temporal.Instant; lastReviewAt: Temporal.Instant | null; reviewTime: Temporal.Instant; }; }>; }; }>.create: (ctx: {
        readonly config: {
            readonly timezone: string;
            readonly fractionalDays: boolean;
        };
    }) => ChronoCore<Temporal.Instant>
    create
    ({
    config: { timezone: 'America/New_York', fractionalDays: true }, }) // Noon in New York, the day before daylight saving time starts. const from = Temporal.Instant.from('2026-03-07T17:00:00Z') const next =
    const clock: ChronoCore<Temporal.Instant>
    clock
    .
    ChronoCore<Temporal.Instant>.add: (from: Temporal.Instant, days: number) => Temporal.Instant
    add
    (from, 1)
    const halfDay =
    const clock: ChronoCore<Temporal.Instant>
    clock
    .
    ChronoCore<Temporal.Instant>.add: (from: Temporal.Instant, days: number) => Temporal.Instant
    add
    (from, 0.5)
    console.log( JSON.stringify( { nextDayUTC: next.toString(), elapsedHours: from.
    Temporal.Instant.until(other: Temporal.InstantLike, options?: Temporal.RoundingOptionsWithLargestUnit<Temporal.TimeUnit>): Temporal.Duration (+1 overload)
    until
    (next).
    Temporal.Duration.total(totalOf: Temporal.PluralizeUnit<Temporal.DateUnit | Temporal.TimeUnit>): number (+3 overloads)
    total
    ('hours'),
    calendarDays:
    const clock: ChronoCore<Temporal.Instant>
    clock
    .
    ChronoCore<Temporal.Instant>.difference: (from: Temporal.Instant, to: Temporal.Instant) => number

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

    difference
    (from, next),
    fractionalDays:
    const fractionalClock: ChronoCore<Temporal.Instant>
    fractionalClock
    .
    ChronoCore<Temporal.Instant>.difference: (from: Temporal.Instant, to: Temporal.Instant) => number

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

    difference
    (from, halfDay),
    }, null, 2 ) )

    纽约 3 月 7 日中午对应 17:00 UTC。增加一个当地日历天后,是 3 月 8 日中午,即 16:00 UTC;由于进入夏令时,实际只经过 23 小时。fractionalDays: true 将半天的增量计算为 0.5。