Skip to main content

Date

Struct Date 

Source
pub struct Date {
    pub year: i32,
    pub month: u8,
    pub day: u8,
}
Expand description

A calendar day.

Fields§

§year: i32

The year.

§month: u8

1 to 12.

§day: u8

Day of the month, from 1.

Implementations§

Source§

impl Date

Source

pub const fn new(year: i32, month: u8, day: u8) -> Self

A date from year, month (1 to 12) and day (from 1).

Source

pub fn days(self) -> i64

Days since 1970-01-01; negative before it.

Examples found in repository?
examples/gallery.rs (line 1293)
1248pub fn app() -> App {
1249    App {
1250        name: "Gallery".into(),
1251        presses: 0,
1252        page: 0,
1253        room: 0,
1254        filter: String::new(),
1255        notes: String::new(),
1256        renaming: None,
1257        light: false,
1258        contrast: false,
1259        system: false,
1260        spacing: 1,
1261        ticked: false,
1262        on: true,
1263        folded_open: true,
1264        second: false,
1265        level: 72.0,
1266        bold: false,
1267        starred: true,
1268        span: 1,
1269        busy: false,
1270        from: 20.0,
1271        to: 70.0,
1272        followed: 0,
1273        finding: false,
1274        colour: 6,
1275        wanted: String::new(),
1276        picture: None,
1277        photo: None,
1278        drawings: None,
1279        animation: None,
1280        playing: false,
1281        // `TAUT_FONT=some.ttf` writes the whole window with that font, in place of the system's.
1282        letters: std::env::var_os("TAUT_FONT").and_then(|file| std::fs::read(file).ok()).and_then(FontFile::read),
1283        place: String::new(),
1284        shape: None,
1285        selected_row: 1,
1286        tree_open: [true, true],
1287        amount: 4.0,
1288        off: true,
1289        count: 12,
1290        day: Date::today(),
1291        alarm: Time::new(7, 30, 0),
1292        meeting: (Date::today(), Time::new(14, 0, 0)),
1293        away: (Date::today(), Date::from_days(Date::today().days() + 6)),
1294        marked: 3.0,
1295        zoom: 100.0,
1296        within: 2.5,
1297        fruit: "pear",
1298        faint: true,
1299        hide: false,
1300        tint: Theme::dark().accent,
1301        drag_lists: [vec!["Apples", "Pears", "Plums"], vec!["Bread"]],
1302        table: Table { frozen: 1, ..Default::default() },
1303        selection: Selection::default(),
1304        files: (0..5000u32).map(|n| (format!("file {n:04}"), n * 7919 % 4096 + 1, ["text", "picture", "sound", "folder"][n as usize * 5 % 4])).collect(),
1305        tools: Panel { open: false, ..Panel::new(520.0, 150.0, 300.0, 220.0) },
1306        code: CodeEditor::new(include_str!("gallery.rs"), &Syntax::RUST),
1307        lamp: Lamp { name: "Desk".into(), power: 40.0, on: true, kind: LampKind::Spot, tint: Color::rgb(0xffcf7a), rooms: vec!["Study".into(), "Hall".into()] },
1308        inspector: Inspector::default(),
1309        beside: SecondWindow { open: false, ..SecondWindow::new(380.0, 240.0) },
1310        file_dialog: FileDialog::default(),
1311        dock: Dock::of(&["Files"]).beside(Dock::of(&["Editor", "Preview"]).above(Dock::of(&["Log"]), 0.7), 0.25),
1312        step: 2,
1313        results: 0,
1314        query: String::new(),
1315        topics: vec!["mountains".into(), "walks".into()],
1316        topic: String::new(),
1317        stars: 3.5,
1318        face: None,
1319        liked: [true, false],
1320        loading: true,
1321        banner: true,
1322        styles: [true, false, false],
1323        section: Some(0),
1324        slices: ChartView::default(),
1325        view: ChartView::default(),
1326        dots: [0, 1, 2, 3].map(|row| (0..80u32).map(|n| chance(n + 80 * row)).collect()),
1327        live: false,
1328        load: (0..600).map(|nth| 0.5 + (nth as f32 / 40.0).sin() * 0.2).collect(),
1329        fed: taut::platform::unix_time(),
1330        folders: TreeView::default(),
1331        writing: Markdown::parse(WRITING),
1332    }
1333}
Source

pub fn from_days(days: i64) -> Self

The date days after 1970-01-01. Beyond the representable years, the first or last.

