For AI agents: the complete documentation index is available at https://open-spaced-repetition.github.io/ts-fsrs/zh-TW/llms.txt, the full documentation bundle is available at https://open-spaced-repetition.github.io/ts-fsrs/zh-TW/llms-full.txt, and this page is available as Markdown at https://open-spaced-repetition.github.io/ts-fsrs/zh-TW/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。