Skip to content

Make "date" also accept the date(time) data type #37

@rugk

Description

@rugk

Background

I am a total newbie to typst, so just as #32 I am again trying to get a letter for a date "today". I guess, that should be quite a common thing, as the issues also show?

I am using the VSCode/VScodium TinyMist extension.

Same as #36 but here is a related solution, that, IMHO, though could be implemented both.

My aim

I actually found https://typst.app/docs/reference/foundations/datetime/ when searching for a solution to my problem. (actually I did the first try below before but that was just because I could not read docs, I should have been able to find the today() method.

This here would have been my most intuitive/proper solution to solve this:

#show: letter-simple.with(
  // ...
  date: datetime.today(),
  // ...
)

Surprisingly (in a bad way) my extension does not show any red (squiggle) error message, but the compilation shows "red" (which I subsequently learned to interpret as a compiler error, it appears)…
Image

I am still not quite sure how/where I am supposed to find the actual error in this case, but I found this:

INFO  tinymist_project::compiler] ***/main.typ: compilation failed with 2 warnings and errors in 1.4525ms

(Yes even filtering for warn did not turn anything up – I have no idea.)

My first try

I thus tried this then:

#show: letter-simple.with(
  // ...
  date: datetime(2025, 12, 01),
  // ...
)

with a very confusing error message:

unexpected argument - typst

Image

My second try

Given my OOP mind, I tried this, which was not any better:

#show: letter-simple.with(
  // ...
  date: new datetime(2025, 12, 01),
  // ...
)

expected comma - typst

Image

Assumed problem

I guess this because the data type is content | none and datetime is not included there?

Image

Proposal

I mean, what would not make more sense than to allow passing a date (or datetime I am unsure whether time should be allowed, but probably also okay) to a propery named date that is used for displaying a date?
At least optionally?

I mean I agree a string is nice too, but a date and then have it auto-format would be cool, would not it? Yeah, maybe it needs localization then (though this template includes/sets #set text(lang: "de", already, so this seems possible) and a date formatting option possibly (or not), but yeah?

As a new user for this otherwise awesome template, I see this as the only "flaw", currently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions