tinymist_std::typst::foundations

Enum Datetime

pub enum Datetime {
    Date(Date),
    Time(Time),
    Datetime(PrimitiveDateTime),
}
Expand description

Represents a date, a time, or a combination of both.

Can be created by either specifying a custom datetime using this type’s constructor function or getting the current date with datetime.today.

§Example

#let date = datetime(
  year: 2020,
  month: 10,
  day: 4,
)

#date.display() \
#date.display(
  "y:[year repr:last_two]"
)

#let time = datetime(
  hour: 18,
  minute: 2,
  second: 23,
)

#time.display() \
#time.display(
  "h:[hour repr:12][period]"
)

§Datetime and Duration

You can get a [duration] by subtracting two datetime:

#let first-of-march = datetime(day: 1, month: 3, year: 2024)
#let first-of-jan = datetime(day: 1, month: 1, year: 2024)
#let distance = first-of-march - first-of-jan
#distance.hours()

You can also add/subtract a datetime and a duration to retrieve a new, offset datetime:

#let date = datetime(day: 1, month: 3, year: 2024)
#let two-days = duration(days: 2)
#let two-days-earlier = date - two-days
#let two-days-later = date + two-days

#date.display() \
#two-days-earlier.display() \
#two-days-later.display()

§Format

You can specify a customized formatting using the display method. The format of a datetime is specified by providing components with a specified number of modifiers. A component represents a certain part of the datetime that you want to display, and with the help of modifiers you can define how you want to display that component. In order to display a component, you wrap the name of the component in square brackets (e.g. [[year]] will display the year). In order to add modifiers, you add a space after the component name followed by the name of the modifier, a colon and the value of the modifier (e.g. [[month repr:short]] will display the short representation of the month).

The possible combination of components and their respective modifiers is as follows:

  • year: Displays the year of the datetime.
    • padding: Can be either zero, space or none. Specifies how the year is padded.
    • repr Can be either full in which case the full year is displayed or last_two in which case only the last two digits are displayed.
    • sign: Can be either automatic or mandatory. Specifies when the sign should be displayed.
  • month: Displays the month of the datetime.
    • padding: Can be either zero, space or none. Specifies how the month is padded.
    • repr: Can be either numerical, long or short. Specifies if the month should be displayed as a number or a word. Unfortunately, when choosing the word representation, it can currently only display the English version. In the future, it is planned to support localization.
  • day: Displays the day of the datetime.
    • padding: Can be either zero, space or none. Specifies how the day is padded.
  • week_number: Displays the week number of the datetime.
    • padding: Can be either zero, space or none. Specifies how the week number is padded.
    • repr: Can be either ISO, sunday or monday. In the case of ISO, week numbers are between 1 and 53, while the other ones are between 0 and 53.
  • weekday: Displays the weekday of the date.
    • repr Can be either long, short, sunday or monday. In the case of long and short, the corresponding English name will be displayed (same as for the month, other languages are currently not supported). In the case of sunday and monday, the numerical value will be displayed (assuming Sunday and Monday as the first day of the week, respectively).
    • one_indexed: Can be either true or false. Defines whether the numerical representation of the week starts with 0 or 1.
  • hour: Displays the hour of the date.
    • padding: Can be either zero, space or none. Specifies how the hour is padded.
    • repr: Can be either 24 or 12. Changes whether the hour is displayed in the 24-hour or 12-hour format.
  • period: The AM/PM part of the hour
    • case: Can be lower to display it in lower case and upper to display it in upper case.
  • minute: Displays the minute of the date.
    • padding: Can be either zero, space or none. Specifies how the minute is padded.
  • second: Displays the second of the date.
    • padding: Can be either zero, space or none. Specifies how the second is padded.

Keep in mind that not always all components can be used. For example, if you create a new datetime with {datetime(year: 2023, month: 10, day: 13)}, it will be stored as a plain date internally, meaning that you cannot use components such as hour or minute, which would only work on datetimes that have a specified time.

Variants§

§

Date(Date)

Representation as a date.

§

Time(Time)

Representation as a time.

§

Datetime(PrimitiveDateTime)

Representation as a combination of date and time.

Implementations§

§

impl Datetime

pub fn from_ymd(year: i32, month: u8, day: u8) -> Option<Datetime>

Create a datetime from year, month, and day.

pub fn from_hms(hour: u8, minute: u8, second: u8) -> Option<Datetime>

Create a datetime from hour, minute, and second.

