FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    DateTime

    struct · ferroui-base · v0.5.0

    struct DateTime
    

    A date and time of day with a resolution of 100 nanoseconds.

    Equality, ordering and hashing consider the ticks only; the kind is ignored, as in .NET.

    View source

    Members

    MIN_VALUE

    const MIN_VALUE: DateTime
    

    The smallest value, 0001-01-01T00:00:00.

    Source

    MAX_VALUE

    const MAX_VALUE: DateTime
    

    The largest value, 9999-12-31T23:59:59.9999999.

    Source

    UNIX_EPOCH

    const UNIX_EPOCH: DateTime
    

    1970-01-01T00:00:00 UTC.

    Source

    new

    fn new(year: i32, month: i32, day: i32) -> DateTime
    

    The date year-month-day at midnight, of unspecified kind. Panics when the arguments do not name a date in 0001..=9999.

    Source

    new_with_time

    fn new_with_time(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32) -> DateTime
    

    The given date and time of day, of unspecified kind. Panics when the arguments do not name a valid date and time.

    Source

    new_with_millisecond

    fn new_with_millisecond(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32, millisecond: i32) -> DateTime
    

    The given date and time of day with milliseconds, of unspecified kind. Panics when the arguments do not name a valid date and time.

    Source

    try_new

    fn try_new(year: i32, month: i32, day: i32) -> Option<DateTime>
    

    The date year-month-day at midnight; None when the arguments do not name a date in 0001..=9999.

    Source

    try_new_with_time

    fn try_new_with_time(year: i32, month: i32, day: i32, hour: i32, minute: i32, second: i32) -> Option<DateTime>
    

    The given date and time of day; None when the arguments do not name a valid date and time.

    Source

    from_ticks

    const fn from_ticks(ticks: i64) -> DateTime
    

    The value with the given number of ticks, of unspecified kind. Panics when ticks is outside the range of the type.

    Source

    from_ticks_kind

    const fn from_ticks_kind(ticks: i64, kind: DateTimeKind) -> DateTime
    

    The value with the given number of ticks and kind. Panics when ticks is outside the range of the type.

    Source

    try_from_ticks

    const fn try_from_ticks(ticks: i64, kind: DateTimeKind) -> Option<DateTime>
    

    The value with the given number of ticks; None when out of range.

    Source

    specify_kind

    const fn specify_kind(self: Self, kind: DateTimeKind) -> DateTime
    

    The same ticks with another kind (.NET DateTime.SpecifyKind).

    Source

    set_utc_now_provider

    fn set_utc_now_provider(provider: Option<UtcNowProvider>) -> Option<UtcNowProvider>
    

    Installs (or with None removes) the source of the current instant of the current thread and returns the previous one. Tests use it to pin system_time_now, now, utc_now and today.

    Source

    utc_now

    fn utc_now() -> DateTime
    

    The current date and time in UTC (kind DateTimeKind::Utc): the instant of system_time_now as a date. An instant outside of the years 1 to 9999 is MIN_VALUE or MAX_VALUE.

    Source

    now

    fn now() -> DateTime
    

    The current date and time in local time (kind DateTimeKind::Local).

    Source

    today

    fn today() -> DateTime
    

    The current local date at midnight (kind DateTimeKind::Local).

    Source

    ticks

    const fn ticks(self: Self) -> i64
    

    The number of ticks since 0001-01-01T00:00:00.

    Source

    kind

    const fn kind(self: Self) -> DateTimeKind
    

    The kind of time.

    Source

    date

    const fn date(self: Self) -> DateTime
    

    The date at midnight, with the same kind.

    Source

    time_of_day

    const fn time_of_day(self: Self) -> SignedDuration
    

    The time elapsed since midnight.

    Source

    year

    fn year(self: Self) -> i32
    

    The year, 1..=9999.

    Source

    month

    fn month(self: Self) -> i32
    

    The month, 1..=12.

    Source

    day

    fn day(self: Self) -> i32
    

    The day of the month, 1..=31.

    Source

    day_of_year

    fn day_of_year(self: Self) -> i32
    

    The day of the year, 1..=366.

    Source

    day_of_week

    fn day_of_week(self: Self) -> DayOfWeek
    

    The day of the week.

    Source

    hour

    const fn hour(self: Self) -> i32
    

    The hour, 0..=23.

    Source

    minute

    const fn minute(self: Self) -> i32
    

    The minute, 0..=59.

    Source

    second

    const fn second(self: Self) -> i32
    

    The second, 0..=59.

    Source

    millisecond

    const fn millisecond(self: Self) -> i32
    

    The millisecond, 0..=999.

    Source

    is_leap_year

    fn is_leap_year(year: i32) -> bool
    

    Whether year (1..=9999) is a leap year. Panics for other years.

    Source

    days_in_month

    fn days_in_month(year: i32, month: i32) -> i32
    

    The number of days of month in year. Panics when the month is not 1..=12 or the year not 1..=9999.

    Source

    try_add_ticks

    const fn try_add_ticks(self: Self, ticks: i64) -> Option<DateTime>
    

    The value ticks later; None when out of range.

    Source

    add_ticks

    fn add_ticks(self: Self, ticks: i64) -> DateTime
    

    The value ticks later. Panics when out of range.

    Source

    add

    fn add(self: Self, value: SignedDuration) -> DateTime
    

    The value value later. Panics when out of range.

    Source

    try_add

    fn try_add(self: Self, value: SignedDuration) -> Option<DateTime>
    

    The value value later; None when out of range.

    Source

    subtract

    fn subtract(self: Self, value: SignedDuration) -> DateTime
    

    The value value earlier. Panics when out of range.

    Source

    subtract_date_time

    fn subtract_date_time(self: Self, other: DateTime) -> SignedDuration
    

    The interval from other to this value.

    Source

    try_add_days

    fn try_add_days(self: Self, value: f64) -> Option<DateTime>
    

    The value value (whole and fractional) days later; None when out of range.

    Source

    add_days

    fn add_days(self: Self, value: f64) -> DateTime
    

    The value value (whole and fractional) days later. Panics when out of range.

    Source

    try_add_months

    fn try_add_months(self: Self, months: i32) -> Option<DateTime>
    

    The value months months later (earlier when negative). The day is kept, or becomes the last day of the resulting month when that month is shorter. None when months is not in -120000..=120000 or the result is out of range.

    Source

    add_months

    fn add_months(self: Self, months: i32) -> DateTime
    

    The value months months later; see try_add_months. Panics when months or the result is out of range.

    Source

    try_add_years

    fn try_add_years(self: Self, years: i32) -> Option<DateTime>
    

    The value years years later (earlier when negative); February 29 becomes February 28 in a year that is not a leap year. None when years is not in -10000..=10000 or the result is out of range.

    Source

    add_years

    fn add_years(self: Self, years: i32) -> DateTime
    

    The value years years later; see try_add_years. Panics when years or the result is out of range.

    Source

    compare

    fn compare(t1: DateTime, t2: DateTime) -> i32
    

    Compares two values by their ticks: negative, zero or positive (.NET DateTime.Compare, which returns -1, 0 or 1).

    Source

    compare_to

    fn compare_to(self: Self, other: DateTime) -> i32
    

    Compares this value with other: -1, 0 or 1.

    Source

    to_universal_time

    fn to_universal_time(self: Self) -> DateTime
    

    The value converted to UTC. A value of unspecified kind is taken as local time. A result outside the range is clamped to it.

    Source

    to_local_time

    fn to_local_time(self: Self) -> DateTime
    

    The value converted to local time. A value of unspecified kind is taken as UTC. A result outside the range is clamped to it.

    Source

    to_string_format

    fn to_string_format(self: Self, format: &str, provider: &impl DateTimeFormatProvider + ?Sized) -> String
    

    Formats with a standard or custom .NET date and time format string and the conventions of provider (a CultureInfo or a DateTimeFormatInfo). An empty format is the general format "G". Panics when the format string is invalid (.NET throws FormatException).

    Source

    try_to_string_format

    fn try_to_string_format(self: Self, format: &str, provider: &impl DateTimeFormatProvider + ?Sized) -> Result<String, FormatError>
    

    Like to_string_format, but gives the error of an invalid format string.

    Source

    to_string_with

    fn to_string_with(self: Self, format: &str) -> String
    

    Formats with a format string and the conventions of the current culture (.NET ToString(string)). Panics when the format is invalid.

    Source

    to_string_provider

    fn to_string_provider(self: Self, provider: &impl DateTimeFormatProvider + ?Sized) -> String
    

    Formats with the general format "G" and the conventions of provider (.NET ToString(IFormatProvider)).

    Source

    parse

    fn parse(text: &str, provider: &impl DateTimeFormatProvider + ?Sized) -> Result<DateTime, FormatError>
    

    Parses a date and time written in the conventions of provider (.NET DateTime.Parse(string, IFormatProvider)).

    This is not the heuristic parser of .NET. It is checked against results recorded from .NET (date_time_net_data.rs, tables PARSE, PARSE_ROUND_TRIP and PARSE_STYLES) for the invariant culture, en, en-US and en-GB, which covers what the date picker feeds it: the text it writes itself with the short and the long date pattern of the culture, and typed dates of these forms:

    • numeric dates with /, -, . or spaces in the order of the short date pattern; a year of three or more digits written first gives year-month-day; two-digit years are 1950..=2049;
    • month names and abbreviations (of the culture or English), with the day before or after and an optional, matching day name;
    • a month and a year alone (the first of the month), a month and a day alone (the current year);
    • an offset from UTC (Z, GMT, a signed hh:mm, hhmm or h[h]) after the time or after a date without a time; the result is then the local time of that instant;
    • ISO 8601 yyyy-MM-ddTHH:mm:ss[.fffffff] with Z or an offset, the sortable, universal sortable and RFC 1123 formats;
    • a time H:mm[:ss[.fffffff]] with an optional designator before or after the date, or alone (the current date).

    Everything else is rejected, and has not been compared with .NET beyond the recorded rows: other time zone names than GMT and Z (.NET rejects UTC too), era names, and a two-number date that is only valid in the order the culture does not use. The genitive month names of a culture that has them (DateTimeFormatInfo::month_genitive_names) are read beside the plain ones, as in .NET.

    Source

    parse_with_styles

    fn parse_with_styles(text: &str, provider: &impl DateTimeFormatProvider + ?Sized, styles: DateTimeStyles) -> Result<DateTime, FormatError>
    

    Parses a date and time written in the conventions of provider (.NET DateTime.Parse(string, IFormatProvider, DateTimeStyles)).

    Source

    try_parse

    fn try_parse(text: &str, provider: &impl DateTimeFormatProvider + ?Sized, styles: DateTimeStyles) -> Option<DateTime>
    

    Parses like parse_with_styles; None on failure (.NET DateTime.TryParse).

    Source

    parse_exact

    fn parse_exact(text: &str, format: &str, provider: &impl DateTimeFormatProvider + ?Sized) -> Result<DateTime, FormatError>
    

    Parses a date and time that has to match format exactly (.NET DateTime.ParseExact(string, string, IFormatProvider)).

    Source

    parse_exact_with_styles

    fn parse_exact_with_styles(text: &str, format: &str, provider: &impl DateTimeFormatProvider + ?Sized, styles: DateTimeStyles) -> Result<DateTime, FormatError>
    

    Parses a date and time that has to match format exactly (.NET DateTime.ParseExact(string, string, IFormatProvider, DateTimeStyles)).

    Source

    parse_exact_multiple

    fn parse_exact_multiple(text: &str, formats: &[&str], provider: &impl DateTimeFormatProvider + ?Sized, styles: DateTimeStyles) -> Result<DateTime, FormatError>
    

    Parses a date and time that has to match one of formats exactly; the first format that matches wins (.NET DateTime.ParseExact(string, string[], ..)).

    Source

    try_parse_exact

    fn try_parse_exact(text: &str, format: &str, provider: &impl DateTimeFormatProvider + ?Sized, styles: DateTimeStyles) -> Option<DateTime>
    

    Like parse_exact_with_styles; None on failure (.NET DateTime.TryParseExact(string, string, ..)).

    Source

    try_parse_exact_multiple

    fn try_parse_exact_multiple(text: &str, formats: &[&str], provider: &impl DateTimeFormatProvider + ?Sized, styles: DateTimeStyles) -> Option<DateTime>
    

    Like parse_exact_multiple; None on failure (.NET DateTime.TryParseExact(string, string[], ..)).

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • ResourceKeyObject
    • PropertyValue
    • AnyValue
    • ClassDefaults
    • Borrow<T>
    • BorrowMut<T>
    • CloneToUninit
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ToOwned
    • ToString
    • ErasedDestructor
    • IntoEither
    • Clone
    • Copy
    • Default
    • PartialEq
    • Eq
    • PartialOrd
    • Ord
    • Hash
    • Add<SignedDuration>
    • Sub<SignedDuration>
    • Sub
    • AddAssign<SignedDuration>
    • SubAssign<SignedDuration>
    • Display
    • Debug
    • FromStr
    • TryFrom<SystemTime>
    • TryFrom<DateTime>
    • From<DateTime>
    • MarkupTyped
    • ValueTypeRegistration

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.