Skip to content

Accept Duration type timezone offset values - #7691

Merged
laurmaedje merged 4 commits into
typst:mainfrom
t-rapp:tr-today-offset
Feb 10, 2026
Merged

laurmaedje merged 4 commits into
typst:mainfrom
t-rapp:tr-today-offset

Conversation

@t-rapp

@t-rapp t-rapp commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

Support timezone offset values in #datetime.today() which are not full hours. For example this applies to the Newfoundland Time Zone (UTC-03:30 / UTC-02:30), or Nepal Standard Time (UTC+05:45).

Fixes #6277.

Add support for offset handling in the test-runner implementation of
World::today(). Add some checks for offsets with forward/backward day
wrapping.
Preparation step to support timezone offset values in `#datetime.today()` that
are not full hours.
Support timezone offset values in `#datetime.today()` which are not full hours.
For example this applies to the Newfoundland Time Zone (UTC-03:30/ UTC-02:30),
or Nepal Standard Time (UTC+05:45).

Fixes typst#6277.
@t-rapp t-rapp changed the title Accept Duration type timezone offset values Accept Duration type timezone offset values Jan 20, 2026
@laurmaedje laurmaedje added crash The Typst compiler crashes for some input waiting-on-review This PR is waiting to be reviewed. crate Issues with using Typst as a library for other apps and removed crash The Typst compiler crashes for some input labels Jan 20, 2026
Comment on lines +68 to +72
#test(datetime.today(offset: 24).display(), "1970-01-02")
#test(datetime.today(offset: -24).display(), "1969-12-31")
#test(datetime.today(offset: duration(hours: 5, minutes: 45)).display(), "1970-01-01")
#test(datetime.today(offset: duration(days: 2)).display(), "1970-01-03")
#test(datetime.today(offset: duration(days: -2)).display(), "1969-12-30")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are a tad misleading because the actual CLI function using FixedOffset does not allow a duration >= 24h. Perhaps, we should rather base the TestWorld's today output on a time different than midnight such that an offset < 24h can have an effect in both directions.

I also noticed #7843 while playing with this. I'm good with merging the fix as-is for now, but aligning the CLI and test impls a bit more could be a good followup.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for bringing the limitation with FixedOffset to my attention, I somehow missed that.

I assume aligning CLI and test World impls would mean the offset calculation is also done with chrono types in the tests?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be an option. Alternatively, we could impose the limitation separately in the tests though at that point we're not testing all that much I suppose.

I could also imagine moving the chrono based today impl to typst-kit to share it, but that would be a slightly larger task and might involve some API design bikeshedding. And it would need to support both current and fixed time of course.

While looking at that, I just noticed that we're depending on Local timezone even when SOURCE_DATE_EPOCH is set, which I guess is not great for reproducibility.

But anyways, I'm going a bit off-topic. There are more things to improve here, but moving the tests to a reproducible chrono based impl would be a reasonable first step I think.

@laurmaedje
laurmaedje enabled auto-merge February 10, 2026 16:28
@laurmaedje

Copy link
Copy Markdown
Member

Thanks!

@laurmaedje laurmaedje added scripting About Typst's coding capabilities interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. and removed waiting-on-review This PR is waiting to be reviewed. labels Feb 10, 2026
@laurmaedje
laurmaedje added this pull request to the merge queue Feb 10, 2026
Merged via the queue into typst:main with commit 186df36 Feb 10, 2026
8 checks passed
t-rapp added a commit to t-rapp/typst that referenced this pull request Feb 12, 2026
Create date values in tests with a chrono-based approach that is similar
to the implementation in `typst-cli`.

Suggested in typst#7691.
@t-rapp
t-rapp deleted the tr-today-offset branch February 12, 2026 12:12
t-rapp added a commit to t-rapp/typst that referenced this pull request Feb 13, 2026
Create date values in tests with a chrono-based approach that is similar
to the implementation in `typst-cli`.

Suggested in typst#7691.
t-rapp added a commit to t-rapp/typst that referenced this pull request Feb 13, 2026
Only apply the local timezone offset in the CLI implementation of
`World::today()` when no fixed date is used, and no offset argument is
set.

Mentioned by Laurenz in typst#7691.
t-rapp added a commit to t-rapp/typst that referenced this pull request Feb 13, 2026
Always use UTC timezone in the CLI implementation of `World::today()`
when a fixed date is requested. Only apply the local timezone offset
when the date is not fixed, and no offset argument is set.

Mentioned in typst#7691.
jassielof pushed a commit to jassielof/typst that referenced this pull request Apr 7, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request May 15, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request May 15, 2026
ParaN3xus added a commit to ParaN3xus/typstyle that referenced this pull request May 16, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request May 24, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request May 24, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 1, 2026
ParaN3xus added a commit to ParaN3xus/tinymist that referenced this pull request Jun 1, 2026
ParaN3xus added a commit to ParaN3xus/typstyle that referenced this pull request Jun 4, 2026
QuadnucYard added a commit to typstyle-rs/typstyle that referenced this pull request Jun 6, 2026
commit 65301b2
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Fri Jun 5 00:57:12 2026 +0000

    build: update tinymist to 0.14.23

commit 3ac7c69
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Thu Jun 4 23:30:34 2026 +0000

    build: update tinymist to 0.14.23-rc1

commit 4f5efbf
Author: paran3xus <[email protected]>
Date:   Thu Jun 4 12:41:19 2026 +0000

    feat: add compatibility for typst/typst#7865 and typst/typst#8116

commit cb25b2e
Author: paran3xus <[email protected]>
Date:   Sat May 16 10:06:29 2026 +0000

    fix: adapt typstyle-consistency to typst/typst#7964

commit ae25cb3
Author: paran3xus <[email protected]>
Date:   Sat May 16 10:06:22 2026 +0000

    fix: adapt today to typst/typst#7691

commit c5702de
Author: paran3xus <[email protected]>
Date:   Sat May 16 05:14:33 2026 +0000

    build: patch typst-bundle

commit aeffa37
Author: paran3xus <[email protected]>
Date:   Fri May 15 05:09:16 2026 +0000

    build: bump tinymist-world to nightly (remote branch)

commit 8ea80b1
Author: paran3xus <[email protected]>
Date:   Thu May 14 05:08:26 2026 +0000

    build: bump typst to nightly (local patch)

    a
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin pushed a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 13, 2026
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 14, 2026
This PR is part of the Typst 0.15 cleanup stack. It sits on top of the
dependency/toolchain group and covers the first world/document output
API adaptation slice.

## Upstream Typst Changes