pub fn from_ymd_hms( year: i32, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Option<Datetime>

Create a datetime from day and time.

pub fn from_toml_dict(dict: &Dict) -> Option<Datetime>

Try to parse a dictionary as a TOML date.

pub fn kind(&self) -> &'static str

Which kind of variant this datetime stores.

§

impl Datetime

pub fn construct( year: Option<i32>, month: Option<Month>, day: Option<u8>, hour: Option<u8>, minute: Option<u8>, second: Option<u8>, ) -> Result<Datetime, EcoString>

Creates a new datetime.

You can specify the [datetime] using a year, month, day, hour, minute, and second.

Note: Depending on which components of the datetime you specify, Typst will store it in one of the following three ways:

  • If you specify year, month and day, Typst will store just a date.
  • If you specify hour, minute and second, Typst will store just a time.
  • If you specify all of year, month, day, hour, minute and second, Typst will store a full datetime.

Depending on how it is stored, the display method will choose a different formatting by default.

#datetime(
  year: 2012,
  month: 8,
  day: 3,
).display()

pub fn today( engine: &mut Engine<'_>, offset: Smart<i64>, ) -> Result<Datetime, EcoString>

Returns the current date.

Today's date is
#datetime.today().display().

pub fn display( &self, pattern: Smart<DisplayPattern>, ) -> Result<EcoString, EcoString>

Displays the datetime in a specified format.

Depending on whether you have defined just a date, a time or both, the default format will be different. If you specified a date, it will be [[year]-[month]-[day]]. If you specified a time, it will be [[hour]:[minute]:[second]]. In the case of a datetime, it will be [[year]-[month]-[day] [hour]:[minute]:[second]].

See the format syntax for more information.

pub fn year(&self) -> Option<i32>

The year if it was specified, or {none} for times without a date.

pub fn month(&self) -> Option<u8>

The month if it was specified, or {none} for times without a date.

pub fn weekday(&self) -> Option<u8>

The weekday (counting Monday as 1) or {none} for times without a date.

pub fn day(&self) -> Option<u8>

The day if it was specified, or {none} for times without a date.

pub fn hour(&self) -> Option<u8>

The hour if it was specified, or {none} for dates without a time.

pub fn minute(&self) -> Option<u8>

The minute if it was specified, or {none} for dates without a time.

pub fn second(&self) -> Option<u8>

The second if it was specified, or {none} for dates without a time.

pub fn ordinal(&self) -> Option<u16>

The ordinal (day of the year), or {none} for times without a date.

Trait Implementations§

§

impl Add<Duration> for Datetime

§

type Output = Datetime

The resulting type after applying the + operator.
§

fn add(self, rhs: Duration) -> <Datetime as Add<Duration>>::Output

Performs the + operation. Read more
§

impl Clone for Datetime

§

fn clone(&self) -> Datetime

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Datetime

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl FromValue for Datetime

§

fn from_value(value: Value) -> Result<Datetime, HintedString>

Try to cast the value into an instance of Self.
§

impl Hash for Datetime

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl IntoValue for Datetime

§

fn into_value(self) -> Value

Cast this type into a value.
§

impl NativeScope for Datetime

§

fn constructor() -> Option<&'static NativeFuncData>

The constructor function for the type, if any.
§

fn scope() -> Scope

Get the associated scope for the type.
§

impl NativeType for Datetime

§

const NAME: &'static str = "datetime"

The type’s name. Read more
§

fn data() -> &'static NativeTypeData

§

fn ty() -> Type

Get the type for the native Rust type.
§

impl PartialEq for Datetime

§

fn eq(&self, other: &Datetime) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialOrd for Datetime

§

fn partial_cmp(&self, other: &Datetime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl Reflect for Datetime

§

fn input() -> CastInfo

Describe what can be cast into this value.
§

fn output() -> CastInfo

Describe what this value can be cast into.
§

fn castable(value: &Value) -> bool

Whether the given value can be converted to T. Read more
§

fn error(found: &Value) -> HintedString

Produce an error message for an unacceptable value type. Read more
§

impl Repr for Datetime

§

fn repr(&self) -> EcoString

Return the debug representation of the value.
§

impl Sub<Duration> for Datetime

§

type Output = Datetime

The resulting type after applying the - operator.
§

fn sub(self, rhs: Duration) -> <Datetime as Sub<Duration>>::Output

Performs the - operation. Read more
§

impl Sub for Datetime

§

type Output = Result<Duration, EcoString>

The resulting type after applying the - operator.
§

fn sub(self, rhs: Datetime) -> <Datetime as Sub>::Output

Performs the - operation. Read more
§

impl Copy for Datetime

§

impl StructuralPartialEq for Datetime

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<S, T> ArcInto<T> for S
where Arc<S>: Into<T>,

Source§

fn arc_into(self: Arc<S>) -> T

Converts Arc<T> into Self.
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CallHasher for T
where T: Hash + ?Sized,

§

fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

Source§

impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<T> Filterable for T

§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
§

impl<T> FromValue<Spanned<Value>> for T
where T: FromValue,

§

fn from_value(value: Spanned<Value>) -> Result<T, HintedString>

Try to cast the value into an instance of Self.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoResult for T
where T: IntoValue,

§

fn into_result(self, _: Span) -> Result<Value, EcoVec<SourceDiagnostic>>

Cast this type into a value.
Source§

impl<T> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,