Examples found in repository?
examples/file_browser.rs (line 120)
118fn entry_of(entry: &std::fs::DirEntry) -> Option<Entry> {
119    let about = entry.metadata().ok()?;
120    let days = about.modified().ok()?.duration_since(UNIX_EPOCH).ok().map(|since| Date::from_days((since.as_secs() / 86_400) as i64));
121    Some(Entry { name: entry.file_name().to_string_lossy().into_owned(), folder: about.is_dir(), size: if about.is_dir() { 0 } else { about.len() }, changed: days })
122}
More examples
Hide additional examples
examples/gallery.rs (line 1293)
1248pub fn app() -> App {
1249    App {
1250        name: "Gallery".into(),
1251        presses: 0,
1252        page: 0,
1253        room: 0,
1254        filter: String::new(),
1255        notes: String::new(),
1256        renaming: None,
1257        light: false,
1258        contrast: false,
1259        system: false,
1260        spacing: 1,
1261        ticked: false,
1262        on: true,
1263        folded_open: true,
1264        second: false,
1265        level: 72.0,
1266        bold: false,
1267        starred: true,
1268        span: 1,
1269        busy: false,
1270        from: 20.0,
1271        to: 70.0,
1272        followed: 0,
1273        finding: false,
1274        colour: 6,
1275        wanted: String::new(),
1276        picture: None,
1277        photo: None,
1278        drawings: None,
1279        animation: None,
1280        playing: false,
1281        // `TAUT_FONT=some.ttf` writes the whole window with that font, in place of the system's.
1282        letters: std::env::var_os("TAUT_FONT").and_then(|file| std::fs::read(file).ok()).and_then(FontFile::read),
1283        place: String::new(),
1284        shape: None,
1285        selected_row: 1,
1286        tree_open: [true, true],
1287        amount: 4.0,
1288        off: true,
1289        count: 12,
1290        day: Date::today(),
1291        alarm: Time::new(7, 30, 0),
1292        meeting: (Date::today(), Time::new(14, 0, 0)),
1293        away: (Date::today(), Date::from_days(Date::today().days() + 6)),
1294        marked: 3.0,
1295        zoom: 100.0,
1296        within: 2.5,
1297        fruit: "pear",
1298        faint: true,
1299        hide: false,
1300        tint: Theme::dark().accent,
1301        drag_lists: [vec!["Apples", "Pears", "Plums"], vec!["Bread"]],
1302        table: Table { frozen: 1, ..Default::default() },
1303        selection: Selection::default(),
1304        files: (0..5000u32).map(|n| (format!("file {n:04}"), n * 7919 % 4096 + 1, ["text", "picture", "sound", "folder"][n as usize * 5 % 4])).collect(),
1305        tools: Panel { open: false, ..Panel::new(520.0, 150.0, 300.0, 220.0) },
1306        code: CodeEditor::new(include_str!("gallery.rs"), &Syntax::RUST),
1307        lamp: Lamp { name: "Desk".into(), power: 40.0, on: true, kind: LampKind::Spot, tint: Color::rgb(0xffcf7a), rooms: vec!["Study".into(), "Hall".into()] },
1308        inspector: Inspector::default(),
1309        beside: SecondWindow { open: false, ..SecondWindow::new(380.0, 240.0) },
1310        file_dialog: FileDialog::default(),
1311        dock: Dock::of(&["Files"]).beside(Dock::of(&["Editor", "Preview"]).above(Dock::of(&["Log"]), 0.7), 0.25),
1312        step: 2,
1313        results: 0,
1314        query: String::new(),
1315        topics: vec!["mountains".into(), "walks".into()],
1316        topic: String::new(),
1317        stars: 3.5,
1318        face: None,
1319        liked: [true, false],
1320        loading: true,
1321        banner: true,
1322        styles: [true, false, false],
1323        section: Some(0),
1324        slices: ChartView::default(),
1325        view: ChartView::default(),
1326        dots: [0, 1, 2, 3].map(|row| (0..80u32).map(|n| chance(n + 80 * row)).collect()),
1327        live: false,
1328        load: (0..600).map(|nth| 0.5 + (nth as f32 / 40.0).sin() * 0.2).collect(),
1329        fed: taut::platform::unix_time(),
1330        folders: TreeView::default(),
1331        writing: Markdown::parse(WRITING),
1332    }
1333}
Source

pub fn weekday(self) -> u8

Day of the week: 0 Monday to 6 Sunday.

Source

pub fn month_length(self) -> u8

Days in its month.

Source

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

The same day months later (earlier, if negative); the month’s last day if it has fewer.

Source

pub fn today() -> Self

Today, in local time.