- [`typst/typst#7964` Bundle
export](typst/typst#7964) splits document output
into target-specific APIs.
- Tinymist now works with `typst_layout::PagedDocument`,
`typst_html::HtmlDocument`, `typst::model::Document`, and
`typst::foundations::Output` instead of relying on the old broad
document surface.
- Document fields are private; callers need accessors such as `pages()`,
`info()`, `introspector()`, and `root_mut()`.
- Document introspection changes around `typst/typst@7d2edbdb3` move
consumers toward the target document's output introspector.
- `DocumentInfo` is the compiled-document metadata payload (`title`,
`author`, `description`, `keywords`, `date`, `locale`). Typst populates
it while creating the target document from document/text styles, not
from finished `Page` or `Frame` values.
- HTML/SVG conversion now goes through the bundle-aware `svg_in_html`
path with a `LateLinkResolver`.
- [`typst/typst#7691`](typst/typst#7691) changes
`World::today` from an hour offset to
`Option<typst::foundations::Duration>`.
- `typst/typst@acc3fed51` moves paged positions to
`typst::introspection::PagedPosition`.
- Typst 0.15 also requires protected engine introspection through
`typst::utils::Protected`.

## Tinymist Changes

- Adapts `tinymist-std`, `tinymist-world`, and `tinymist-task` to the
new `Document` / `Output` split and concrete paged/HTML document types.
- Updates query export for the new `eval_string` signature and uses
`SpanMode::Uniform(Span::detached())` for selector strings that do not
come from a `.typ` source range.
- Updates paged document access, output introspector access, debug
location typing, preview/outline consumers, and HTML root mutation to
the new accessor-based APIs.
- Preserves original compiled document metadata for merged PNG/SVG
exports with `doc.info().clone()` while still constructing a temporary
document from selected pages.
- Updates typlite SVG embedding to forward real `HtmlFrame` metadata
when available and use neutral standalone-frame defaults when only a
bare `Frame` is available.
- Updates `World::today` for Typst duration offsets while keeping
existing cached `now` initialization in place; only the
duration-to-second offset conversion is factored out.
- Refreshes the minimal `Cargo.lock` metadata needed by the new
`typst-layout` dependency path.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
This PR is part of the Typst 0.15 cleanup stack. It sits on top of the
dependency/toolchain group and covers the first world/document output
API adaptation slice.

- [`typst/typst#7964` Bundle
export](typst/typst#7964) splits document output
into target-specific APIs.
- Tinymist now works with `typst_layout::PagedDocument`,
`typst_html::HtmlDocument`, `typst::model::Document`, and
`typst::foundations::Output` instead of relying on the old broad
document surface.
- Document fields are private; callers need accessors such as `pages()`,
`info()`, `introspector()`, and `root_mut()`.
- Document introspection changes around `typst/typst@7d2edbdb3` move
consumers toward the target document's output introspector.
- `DocumentInfo` is the compiled-document metadata payload (`title`,
`author`, `description`, `keywords`, `date`, `locale`). Typst populates
it while creating the target document from document/text styles, not
from finished `Page` or `Frame` values.
- HTML/SVG conversion now goes through the bundle-aware `svg_in_html`
path with a `LateLinkResolver`.
- [`typst/typst#7691`](typst/typst#7691) changes
`World::today` from an hour offset to
`Option<typst::foundations::Duration>`.
- `typst/typst@acc3fed51` moves paged positions to
`typst::introspection::PagedPosition`.
- Typst 0.15 also requires protected engine introspection through
`typst::utils::Protected`.

- Adapts `tinymist-std`, `tinymist-world`, and `tinymist-task` to the
new `Document` / `Output` split and concrete paged/HTML document types.
- Updates query export for the new `eval_string` signature and uses
`SpanMode::Uniform(Span::detached())` for selector strings that do not
come from a `.typ` source range.
- Updates paged document access, output introspector access, debug
location typing, preview/outline consumers, and HTML root mutation to
the new accessor-based APIs.
- Preserves original compiled document metadata for merged PNG/SVG
exports with `doc.info().clone()` while still constructing a temporary
document from selected pages.
- Updates typlite SVG embedding to forward real `HtmlFrame` metadata
when available and use neutral standalone-frame defaults when only a
bare `Frame` is available.
- Updates `World::today` for Typst duration offsets while keeping
existing cached `now` initialization in place; only the
duration-to-second offset conversion is factored out.
- Refreshes the minimal `Cargo.lock` metadata needed by the new
`typst-layout` dependency path.

---------

Co-authored-by: paran3xus <[email protected]>
Myriad-Dreamin added a commit to Myriad-Dreamin/tinymist that referenced this pull request Jun 15, 2026
This PR is part of the Typst 0.15 cleanup stack. It sits on top of the
dependency/toolchain group and covers the first world/document output
API adaptation slice.

- [`typst/typst#7964` Bundle
export](typst/typst#7964) splits document output
into target-specific APIs.
- Tinymist now works with `typst_layout::PagedDocument`,
`typst_html::HtmlDocument`, `typst::model::Document`, and
`typst::foundations::Output` instead of relying on the old broad
document surface.
- Document fields are private; callers need accessors such as `pages()`,
`info()`, `introspector()`, and `root_mut()`.
- Document introspection changes around `typst/typst@7d2edbdb3` move
consumers toward the target document's output introspector.
- `DocumentInfo` is the compiled-document metadata payload (`title`,
`author`, `description`, `keywords`, `date`, `locale`). Typst populates
it while creating the target document from document/text styles, not
from finished `Page` or `Frame` values.
- HTML/SVG conversion now goes through the bundle-aware `svg_in_html`
path with a `LateLinkResolver`.
- [`typst/typst#7691`](typst/typst#7691) changes
`World::today` from an hour offset to
`Option<typst::foundations::Duration>`.
- `typst/typst@acc3fed51` moves paged positions to
`typst::introspection::PagedPosition`.
- Typst 0.15 also requires protected engine introspection through
`typst::utils::Protected`.

- Adapts `tinymist-std`, `tinymist-world`, and `tinymist-task` to the
new `Document` / `Output` split and concrete paged/HTML document types.
- Updates query export for the new `eval_string` signature and uses
`SpanMode::Uniform(Span::detached())` for selector strings that do not
come from a `.typ` source range.
- Updates paged document access, output introspector access, debug
location typing, preview/outline consumers, and HTML root mutation to
the new accessor-based APIs.
- Preserves original compiled document metadata for merged PNG/SVG
exports with `doc.info().clone()` while still constructing a temporary
document from selected pages.
- Updates typlite SVG embedding to forward real `HtmlFrame` metadata
when available and use neutral standalone-frame defaults when only a
bare `Frame` is available.
- Updates `World::today` for Typst duration offsets while keeping
existing cached `now` initialization in place; only the
duration-to-second offset conversion is factored out.
- Refreshes the minimal `Cargo.lock` metadata needed by the new
`typst-layout` dependency path.

---------

Co-authored-by: paran3xus <[email protected]>
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crate Issues with using Typst as a library for other apps interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. scripting About Typst's coding capabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support half-hour timezones

2 participants