Examples found in repository?
examples/gallery.rs (line 1290)
1248pub fn app() -> App {
1249    App {
1250        name: "Gallery".into(),
1251        presses: 0,
1252        page: 0,
1253        room: 0,
1254        filter: String::new(),
1255        notes: String::new(),
1256        renaming: None,
1257        light: false,
1258        contrast: false,
1259        system: false,
1260        spacing: 1,
1261        ticked: false,
1262        on: true,
1263        folded_open: true,
1264        second: false,
1265        level: 72.0,
1266        bold: false,
1267        starred: true,
1268        span: 1,
1269        busy: false,
1270        from: 20.0,
1271        to: 70.0,
1272        followed: 0,
1273        finding: false,
1274        colour: 6,
1275        wanted: String::new(),
1276        picture: None,
1277        photo: None,
1278        drawings: None,
1279        animation: None,
1280        playing: false,
1281        // `TAUT_FONT=some.ttf` writes the whole window with that font, in place of the system's.
1282        letters: std::env::var_os("TAUT_FONT").and_then(|file| std::fs::read(file).ok()).and_then(FontFile::read),
1283        place: String::new(),
1284        shape: None,
1285        selected_row: 1,
1286        tree_open: [true, true],
1287        amount: 4.0,
1288        off: true,
1289        count: 12,
1290        day: Date::today(),
1291        alarm: Time::new(7, 30, 0),
1292        meeting: (Date::today(), Time::new(14, 0, 0)),
1293        away: (Date::today(), Date::from_days(Date::today().days() + 6)),
1294        marked: 3.0,
1295        zoom: 100.0,
1296        within: 2.5,
1297        fruit: "pear",
1298        faint: true,
1299        hide: false,
1300        tint: Theme::dark().accent,
1301        drag_lists: [vec!["Apples", "Pears", "Plums"], vec!["Bread"]],
1302        table: Table { frozen: 1, ..Default::default() },
1303        selection: Selection::default(),
1304        files: (0..5000u32).map(|n| (format!("file {n:04}"), n * 7919 % 4096 + 1, ["text", "picture", "sound", "folder"][n as usize * 5 % 4])).collect(),
1305        tools: Panel { open: false, ..Panel::new(520.0, 150.0, 300.0, 220.0) },
1306        code: CodeEditor::new(include_str!("gallery.rs"), &Syntax::RUST),
1307        lamp: Lamp { name: "Desk".into(), power: 40.0, on: true, kind: LampKind::Spot, tint: Color::rgb(0xffcf7a), rooms: vec!["Study".into(), "Hall".into()] },
1308        inspector: Inspector::default(),
1309        beside: SecondWindow { open: false, ..SecondWindow::new(380.0, 240.0) },
1310        file_dialog: FileDialog::default(),
1311        dock: Dock::of(&["Files"]).beside(Dock::of(&["Editor", "Preview"]).above(Dock::of(&["Log"]), 0.7), 0.25),
1312        step: 2,
1313        results: 0,
1314        query: String::new(),
1315        topics: vec!["mountains".into(), "walks".into()],
1316        topic: String::new(),
1317        stars: 3.5,
1318        face: None,
1319        liked: [true, false],
1320        loading: true,
1321        banner: true,
1322        styles: [true, false, false],
1323        section: Some(0),
1324        slices: ChartView::default(),
1325        view: ChartView::default(),
1326        dots: [0, 1, 2, 3].map(|row| (0..80u32).map(|n| chance(n + 80 * row)).collect()),
1327        live: false,
1328        load: (0..600).map(|nth| 0.5 + (nth as f32 / 40.0).sin() * 0.2).collect(),
1329        fed: taut::platform::unix_time(),
1330        folders: TreeView::default(),
1331        writing: Markdown::parse(WRITING),
1332    }
1333}

Trait Implementations§

Source§

impl Clone for Date

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Date

Source§

impl Debug for Date

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Date

1970-01-01.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Date

ISO 8601, which sorts: 2026-11-30. For the user’s format, see ui.format_date(date).

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Date

Source§

impl Hash for Date

Source§

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

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
Source§

impl Inspect for Date

Source§

const ROW: bool = true

A single-row value with an editor beside its name; not a heading.
Source§

fn part(&mut self, row: &mut InspectorRow<'_>) -> Response

For a single-row value: its editor, described beside the name; changed is set when the user edits it. For a heading: what shows beside its name (a list shows its length).
Source§

fn hashed(&self) -> u64

A hash of the value: different values give different hashes. With several values inspected it shows where they differ; compared with the initial state, what was edited. (A struct’s is 0: its rows are compared one by one.)
Source§

fn fields(&mut self, fields: &mut Fields<'_>)

For a heading: lists its children, each with fields.field(..), in display order.
Source§

fn mixed(&mut self, row: &mut InspectorRow<'_>) -> Response

The same where the inspected values differ: an editor showing that they do; when edited (changed), every value is set as the first then is. By default, a “—” box that does that when pressed.
Source§

impl Ord for Date

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Date

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Date

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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
Source§

impl StructuralPartialEq for Date

Auto Trait Implementations§

§

impl Forget for Date

§

impl Freeze for Date

§

impl Move for Date

§

impl RefUnwindSafe for Date

§

impl Send for Date

§

impl Sync for Date

§

impl Unpin for Date

§

impl UnsafeUnpin for Date

§

impl UnwindSafe for Date

Blanket Implementations§

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<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
Source§

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

Source§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.