pub struct ChronoDate { /* private fields */ }
Expand description
ISO 8601 calendar date without timezone. Allows for every proleptic Gregorian date from Jan 1, 262145 BCE to Dec 31, 262143 CE. Also supports the conversion from ISO 8601 ordinal and week date.
ยงCalendar Date
The ISO 8601 calendar date follows the proleptic Gregorian calendar. It is like a normal civil calendar but note some slight differences:
-
Dates before the Gregorian calendarโs inception in 1582 are defined via the extrapolation. Be careful, as historical dates are often noted in the Julian calendar and others and the transition to Gregorian may differ across countries (as late as early 20C).
(Some example: Both Shakespeare from Britain and Cervantes from Spain seemingly died on the same calendar dateโApril 23, 1616โbut in the different calendar. Britain used the Julian calendar at that time, so Shakespeareโs death is later.)
-
ISO 8601 calendars has the year 0, which is 1 BCE (a year before 1 CE). If you need a typical BCE/BC and CE/AD notation for year numbers, use the
Datelike::year_ce
method.
ยงWeek Date
The ISO 8601 week date is a triple of year number, week number and day of the week with the following rules:
-
A week consists of Monday through Sunday, and is always numbered within some year. The week number ranges from 1 to 52 or 53 depending on the year.
-
The week 1 of given year is defined as the first week containing January 4 of that year, or equivalently, the first week containing four or more days in that year.
-
The year number in the week date may not correspond to the actual Gregorian year. For example, January 3, 2016 (Sunday) was on the last (53rd) week of 2015.
Chronoโs date types default to the ISO 8601 calendar date, but
Datelike::iso_week
and Datelike::weekday
methods can be used to get the corresponding
week date.
ยงOrdinal Date
The ISO 8601 ordinal date is a pair of year number and day of the year (โordinalโ). The ordinal number ranges from 1 to 365 or 366 depending on the year. The year number is the same as that of the calendar date.
This is currently the internal format of Chronoโs date types.
Implementationsยง
Sourceยงimpl NaiveDate
impl NaiveDate
Sourcepub const fn from_ymd(year: i32, month: u32, day: u32) -> NaiveDate
๐Deprecated since 0.4.23: use from_ymd_opt()
instead
pub const fn from_ymd(year: i32, month: u32, day: u32) -> NaiveDate
from_ymd_opt()
insteadMakes a new NaiveDate
from the calendar date
(year, month and day).
ยงPanics
Panics if the specified calendar day does not exist, on invalid values for month
or day
,
or if year
is out of range for NaiveDate
.
Sourcepub const fn from_ymd_opt(year: i32, month: u32, day: u32) -> Option<NaiveDate>
pub const fn from_ymd_opt(year: i32, month: u32, day: u32) -> Option<NaiveDate>
Makes a new NaiveDate
from the calendar date
(year, month and day).
ยงErrors
Returns None
if:
- The specified calendar day does not exist (for example 2023-04-31).
- The value for
month
orday
is invalid. year
is out of range forNaiveDate
.
ยงExample
use chrono::NaiveDate;
let from_ymd_opt = NaiveDate::from_ymd_opt;
assert!(from_ymd_opt(2015, 3, 14).is_some());
assert!(from_ymd_opt(2015, 0, 14).is_none());
assert!(from_ymd_opt(2015, 2, 29).is_none());
assert!(from_ymd_opt(-4, 2, 29).is_some()); // 5 BCE is a leap year
assert!(from_ymd_opt(400000, 1, 1).is_none());
assert!(from_ymd_opt(-400000, 1, 1).is_none());
Sourcepub const fn from_yo(year: i32, ordinal: u32) -> NaiveDate
๐Deprecated since 0.4.23: use from_yo_opt()
instead
pub const fn from_yo(year: i32, ordinal: u32) -> NaiveDate
from_yo_opt()
insteadMakes a new NaiveDate
from the ordinal date
(year and day of the year).
ยงPanics
Panics if the specified ordinal day does not exist, on invalid values for ordinal
, or if
year
is out of range for NaiveDate
.
Sourcepub const fn from_yo_opt(year: i32, ordinal: u32) -> Option<NaiveDate>
pub const fn from_yo_opt(year: i32, ordinal: u32) -> Option<NaiveDate>
Makes a new NaiveDate
from the ordinal date
(year and day of the year).
ยงErrors
Returns None
if:
- The specified ordinal day does not exist (for example 2023-366).
- The value for
ordinal
is invalid (for example:0
,400
). year
is out of range forNaiveDate
.
ยงExample
use chrono::NaiveDate;
let from_yo_opt = NaiveDate::from_yo_opt;
assert!(from_yo_opt(2015, 100).is_some());
assert!(from_yo_opt(2015, 0).is_none());
assert!(from_yo_opt(2015, 365).is_some());
assert!(from_yo_opt(2015, 366).is_none());
assert!(from_yo_opt(-4, 366).is_some()); // 5 BCE is a leap year
assert!(from_yo_opt(400000, 1).is_none());
assert!(from_yo_opt(-400000, 1).is_none());
Sourcepub const fn from_isoywd(year: i32, week: u32, weekday: Weekday) -> NaiveDate
๐Deprecated since 0.4.23: use from_isoywd_opt()
instead
pub const fn from_isoywd(year: i32, week: u32, weekday: Weekday) -> NaiveDate
from_isoywd_opt()
insteadMakes a new NaiveDate
from the ISO week date
(year, week number and day of the week).
The resulting NaiveDate
may have a different year from the input year.
ยงPanics
Panics if the specified week does not exist in that year, on invalid values for week
, or
if the resulting date is out of range for NaiveDate
.
Sourcepub const fn from_isoywd_opt(
year: i32,
week: u32,
weekday: Weekday,
) -> Option<NaiveDate>
pub const fn from_isoywd_opt( year: i32, week: u32, weekday: Weekday, ) -> Option<NaiveDate>
Makes a new NaiveDate
from the ISO week date
(year, week number and day of the week).
The resulting NaiveDate
may have a different year from the input year.
ยงErrors
Returns None
if:
- The specified week does not exist in that year (for example 2023 week 53).
- The value for
week
is invalid (for example:0
,60
). - If the resulting date is out of range for
NaiveDate
.
ยงExample
use chrono::{NaiveDate, Weekday};
let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
let from_isoywd_opt = NaiveDate::from_isoywd_opt;
assert_eq!(from_isoywd_opt(2015, 0, Weekday::Sun), None);
assert_eq!(from_isoywd_opt(2015, 10, Weekday::Sun), Some(from_ymd(2015, 3, 8)));
assert_eq!(from_isoywd_opt(2015, 30, Weekday::Mon), Some(from_ymd(2015, 7, 20)));
assert_eq!(from_isoywd_opt(2015, 60, Weekday::Mon), None);
assert_eq!(from_isoywd_opt(400000, 10, Weekday::Fri), None);
assert_eq!(from_isoywd_opt(-400000, 10, Weekday::Sat), None);
The year number of ISO week date may differ from that of the calendar date.
// Mo Tu We Th Fr Sa Su
// 2014-W52 22 23 24 25 26 27 28 has 4+ days of new year,
// 2015-W01 29 30 31 1 2 3 4 <- so this is the first week
assert_eq!(from_isoywd_opt(2014, 52, Weekday::Sun), Some(from_ymd(2014, 12, 28)));
assert_eq!(from_isoywd_opt(2014, 53, Weekday::Mon), None);
assert_eq!(from_isoywd_opt(2015, 1, Weekday::Mon), Some(from_ymd(2014, 12, 29)));
// 2015-W52 21 22 23 24 25 26 27 has 4+ days of old year,
// 2015-W53 28 29 30 31 1 2 3 <- so this is the last week
// 2016-W01 4 5 6 7 8 9 10
assert_eq!(from_isoywd_opt(2015, 52, Weekday::Sun), Some(from_ymd(2015, 12, 27)));
assert_eq!(from_isoywd_opt(2015, 53, Weekday::Sun), Some(from_ymd(2016, 1, 3)));
assert_eq!(from_isoywd_opt(2015, 54, Weekday::Mon), None);
assert_eq!(from_isoywd_opt(2016, 1, Weekday::Mon), Some(from_ymd(2016, 1, 4)));
Sourcepub const fn from_num_days_from_ce(days: i32) -> NaiveDate
๐Deprecated since 0.4.23: use from_num_days_from_ce_opt()
instead
pub const fn from_num_days_from_ce(days: i32) -> NaiveDate
from_num_days_from_ce_opt()
insteadMakes a new NaiveDate
from a dayโs number in the proleptic Gregorian calendar, with
January 1, 1 being day 1.
ยงPanics
Panics if the date is out of range.
Sourcepub const fn from_num_days_from_ce_opt(days: i32) -> Option<NaiveDate>
pub const fn from_num_days_from_ce_opt(days: i32) -> Option<NaiveDate>
Makes a new NaiveDate
from a dayโs number in the proleptic Gregorian calendar, with
January 1, 1 being day 1.
ยงErrors
Returns None
if the date is out of range.
ยงExample
use chrono::NaiveDate;
let from_ndays_opt = NaiveDate::from_num_days_from_ce_opt;
let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
assert_eq!(from_ndays_opt(730_000), Some(from_ymd(1999, 9, 3)));
assert_eq!(from_ndays_opt(1), Some(from_ymd(1, 1, 1)));
assert_eq!(from_ndays_opt(0), Some(from_ymd(0, 12, 31)));
assert_eq!(from_ndays_opt(-1), Some(from_ymd(0, 12, 30)));
assert_eq!(from_ndays_opt(100_000_000), None);
assert_eq!(from_ndays_opt(-100_000_000), None);
Sourcepub const fn from_weekday_of_month(
year: i32,
month: u32,
weekday: Weekday,
n: u8,
) -> NaiveDate
๐Deprecated since 0.4.23: use from_weekday_of_month_opt()
instead
pub const fn from_weekday_of_month( year: i32, month: u32, weekday: Weekday, n: u8, ) -> NaiveDate
from_weekday_of_month_opt()
insteadMakes a new NaiveDate
by counting the number of occurrences of a particular day-of-week
since the beginning of the given month. For instance, if you want the 2nd Friday of March
2017, you would use NaiveDate::from_weekday_of_month(2017, 3, Weekday::Fri, 2)
.
n
is 1-indexed.
ยงPanics
Panics if the specified day does not exist in that month, on invalid values for month
or
n
, or if year
is out of range for NaiveDate
.
Sourcepub const fn from_weekday_of_month_opt(
year: i32,
month: u32,
weekday: Weekday,
n: u8,
) -> Option<NaiveDate>
pub const fn from_weekday_of_month_opt( year: i32, month: u32, weekday: Weekday, n: u8, ) -> Option<NaiveDate>
Makes a new NaiveDate
by counting the number of occurrences of a particular day-of-week
since the beginning of the given month. For instance, if you want the 2nd Friday of March
2017, you would use NaiveDate::from_weekday_of_month(2017, 3, Weekday::Fri, 2)
.
n
is 1-indexed.
ยงErrors
Returns None
if:
- The specified day does not exist in that month (for example the 5th Monday of Apr. 2023).
- The value for
month
orn
is invalid. year
is out of range forNaiveDate
.
ยงExample
use chrono::{NaiveDate, Weekday};
assert_eq!(
NaiveDate::from_weekday_of_month_opt(2017, 3, Weekday::Fri, 2),
NaiveDate::from_ymd_opt(2017, 3, 10)
)
Sourcepub fn parse_from_str(s: &str, fmt: &str) -> Result<NaiveDate, ParseError>
pub fn parse_from_str(s: &str, fmt: &str) -> Result<NaiveDate, ParseError>
Parses a string with the specified format string and returns a new NaiveDate
.
See the format::strftime
module
on the supported escape sequences.
ยงExample
use chrono::NaiveDate;
let parse_from_str = NaiveDate::parse_from_str;
assert_eq!(
parse_from_str("2015-09-05", "%Y-%m-%d"),
Ok(NaiveDate::from_ymd_opt(2015, 9, 5).unwrap())
);
assert_eq!(
parse_from_str("5sep2015", "%d%b%Y"),
Ok(NaiveDate::from_ymd_opt(2015, 9, 5).unwrap())
);
Time and offset is ignored for the purpose of parsing.
assert_eq!(
parse_from_str("2014-5-17T12:34:56+09:30", "%Y-%m-%dT%H:%M:%S%z"),
Ok(NaiveDate::from_ymd_opt(2014, 5, 17).unwrap())
);
Out-of-bound dates or insufficient fields are errors.
assert!(parse_from_str("2015/9", "%Y/%m").is_err());
assert!(parse_from_str("2015/9/31", "%Y/%m/%d").is_err());
All parsed fields should be consistent to each other, otherwise itโs an error.
assert!(parse_from_str("Sat, 09 Aug 2013", "%a, %d %b %Y").is_err());
Sourcepub fn parse_and_remainder<'a>(
s: &'a str,
fmt: &str,
) -> Result<(NaiveDate, &'a str), ParseError>
pub fn parse_and_remainder<'a>( s: &'a str, fmt: &str, ) -> Result<(NaiveDate, &'a str), ParseError>
Parses a string from a user-specified format into a new NaiveDate
value, and a slice with
the remaining portion of the string.
See the format::strftime
module
on the supported escape sequences.
Similar to parse_from_str
.
ยงExample
let (date, remainder) =
NaiveDate::parse_and_remainder("2015-02-18 trailing text", "%Y-%m-%d").unwrap();
assert_eq!(date, NaiveDate::from_ymd_opt(2015, 2, 18).unwrap());
assert_eq!(remainder, " trailing text");
Sourcepub const fn checked_add_months(self, months: Months) -> Option<NaiveDate>
pub const fn checked_add_months(self, months: Months) -> Option<NaiveDate>
Add a duration in Months
to the date
Uses the last day of the month if the day does not exist in the resulting month.
ยงErrors
Returns None
if the resulting date would be out of range.
ยงExample
assert_eq!(
NaiveDate::from_ymd_opt(2022, 2, 20).unwrap().checked_add_months(Months::new(6)),
Some(NaiveDate::from_ymd_opt(2022, 8, 20).unwrap())
);
assert_eq!(
NaiveDate::from_ymd_opt(2022, 7, 31).unwrap().checked_add_months(Months::new(2)),
Some(NaiveDate::from_ymd_opt(2022, 9, 30).unwrap())
);
Sourcepub const fn checked_sub_months(self, months: Months) -> Option<NaiveDate>
pub const fn checked_sub_months(self, months: Months) -> Option<NaiveDate>
Subtract a duration in Months
from the date
Uses the last day of the month if the day does not exist in the resulting month.
ยงErrors
Returns None
if the resulting date would be out of range.
ยงExample
assert_eq!(
NaiveDate::from_ymd_opt(2022, 2, 20).unwrap().checked_sub_months(Months::new(6)),
Some(NaiveDate::from_ymd_opt(2021, 8, 20).unwrap())
);
assert_eq!(
NaiveDate::from_ymd_opt(2014, 1, 1)
.unwrap()
.checked_sub_months(Months::new(core::i32::MAX as u32 + 1)),
None
);
Sourcepub const fn checked_add_days(self, days: Days) -> Option<NaiveDate>
pub const fn checked_add_days(self, days: Days) -> Option<NaiveDate>
Add a duration in Days
to the date
ยงErrors
Returns None
if the resulting date would be out of range.
ยงExample
assert_eq!(
NaiveDate::from_ymd_opt(2022, 2, 20).unwrap().checked_add_days(Days::new(9)),
Some(NaiveDate::from_ymd_opt(2022, 3, 1).unwrap())
);
assert_eq!(
NaiveDate::from_ymd_opt(2022, 7, 31).unwrap().checked_add_days(Days::new(2)),
Some(NaiveDate::from_ymd_opt(2022, 8, 2).unwrap())
);
assert_eq!(
NaiveDate::from_ymd_opt(2022, 7, 31).unwrap().checked_add_days(Days::new(1000000000000)),
None
);
Sourcepub const fn checked_sub_days(self, days: Days) -> Option<NaiveDate>
pub const fn checked_sub_days(self, days: Days) -> Option<NaiveDate>
Subtract a duration in Days
from the date
ยงErrors
Returns None
if the resulting date would be out of range.
ยงExample
assert_eq!(
NaiveDate::from_ymd_opt(2022, 2, 20).unwrap().checked_sub_days(Days::new(6)),
Some(NaiveDate::from_ymd_opt(2022, 2, 14).unwrap())
);
assert_eq!(
NaiveDate::from_ymd_opt(2022, 2, 20).unwrap().checked_sub_days(Days::new(1000000000000)),
None
);
Sourcepub const fn and_time(&self, time: NaiveTime) -> NaiveDateTime
pub const fn and_time(&self, time: NaiveTime) -> NaiveDateTime
Makes a new NaiveDateTime
from the current date and given NaiveTime
.
ยงExample
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
let d = NaiveDate::from_ymd_opt(2015, 6, 3).unwrap();
let t = NaiveTime::from_hms_milli_opt(12, 34, 56, 789).unwrap();
let dt: NaiveDateTime = d.and_time(t);
assert_eq!(dt.date(), d);
assert_eq!(dt.time(), t);
Sourcepub const fn and_hms(&self, hour: u32, min: u32, sec: u32) -> NaiveDateTime
๐Deprecated since 0.4.23: use and_hms_opt()
instead
pub const fn and_hms(&self, hour: u32, min: u32, sec: u32) -> NaiveDateTime
and_hms_opt()
insteadMakes a new NaiveDateTime
from the current date, hour, minute and second.
No leap second is allowed here;
use NaiveDate::and_hms_*
methods with a subsecond parameter instead.
ยงPanics
Panics on invalid hour, minute and/or second.
Sourcepub const fn and_hms_opt(
&self,
hour: u32,
min: u32,
sec: u32,
) -> Option<NaiveDateTime>
pub const fn and_hms_opt( &self, hour: u32, min: u32, sec: u32, ) -> Option<NaiveDateTime>
Makes a new NaiveDateTime
from the current date, hour, minute and second.
No leap second is allowed here;
use NaiveDate::and_hms_*_opt
methods with a subsecond parameter instead.
ยงErrors
Returns None
on invalid hour, minute and/or second.
ยงExample
use chrono::NaiveDate;
let d = NaiveDate::from_ymd_opt(2015, 6, 3).unwrap();
assert!(d.and_hms_opt(12, 34, 56).is_some());
assert!(d.and_hms_opt(12, 34, 60).is_none()); // use `and_hms_milli_opt` instead
assert!(d.and_hms_opt(12, 60, 56).is_none());
assert!(d.and_hms_opt(24, 34, 56).is_none());
Sourcepub const fn and_hms_milli(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32,
) -> NaiveDateTime
๐Deprecated since 0.4.23: use and_hms_milli_opt()
instead
pub const fn and_hms_milli( &self, hour: u32, min: u32, sec: u32, milli: u32, ) -> NaiveDateTime
and_hms_milli_opt()
insteadMakes a new NaiveDateTime
from the current date, hour, minute, second and millisecond.
The millisecond part is allowed to exceed 1,000,000,000 in order to represent a leap second, but only when sec == 59
.
ยงPanics
Panics on invalid hour, minute, second and/or millisecond.
Sourcepub const fn and_hms_milli_opt(
&self,
hour: u32,
min: u32,
sec: u32,
milli: u32,
) -> Option<NaiveDateTime>
pub const fn and_hms_milli_opt( &self, hour: u32, min: u32, sec: u32, milli: u32, ) -> Option<NaiveDateTime>
Makes a new NaiveDateTime
from the current date, hour, minute, second and millisecond.
The millisecond part is allowed to exceed 1,000,000,000 in order to represent a leap second, but only when sec == 59
.
ยงErrors
Returns None
on invalid hour, minute, second and/or millisecond.
ยงExample
use chrono::NaiveDate;
let d = NaiveDate::from_ymd_opt(2015, 6, 3).unwrap();
assert!(d.and_hms_milli_opt(12, 34, 56, 789).is_some());
assert!(d.and_hms_milli_opt(12, 34, 59, 1_789).is_some()); // leap second
assert!(d.and_hms_milli_opt(12, 34, 59, 2_789).is_none());
assert!(d.and_hms_milli_opt(12, 34, 60, 789).is_none());
assert!(d.and_hms_milli_opt(12, 60, 56, 789).is_none());
assert!(d.and_hms_milli_opt(24, 34, 56, 789).is_none());
Sourcepub const fn and_hms_micro(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32,
) -> NaiveDateTime
๐Deprecated since 0.4.23: use and_hms_micro_opt()
instead
pub const fn and_hms_micro( &self, hour: u32, min: u32, sec: u32, micro: u32, ) -> NaiveDateTime
and_hms_micro_opt()
insteadMakes a new NaiveDateTime
from the current date, hour, minute, second and microsecond.
The microsecond part is allowed to exceed 1,000,000,000 in order to represent a leap second, but only when sec == 59
.
ยงPanics
Panics on invalid hour, minute, second and/or microsecond.
ยงExample
use chrono::{Datelike, NaiveDate, NaiveDateTime, Timelike, Weekday};
let d = NaiveDate::from_ymd_opt(2015, 6, 3).unwrap();
let dt: NaiveDateTime = d.and_hms_micro_opt(12, 34, 56, 789_012).unwrap();
assert_eq!(dt.year(), 2015);
assert_eq!(dt.weekday(), Weekday::Wed);
assert_eq!(dt.second(), 56);
assert_eq!(dt.nanosecond(), 789_012_000);
Sourcepub const fn and_hms_micro_opt(
&self,
hour: u32,
min: u32,
sec: u32,
micro: u32,
) -> Option<NaiveDateTime>
pub const fn and_hms_micro_opt( &self, hour: u32, min: u32, sec: u32, micro: u32, ) -> Option<NaiveDateTime>
Makes a new NaiveDateTime
from the current date, hour, minute, second and microsecond.
The microsecond part is allowed to exceed 1,000,000,000 in order to represent a leap second, but only when sec == 59
.
ยงErrors
Returns None
on invalid hour, minute, second and/or microsecond.
ยงExample
use chrono::NaiveDate;
let d = NaiveDate::from_ymd_opt(2015, 6, 3).unwrap();
assert!(d.and_hms_micro_opt(12, 34, 56, 789_012).is_some());
assert!(d.and_hms_micro_opt(12, 34, 59, 1_789_012).is_some()); // leap second
assert!(d.and_hms_micro_opt(12, 34, 59, 2_789_012).is_none());
assert!(d.and_hms_micro_opt(12, 34, 60, 789_012).is_none());
assert!(d.and_hms_micro_opt(12, 60, 56, 789_012).is_none());
assert!(d.and_hms_micro_opt(24, 34, 56, 789_012).is_none());
Sourcepub const fn and_hms_nano(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32,
) -> NaiveDateTime
๐Deprecated since 0.4.23: use and_hms_nano_opt()
instead
pub const fn and_hms_nano( &self, hour: u32, min: u32, sec: u32, nano: u32, ) -> NaiveDateTime
and_hms_nano_opt()
insteadMakes a new NaiveDateTime
from the current date, hour, minute, second and nanosecond.
The nanosecond part is allowed to exceed 1,000,000,000 in order to represent a leap second, but only when sec == 59
.
ยงPanics
Panics on invalid hour, minute, second and/or nanosecond.
Sourcepub const fn and_hms_nano_opt(
&self,
hour: u32,
min: u32,
sec: u32,
nano: u32,
) -> Option<NaiveDateTime>
pub const fn and_hms_nano_opt( &self, hour: u32, min: u32, sec: u32, nano: u32, ) -> Option<NaiveDateTime>
Makes a new NaiveDateTime
from the current date, hour, minute, second and nanosecond.
The nanosecond part is allowed to exceed 1,000,000,000 in order to represent a leap second, but only when sec == 59
.
ยงErrors
Returns None
on invalid hour, minute, second and/or nanosecond.
ยงExample
use chrono::NaiveDate;
let d = NaiveDate::from_ymd_opt(2015, 6, 3).unwrap();
assert!(d.and_hms_nano_opt(12, 34, 56, 789_012_345).is_some());
assert!(d.and_hms_nano_opt(12, 34, 59, 1_789_012_345).is_some()); // leap second
assert!(d.and_hms_nano_opt(12, 34, 59, 2_789_012_345).is_none());
assert!(d.and_hms_nano_opt(12, 34, 60, 789_012_345).is_none());
assert!(d.and_hms_nano_opt(12, 60, 56, 789_012_345).is_none());
assert!(d.and_hms_nano_opt(24, 34, 56, 789_012_345).is_none());
Sourcepub const fn succ(&self) -> NaiveDate
๐Deprecated since 0.4.23: use succ_opt()
instead
pub const fn succ(&self) -> NaiveDate
succ_opt()
insteadMakes a new NaiveDate
for the next calendar date.
ยงPanics
Panics when self
is the last representable date.
Sourcepub const fn succ_opt(&self) -> Option<NaiveDate>
pub const fn succ_opt(&self) -> Option<NaiveDate>
Makes a new NaiveDate
for the next calendar date.
ยงErrors
Returns None
when self
is the last representable date.
ยงExample
use chrono::NaiveDate;
assert_eq!(
NaiveDate::from_ymd_opt(2015, 6, 3).unwrap().succ_opt(),
Some(NaiveDate::from_ymd_opt(2015, 6, 4).unwrap())
);
assert_eq!(NaiveDate::MAX.succ_opt(), None);
Sourcepub const fn pred(&self) -> NaiveDate
๐Deprecated since 0.4.23: use pred_opt()
instead
pub const fn pred(&self) -> NaiveDate
pred_opt()
insteadMakes a new NaiveDate
for the previous calendar date.
ยงPanics
Panics when self
is the first representable date.
Sourcepub const fn pred_opt(&self) -> Option<NaiveDate>
pub const fn pred_opt(&self) -> Option<NaiveDate>
Makes a new NaiveDate
for the previous calendar date.
ยงErrors
Returns None
when self
is the first representable date.
ยงExample
use chrono::NaiveDate;
assert_eq!(
NaiveDate::from_ymd_opt(2015, 6, 3).unwrap().pred_opt(),
Some(NaiveDate::from_ymd_opt(2015, 6, 2).unwrap())
);
assert_eq!(NaiveDate::MIN.pred_opt(), None);
Sourcepub const fn checked_add_signed(self, rhs: TimeDelta) -> Option<NaiveDate>
pub const fn checked_add_signed(self, rhs: TimeDelta) -> Option<NaiveDate>
Adds the number of whole days in the given TimeDelta
to the current date.
ยงErrors
Returns None
if the resulting date would be out of range.
ยงExample
use chrono::{NaiveDate, TimeDelta};
let d = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap();
assert_eq!(
d.checked_add_signed(TimeDelta::try_days(40).unwrap()),
Some(NaiveDate::from_ymd_opt(2015, 10, 15).unwrap())
);
assert_eq!(
d.checked_add_signed(TimeDelta::try_days(-40).unwrap()),
Some(NaiveDate::from_ymd_opt(2015, 7, 27).unwrap())
);
assert_eq!(d.checked_add_signed(TimeDelta::try_days(1_000_000_000).unwrap()), None);
assert_eq!(d.checked_add_signed(TimeDelta::try_days(-1_000_000_000).unwrap()), None);
assert_eq!(NaiveDate::MAX.checked_add_signed(TimeDelta::try_days(1).unwrap()), None);
Sourcepub const fn checked_sub_signed(self, rhs: TimeDelta) -> Option<NaiveDate>
pub const fn checked_sub_signed(self, rhs: TimeDelta) -> Option<NaiveDate>
Subtracts the number of whole days in the given TimeDelta
from the current date.
ยงErrors
Returns None
if the resulting date would be out of range.
ยงExample
use chrono::{NaiveDate, TimeDelta};
let d = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap();
assert_eq!(
d.checked_sub_signed(TimeDelta::try_days(40).unwrap()),
Some(NaiveDate::from_ymd_opt(2015, 7, 27).unwrap())
);
assert_eq!(
d.checked_sub_signed(TimeDelta::try_days(-40).unwrap()),
Some(NaiveDate::from_ymd_opt(2015, 10, 15).unwrap())
);
assert_eq!(d.checked_sub_signed(TimeDelta::try_days(1_000_000_000).unwrap()), None);
assert_eq!(d.checked_sub_signed(TimeDelta::try_days(-1_000_000_000).unwrap()), None);
assert_eq!(NaiveDate::MIN.checked_sub_signed(TimeDelta::try_days(1).unwrap()), None);
Sourcepub const fn signed_duration_since(self, rhs: NaiveDate) -> TimeDelta
pub const fn signed_duration_since(self, rhs: NaiveDate) -> TimeDelta
Subtracts another NaiveDate
from the current date.
Returns a TimeDelta
of integral numbers.
This does not overflow or underflow at all,
as all possible output fits in the range of TimeDelta
.
ยงExample
use chrono::{NaiveDate, TimeDelta};
let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
let since = NaiveDate::signed_duration_since;
assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2014, 1, 1)), TimeDelta::zero());
assert_eq!(
since(from_ymd(2014, 1, 1), from_ymd(2013, 12, 31)),
TimeDelta::try_days(1).unwrap()
);
assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2014, 1, 2)), TimeDelta::try_days(-1).unwrap());
assert_eq!(
since(from_ymd(2014, 1, 1), from_ymd(2013, 9, 23)),
TimeDelta::try_days(100).unwrap()
);
assert_eq!(
since(from_ymd(2014, 1, 1), from_ymd(2013, 1, 1)),
TimeDelta::try_days(365).unwrap()
);
assert_eq!(
since(from_ymd(2014, 1, 1), from_ymd(2010, 1, 1)),
TimeDelta::try_days(365 * 4 + 1).unwrap()
);
assert_eq!(
since(from_ymd(2014, 1, 1), from_ymd(1614, 1, 1)),
TimeDelta::try_days(365 * 400 + 97).unwrap()
);
Sourcepub const fn years_since(&self, base: NaiveDate) -> Option<u32>
pub const fn years_since(&self, base: NaiveDate) -> Option<u32>
Returns the number of whole years from the given base
until self
.
ยงErrors
Returns None
if base < self
.
Sourcepub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
Formats the date with the specified formatting items.
Otherwise it is the same as the ordinary format
method.
The Iterator
of items should be Clone
able,
since the resulting DelayedFormat
value may be formatted multiple times.
ยงExample
use chrono::format::strftime::StrftimeItems;
use chrono::NaiveDate;
let fmt = StrftimeItems::new("%Y-%m-%d");
let d = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap();
assert_eq!(d.format_with_items(fmt.clone()).to_string(), "2015-09-05");
assert_eq!(d.format("%Y-%m-%d").to_string(), "2015-09-05");
The resulting DelayedFormat
can be formatted directly via the Display
trait.
assert_eq!(format!("{}", d.format_with_items(fmt)), "2015-09-05");
Sourcepub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Formats the date with the specified format string.
See the format::strftime
module
on the supported escape sequences.
This returns a DelayedFormat
,
which gets converted to a string only when actual formatting happens.
You may use the to_string
method to get a String
,
or just feed it into print!
and other formatting macros.
(In this way it avoids the redundant memory allocation.)
A wrong format string does not issue an error immediately.
Rather, converting or formatting the DelayedFormat
fails.
You are recommended to immediately use DelayedFormat
for this reason.
ยงExample
use chrono::NaiveDate;
let d = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap();
assert_eq!(d.format("%Y-%m-%d").to_string(), "2015-09-05");
assert_eq!(d.format("%A, %-d %B, %C%y").to_string(), "Saturday, 5 September, 2015");
The resulting DelayedFormat
can be formatted directly via the Display
trait.
assert_eq!(format!("{}", d.format("%Y-%m-%d")), "2015-09-05");
assert_eq!(format!("{}", d.format("%A, %-d %B, %C%y")), "Saturday, 5 September, 2015");
Sourcepub const fn iter_days(&self) -> NaiveDateDaysIterator
pub const fn iter_days(&self) -> NaiveDateDaysIterator
Returns an iterator that steps by days across all representable dates.
ยงExample
let expected = [
NaiveDate::from_ymd_opt(2016, 2, 27).unwrap(),
NaiveDate::from_ymd_opt(2016, 2, 28).unwrap(),
NaiveDate::from_ymd_opt(2016, 2, 29).unwrap(),
NaiveDate::from_ymd_opt(2016, 3, 1).unwrap(),
];
let mut count = 0;
for (idx, d) in NaiveDate::from_ymd_opt(2016, 2, 27).unwrap().iter_days().take(4).enumerate() {
assert_eq!(d, expected[idx]);
count += 1;
}
assert_eq!(count, 4);
for d in NaiveDate::from_ymd_opt(2016, 3, 1).unwrap().iter_days().rev().take(4) {
count -= 1;
assert_eq!(d, expected[count]);
}
Sourcepub const fn iter_weeks(&self) -> NaiveDateWeeksIterator
pub const fn iter_weeks(&self) -> NaiveDateWeeksIterator
Returns an iterator that steps by weeks across all representable dates.
ยงExample
let expected = [
NaiveDate::from_ymd_opt(2016, 2, 27).unwrap(),
NaiveDate::from_ymd_opt(2016, 3, 5).unwrap(),
NaiveDate::from_ymd_opt(2016, 3, 12).unwrap(),
NaiveDate::from_ymd_opt(2016, 3, 19).unwrap(),
];
let mut count = 0;
for (idx, d) in NaiveDate::from_ymd_opt(2016, 2, 27).unwrap().iter_weeks().take(4).enumerate() {
assert_eq!(d, expected[idx]);
count += 1;
}
assert_eq!(count, 4);
for d in NaiveDate::from_ymd_opt(2016, 3, 19).unwrap().iter_weeks().rev().take(4) {
count -= 1;
assert_eq!(d, expected[count]);
}
Sourcepub const fn leap_year(&self) -> bool
pub const fn leap_year(&self) -> bool
Returns true
if this is a leap year.
assert_eq!(NaiveDate::from_ymd_opt(2000, 1, 1).unwrap().leap_year(), true);
assert_eq!(NaiveDate::from_ymd_opt(2001, 1, 1).unwrap().leap_year(), false);
assert_eq!(NaiveDate::from_ymd_opt(2002, 1, 1).unwrap().leap_year(), false);
assert_eq!(NaiveDate::from_ymd_opt(2003, 1, 1).unwrap().leap_year(), false);
assert_eq!(NaiveDate::from_ymd_opt(2004, 1, 1).unwrap().leap_year(), true);
assert_eq!(NaiveDate::from_ymd_opt(2100, 1, 1).unwrap().leap_year(), false);
Trait Implementationsยง
Sourceยงimpl Add<Days> for NaiveDate
impl Add<Days> for NaiveDate
Add Days
to NaiveDate
.
ยงPanics
Panics if the resulting date would be out of range.
Consider using NaiveDate::checked_add_days
to get an Option
instead.
Sourceยงimpl Add<Months> for NaiveDate
impl Add<Months> for NaiveDate
Add Months
to NaiveDate
.
The result will be clamped to valid days in the resulting month, see checked_add_months
for
details.
ยงPanics
Panics if the resulting date would be out of range.
Consider using NaiveDate::checked_add_months
to get an Option
instead.
ยงExample
use chrono::{Months, NaiveDate};
let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
assert_eq!(from_ymd(2014, 1, 1) + Months::new(1), from_ymd(2014, 2, 1));
assert_eq!(from_ymd(2014, 1, 1) + Months::new(11), from_ymd(2014, 12, 1));
assert_eq!(from_ymd(2014, 1, 1) + Months::new(12), from_ymd(2015, 1, 1));
assert_eq!(from_ymd(2014, 1, 1) + Months::new(13), from_ymd(2015, 2, 1));
assert_eq!(from_ymd(2014, 1, 31) + Months::new(1), from_ymd(2014, 2, 28));
assert_eq!(from_ymd(2020, 1, 31) + Months::new(1), from_ymd(2020, 2, 29));
Sourceยงimpl Add<TimeDelta> for NaiveDate
impl Add<TimeDelta> for NaiveDate
Add TimeDelta
to NaiveDate
.
This discards the fractional days in TimeDelta
, rounding to the closest integral number of
days towards TimeDelta::zero()
.
ยงPanics
Panics if the resulting date would be out of range.
Consider using NaiveDate::checked_add_signed
to get an Option
instead.
ยงExample
use chrono::{NaiveDate, TimeDelta};
let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::zero(), from_ymd(2014, 1, 1));
assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::try_seconds(86399).unwrap(), from_ymd(2014, 1, 1));
assert_eq!(
from_ymd(2014, 1, 1) + TimeDelta::try_seconds(-86399).unwrap(),
from_ymd(2014, 1, 1)
);
assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::try_days(1).unwrap(), from_ymd(2014, 1, 2));
assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::try_days(-1).unwrap(), from_ymd(2013, 12, 31));
assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::try_days(364).unwrap(), from_ymd(2014, 12, 31));
assert_eq!(
from_ymd(2014, 1, 1) + TimeDelta::try_days(365 * 4 + 1).unwrap(),
from_ymd(2018, 1, 1)
);
assert_eq!(
from_ymd(2014, 1, 1) + TimeDelta::try_days(365 * 400 + 97).unwrap(),
from_ymd(2414, 1, 1)
);
Sourceยงimpl AddAssign<TimeDelta> for NaiveDate
impl AddAssign<TimeDelta> for NaiveDate
Add-assign of TimeDelta
to NaiveDate
.
This discards the fractional days in TimeDelta
, rounding to the closest integral number of days
towards TimeDelta::zero()
.
ยงPanics
Panics if the resulting date would be out of range.
Consider using NaiveDate::checked_add_signed
to get an Option
instead.
Sourceยงfn add_assign(&mut self, rhs: TimeDelta)
fn add_assign(&mut self, rhs: TimeDelta)
+=
operation. Read moreSourceยงimpl Datelike for NaiveDate
impl Datelike for NaiveDate
Sourceยงfn year(&self) -> i32
fn year(&self) -> i32
Returns the year number in the calendar date.
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().year(), 2015);
assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().year(), -308); // 309 BCE
Sourceยงfn month(&self) -> u32
fn month(&self) -> u32
Returns the month number starting from 1.
The return value ranges from 1 to 12.
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().month(), 9);
assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().month(), 3);
Sourceยงfn month0(&self) -> u32
fn month0(&self) -> u32
Returns the month number starting from 0.
The return value ranges from 0 to 11.
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().month0(), 8);
assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().month0(), 2);
Sourceยงfn day(&self) -> u32
fn day(&self) -> u32
Returns the day of month starting from 1.
The return value ranges from 1 to 31. (The last day of month differs by months.)
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().day(), 8);
assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().day(), 14);
Combined with NaiveDate::pred_opt
,
one can determine the number of days in a particular month.
(Note that this panics when year
is out of range.)
use chrono::{Datelike, NaiveDate};
fn ndays_in_month(year: i32, month: u32) -> u32 {
// the first day of the next month...
let (y, m) = if month == 12 { (year + 1, 1) } else { (year, month + 1) };
let d = NaiveDate::from_ymd_opt(y, m, 1).unwrap();
// ...is preceded by the last day of the original month
d.pred_opt().unwrap().day()
}
assert_eq!(ndays_in_month(2015, 8), 31);
assert_eq!(ndays_in_month(2015, 9), 30);
assert_eq!(ndays_in_month(2015, 12), 31);
assert_eq!(ndays_in_month(2016, 2), 29);
assert_eq!(ndays_in_month(2017, 2), 28);
Sourceยงfn day0(&self) -> u32
fn day0(&self) -> u32
Returns the day of month starting from 0.
The return value ranges from 0 to 30. (The last day of month differs by months.)
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().day0(), 7);
assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().day0(), 13);
Sourceยงfn ordinal(&self) -> u32
fn ordinal(&self) -> u32
Returns the day of year starting from 1.
The return value ranges from 1 to 366. (The last day of year differs by years.)
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().ordinal(), 251);
assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().ordinal(), 74);
Combined with NaiveDate::pred_opt
,
one can determine the number of days in a particular year.
(Note that this panics when year
is out of range.)
use chrono::{Datelike, NaiveDate};
fn ndays_in_year(year: i32) -> u32 {
// the first day of the next year...
let d = NaiveDate::from_ymd_opt(year + 1, 1, 1).unwrap();
// ...is preceded by the last day of the original year
d.pred_opt().unwrap().ordinal()
}
assert_eq!(ndays_in_year(2015), 365);
assert_eq!(ndays_in_year(2016), 366);
assert_eq!(ndays_in_year(2017), 365);
assert_eq!(ndays_in_year(2000), 366);
assert_eq!(ndays_in_year(2100), 365);
Sourceยงfn ordinal0(&self) -> u32
fn ordinal0(&self) -> u32
Returns the day of year starting from 0.
The return value ranges from 0 to 365. (The last day of year differs by years.)
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().ordinal0(), 250);
assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().ordinal0(), 73);
Sourceยงfn weekday(&self) -> Weekday
fn weekday(&self) -> Weekday
Returns the day of week.
ยงExample
use chrono::{Datelike, NaiveDate, Weekday};
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().weekday(), Weekday::Tue);
assert_eq!(NaiveDate::from_ymd_opt(-308, 3, 14).unwrap().weekday(), Weekday::Fri);
Sourceยงfn with_year(&self, year: i32) -> Option<NaiveDate>
fn with_year(&self, year: i32) -> Option<NaiveDate>
Makes a new NaiveDate
with the year number changed, while keeping the same month and day.
This method assumes you want to work on the date as a year-month-day value. Donโt use it if you want the ordinal to stay the same after changing the year, of if you want the week and weekday values to stay the same.
ยงErrors
Returns None
if:
- The resulting date does not exist (February 29 in a non-leap year).
- The year is out of range for a
NaiveDate
.
ยงExamples
use chrono::{Datelike, NaiveDate};
assert_eq!(
NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_year(2016),
Some(NaiveDate::from_ymd_opt(2016, 9, 8).unwrap())
);
assert_eq!(
NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_year(-308),
Some(NaiveDate::from_ymd_opt(-308, 9, 8).unwrap())
);
A leap day (February 29) is a case where this method can return None
.
assert!(NaiveDate::from_ymd_opt(2016, 2, 29).unwrap().with_year(2015).is_none());
assert!(NaiveDate::from_ymd_opt(2016, 2, 29).unwrap().with_year(2020).is_some());
Donโt use with_year
if you want the ordinal date to stay the same:
assert_ne!(
NaiveDate::from_yo_opt(2020, 100).unwrap().with_year(2023).unwrap(),
NaiveDate::from_yo_opt(2023, 100).unwrap() // result is 2023-101
);
Sourceยงfn with_month(&self, month: u32) -> Option<NaiveDate>
fn with_month(&self, month: u32) -> Option<NaiveDate>
Makes a new NaiveDate
with the month number (starting from 1) changed.
ยงErrors
Returns None
if:
- The resulting date does not exist (for example
month(4)
when day of the month is 31). - The value for
month
is invalid.
ยงExamples
use chrono::{Datelike, NaiveDate};
assert_eq!(
NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_month(10),
Some(NaiveDate::from_ymd_opt(2015, 10, 8).unwrap())
);
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_month(13), None); // No month 13
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 30).unwrap().with_month(2), None); // No Feb 30
Donโt combine multiple Datelike::with_*
methods. The intermediate value may not exist.
use chrono::{Datelike, NaiveDate};
fn with_year_month(date: NaiveDate, year: i32, month: u32) -> Option<NaiveDate> {
date.with_year(year)?.with_month(month)
}
let d = NaiveDate::from_ymd_opt(2020, 2, 29).unwrap();
assert!(with_year_month(d, 2019, 1).is_none()); // fails because of invalid intermediate value
// Correct version:
fn with_year_month_fixed(date: NaiveDate, year: i32, month: u32) -> Option<NaiveDate> {
NaiveDate::from_ymd_opt(year, month, date.day())
}
let d = NaiveDate::from_ymd_opt(2020, 2, 29).unwrap();
assert_eq!(with_year_month_fixed(d, 2019, 1), NaiveDate::from_ymd_opt(2019, 1, 29));
Sourceยงfn with_month0(&self, month0: u32) -> Option<NaiveDate>
fn with_month0(&self, month0: u32) -> Option<NaiveDate>
Makes a new NaiveDate
with the month number (starting from 0) changed.
ยงErrors
Returns None
if:
- The resulting date does not exist (for example
month0(3)
when day of the month is 31). - The value for
month0
is invalid.
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(
NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_month0(9),
Some(NaiveDate::from_ymd_opt(2015, 10, 8).unwrap())
);
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_month0(12), None); // No month 12
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 30).unwrap().with_month0(1), None); // No Feb 30
Sourceยงfn with_day(&self, day: u32) -> Option<NaiveDate>
fn with_day(&self, day: u32) -> Option<NaiveDate>
Makes a new NaiveDate
with the day of month (starting from 1) changed.
ยงErrors
Returns None
if:
- The resulting date does not exist (for example
day(31)
in April). - The value for
day
is invalid.
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(
NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_day(30),
Some(NaiveDate::from_ymd_opt(2015, 9, 30).unwrap())
);
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_day(31), None);
// no September 31
Sourceยงfn with_day0(&self, day0: u32) -> Option<NaiveDate>
fn with_day0(&self, day0: u32) -> Option<NaiveDate>
Makes a new NaiveDate
with the day of month (starting from 0) changed.
ยงErrors
Returns None
if:
- The resulting date does not exist (for example
day(30)
in April). - The value for
day0
is invalid.
ยงExample
use chrono::{Datelike, NaiveDate};
assert_eq!(
NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_day0(29),
Some(NaiveDate::from_ymd_opt(2015, 9, 30).unwrap())
);
assert_eq!(NaiveDate::from_ymd_opt(2015, 9, 8).unwrap().with_day0(30), None);
// no September 31
Sourceยงfn with_ordinal(&self, ordinal: u32) -> Option<NaiveDate>
fn with_ordinal(&self, ordinal: u32) -> Option<NaiveDate>
Makes a new NaiveDate
with the day of year (starting from 1) changed.
ยงErrors
Returns None
if:
- The resulting date does not exist (
with_ordinal(366)
in a non-leap year). - The value for
ordinal
is invalid.
ยงExample
use chrono::{NaiveDate, Datelike};
assert_eq!(NaiveDate::from_ymd_opt(2015, 1, 1).unwrap().with_ordinal(60),
Some(NaiveDate::from_ymd_opt(2015, 3, 1).unwrap()));
assert_eq!(NaiveDate::from_ymd_opt(2015, 1, 1).unwrap().with_ordinal(366),
None); // 2015 had only 365 days
assert_eq!(NaiveDate::from_ymd_opt(2016, 1, 1).unwrap().with_ordinal(60),
Some(NaiveDate::from_ymd_opt(2016, 2, 29).unwrap()));
assert_eq!(NaiveDate::from_ymd_opt(2016, 1, 1).unwrap().with_ordinal(366),
Some(NaiveDate::from_ymd_opt(2016, 12, 31).unwrap()));
Sourceยงfn with_ordinal0(&self, ordinal0: u32) -> Option<NaiveDate>
fn with_ordinal0(&self, ordinal0: u32) -> Option<NaiveDate>
Makes a new NaiveDate
with the day of year (starting from 0) changed.
ยงErrors
Returns None
if:
- The resulting date does not exist (
with_ordinal0(365)
in a non-leap year). - The value for
ordinal0
is invalid.
ยงExample
use chrono::{NaiveDate, Datelike};
assert_eq!(NaiveDate::from_ymd_opt(2015, 1, 1).unwrap().with_ordinal0(59),
Some(NaiveDate::from_ymd_opt(2015, 3, 1).unwrap()));
assert_eq!(NaiveDate::from_ymd_opt(2015, 1, 1).unwrap().with_ordinal0(365),
None); // 2015 had only 365 days
assert_eq!(NaiveDate::from_ymd_opt(2016, 1, 1).unwrap().with_ordinal0(59),
Some(NaiveDate::from_ymd_opt(2016, 2, 29).unwrap()));
assert_eq!(NaiveDate::from_ymd_opt(2016, 1, 1).unwrap().with_ordinal0(365),
Some(NaiveDate::from_ymd_opt(2016, 12, 31).unwrap()));
Sourceยงfn year_ce(&self) -> (bool, u32)
fn year_ce(&self) -> (bool, u32)
Sourceยงfn num_days_from_ce(&self) -> i32
fn num_days_from_ce(&self) -> i32
Sourceยงimpl Debug for NaiveDate
impl Debug for NaiveDate
The Debug
output of the naive date d
is the same as
d.format("%Y-%m-%d")
.
The string printed can be readily parsed via the parse
method on str
.
ยงExample
use chrono::NaiveDate;
assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(2015, 9, 5).unwrap()), "2015-09-05");
assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(0, 1, 1).unwrap()), "0000-01-01");
assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(9999, 12, 31).unwrap()), "9999-12-31");
ISO 8601 requires an explicit sign for years before 1 BCE or after 9999 CE.
assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(-1, 1, 1).unwrap()), "-0001-01-01");
assert_eq!(format!("{:?}", NaiveDate::from_ymd_opt(10000, 12, 31).unwrap()), "+10000-12-31");
Sourceยงimpl Default for NaiveDate
impl Default for NaiveDate
The default value for a NaiveDate is 1st of January 1970.
ยงExample
use chrono::NaiveDate;
let default_date = NaiveDate::default();
assert_eq!(default_date, NaiveDate::from_ymd_opt(1970, 1, 1).unwrap());
Sourceยงimpl<'de> Deserialize<'de> for NaiveDate
impl<'de> Deserialize<'de> for NaiveDate
Sourceยงfn deserialize<D>(
deserializer: D,
) -> Result<NaiveDate, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<NaiveDate, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Sourceยงimpl Display for NaiveDate
impl Display for NaiveDate
The Display
output of the naive date d
is the same as
d.format("%Y-%m-%d")
.
The string printed can be readily parsed via the parse
method on str
.
ยงExample
use chrono::NaiveDate;
assert_eq!(format!("{}", NaiveDate::from_ymd_opt(2015, 9, 5).unwrap()), "2015-09-05");
assert_eq!(format!("{}", NaiveDate::from_ymd_opt(0, 1, 1).unwrap()), "0000-01-01");
assert_eq!(format!("{}", NaiveDate::from_ymd_opt(9999, 12, 31).unwrap()), "9999-12-31");
ISO 8601 requires an explicit sign for years before 1 BCE or after 9999 CE.
assert_eq!(format!("{}", NaiveDate::from_ymd_opt(-1, 1, 1).unwrap()), "-0001-01-01");
assert_eq!(format!("{}", NaiveDate::from_ymd_opt(10000, 12, 31).unwrap()), "+10000-12-31");
Sourceยงimpl Encode<'_, MySql> for NaiveDate
impl Encode<'_, MySql> for NaiveDate
Sourceยงfn encode_by_ref(
&self,
buf: &mut Vec<u8>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut Vec<u8>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn size_hint(&self) -> usize
Sourceยงfn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
self
into buf
in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Sourceยงimpl Encode<'_, Postgres> for NaiveDate
impl Encode<'_, Postgres> for NaiveDate
Sourceยงfn encode_by_ref(
&self,
buf: &mut PgArgumentBuffer,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut PgArgumentBuffer, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn size_hint(&self) -> usize
Sourceยงfn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
self
into buf
in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
Sourceยงimpl Encode<'_, Sqlite> for NaiveDate
impl Encode<'_, Sqlite> for NaiveDate
Sourceยงfn encode_by_ref(
&self,
buf: &mut Vec<SqliteArgumentValue<'_>>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>
fn encode_by_ref( &self, buf: &mut Vec<SqliteArgumentValue<'_>>, ) -> Result<IsNull, Box<dyn Error + Sync + Send>>
Sourceยงfn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
fn encode(
self,
buf: &mut <DB as Database>::ArgumentBuffer<'q>,
) -> Result<IsNull, Box<dyn Error + Sync + Send>>where
Self: Sized,
self
into buf
in the expected format for the database.fn produces(&self) -> Option<<DB as Database>::TypeInfo>
fn size_hint(&self) -> usize
Sourceยงimpl From<NaiveDate> for NaiveDateTime
impl From<NaiveDate> for NaiveDateTime
Sourceยงfn from(date: NaiveDate) -> NaiveDateTime
fn from(date: NaiveDate) -> NaiveDateTime
Converts a NaiveDate
to a NaiveDateTime
of the same date but at midnight.
ยงExample
use chrono::{NaiveDate, NaiveDateTime};
let nd = NaiveDate::from_ymd_opt(2016, 5, 28).unwrap();
let ndt = NaiveDate::from_ymd_opt(2016, 5, 28).unwrap().and_hms_opt(0, 0, 0).unwrap();
assert_eq!(ndt, NaiveDateTime::from(nd));
Sourceยงimpl From<NaiveDateTime> for NaiveDate
impl From<NaiveDateTime> for NaiveDate
Sourceยงfn from(naive_datetime: NaiveDateTime) -> NaiveDate
fn from(naive_datetime: NaiveDateTime) -> NaiveDate
Sourceยงimpl FromStr for NaiveDate
impl FromStr for NaiveDate
Parsing a str
into a NaiveDate
uses the same format,
%Y-%m-%d
, as in Debug
and Display
.
ยงExample
use chrono::NaiveDate;
let d = NaiveDate::from_ymd_opt(2015, 9, 18).unwrap();
assert_eq!("2015-09-18".parse::<NaiveDate>(), Ok(d));
let d = NaiveDate::from_ymd_opt(12345, 6, 7).unwrap();
assert_eq!("+12345-6-7".parse::<NaiveDate>(), Ok(d));
assert!("foo".parse::<NaiveDate>().is_err());
Sourceยงimpl IntoActiveValue<NaiveDate> for Date
impl IntoActiveValue<NaiveDate> for Date
Sourceยงfn into_active_value(self) -> ActiveValue<Date>
fn into_active_value(self) -> ActiveValue<Date>
Sourceยงimpl Ord for NaiveDate
impl Ord for NaiveDate
1.21.0 ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Sourceยงimpl PartialOrd for NaiveDate
impl PartialOrd for NaiveDate
Sourceยงimpl PgHasArrayType for NaiveDate
impl PgHasArrayType for NaiveDate
fn array_type_info() -> PgTypeInfo
fn array_compatible(ty: &PgTypeInfo) -> bool
Sourceยงimpl Serialize for NaiveDate
impl Serialize for NaiveDate
Sourceยงfn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Sourceยงimpl Sub<Days> for NaiveDate
impl Sub<Days> for NaiveDate
Subtract Days
from NaiveDate
.
ยงPanics
Panics if the resulting date would be out of range.
Consider using NaiveDate::checked_sub_days
to get an Option
instead.
Sourceยงimpl Sub<Months> for NaiveDate
impl Sub<Months> for NaiveDate
Subtract Months
from NaiveDate
.
The result will be clamped to valid days in the resulting month, see checked_sub_months
for
details.
ยงPanics
Panics if the resulting date would be out of range.
Consider using NaiveDate::checked_sub_months
to get an Option
instead.
ยงExample
use chrono::{Months, NaiveDate};
let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
assert_eq!(from_ymd(2014, 1, 1) - Months::new(11), from_ymd(2013, 2, 1));
assert_eq!(from_ymd(2014, 1, 1) - Months::new(12), from_ymd(2013, 1, 1));
assert_eq!(from_ymd(2014, 1, 1) - Months::new(13), from_ymd(2012, 12, 1));
Sourceยงimpl Sub<TimeDelta> for NaiveDate
impl Sub<TimeDelta> for NaiveDate
Subtract TimeDelta
from NaiveDate
.
This discards the fractional days in TimeDelta
, rounding to the closest integral number of
days towards TimeDelta::zero()
.
It is the same as the addition with a negated TimeDelta
.
ยงPanics
Panics if the resulting date would be out of range.
Consider using NaiveDate::checked_sub_signed
to get an Option
instead.
ยงExample
use chrono::{NaiveDate, TimeDelta};
let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::zero(), from_ymd(2014, 1, 1));
assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::try_seconds(86399).unwrap(), from_ymd(2014, 1, 1));
assert_eq!(
from_ymd(2014, 1, 1) - TimeDelta::try_seconds(-86399).unwrap(),
from_ymd(2014, 1, 1)
);
assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::try_days(1).unwrap(), from_ymd(2013, 12, 31));
assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::try_days(-1).unwrap(), from_ymd(2014, 1, 2));
assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::try_days(364).unwrap(), from_ymd(2013, 1, 2));
assert_eq!(
from_ymd(2014, 1, 1) - TimeDelta::try_days(365 * 4 + 1).unwrap(),
from_ymd(2010, 1, 1)
);
assert_eq!(
from_ymd(2014, 1, 1) - TimeDelta::try_days(365 * 400 + 97).unwrap(),
from_ymd(1614, 1, 1)
);
Sourceยงimpl Sub for NaiveDate
impl Sub for NaiveDate
Subtracts another NaiveDate
from the current date.
Returns a TimeDelta
of integral numbers.
This does not overflow or underflow at all,
as all possible output fits in the range of TimeDelta
.
The implementation is a wrapper around
NaiveDate::signed_duration_since
.
ยงExample
use chrono::{NaiveDate, TimeDelta};
let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2014, 1, 1), TimeDelta::zero());
assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 12, 31), TimeDelta::try_days(1).unwrap());
assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2014, 1, 2), TimeDelta::try_days(-1).unwrap());
assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 9, 23), TimeDelta::try_days(100).unwrap());
assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 1, 1), TimeDelta::try_days(365).unwrap());
assert_eq!(
from_ymd(2014, 1, 1) - from_ymd(2010, 1, 1),
TimeDelta::try_days(365 * 4 + 1).unwrap()
);
assert_eq!(
from_ymd(2014, 1, 1) - from_ymd(1614, 1, 1),
TimeDelta::try_days(365 * 400 + 97).unwrap()
);
Sourceยงimpl SubAssign<TimeDelta> for NaiveDate
impl SubAssign<TimeDelta> for NaiveDate
Subtract-assign TimeDelta
from NaiveDate
.
This discards the fractional days in TimeDelta
, rounding to the closest integral number of
days towards TimeDelta::zero()
.
It is the same as the addition with a negated TimeDelta
.
ยงPanics
Panics if the resulting date would be out of range.
Consider using NaiveDate::checked_sub_signed
to get an Option
instead.
Sourceยงfn sub_assign(&mut self, rhs: TimeDelta)
fn sub_assign(&mut self, rhs: TimeDelta)
-=
operation. Read moreSourceยงimpl TryFromU64 for NaiveDate
impl TryFromU64 for NaiveDate
Sourceยงimpl TryGetable for NaiveDate
impl TryGetable for NaiveDate
Sourceยงfn try_get_by<I: ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError>
fn try_get_by<I: ColIdx>(res: &QueryResult, idx: I) -> Result<Self, TryGetError>
Sourceยงfn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError>
fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError>
Sourceยงfn try_get_by_index(
res: &QueryResult,
index: usize,
) -> Result<Self, TryGetError>
fn try_get_by_index( res: &QueryResult, index: usize, ) -> Result<Self, TryGetError>
Sourceยงimpl Type<Sqlite> for NaiveDate
impl Type<Sqlite> for NaiveDate
Sourceยงfn type_info() -> SqliteTypeInfo
fn type_info() -> SqliteTypeInfo
Sourceยงfn compatible(ty: &SqliteTypeInfo) -> bool
fn compatible(ty: &SqliteTypeInfo) -> bool
impl Copy for NaiveDate
impl Eq for NaiveDate
impl NotU8 for NaiveDate
impl StructuralPartialEq for NaiveDate
Auto Trait Implementationsยง
impl Freeze for NaiveDate
impl RefUnwindSafe for NaiveDate
impl Send for NaiveDate
impl Sync for NaiveDate
impl Unpin for NaiveDate
impl UnwindSafe for NaiveDate
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงunsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)Sourceยงimpl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Sourceยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Sourceยงimpl<T> ExprTrait for Twhere
T: Into<SimpleExpr>,
impl<T> ExprTrait for Twhere
T: Into<SimpleExpr>,
Sourceยงfn as_enum<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
fn as_enum<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
AS enum
expression. Read moreSourceยงfn binary<O, R>(self, op: O, right: R) -> SimpleExpr
fn binary<O, R>(self, op: O, right: R) -> SimpleExpr
Sourceยงfn cast_as<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
fn cast_as<N>(self, type_name: N) -> SimpleExprwhere
N: IntoIden,
CAST AS
expression. Read moreSourceยงfn unary(self, op: UnOper) -> SimpleExpr
fn unary(self, op: UnOper) -> SimpleExpr
Sourceยงfn add<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn add<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn and<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Sourceยงfn between<A, B>(self, a: A, b: B) -> SimpleExpr
fn between<A, B>(self, a: A, b: B) -> SimpleExpr
BETWEEN
expression. Read moreSourceยงfn div<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn div<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Sourceยงfn eq<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn eq<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
=
) expression. Read moreSourceยงfn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
fn equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
Sourceยงfn gt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn gt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
>
) expression. Read moreSourceยงfn gte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn gte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
>=
) expression. Read moreSourceยงfn in_subquery(self, sel: SelectStatement) -> SimpleExpr
fn in_subquery(self, sel: SelectStatement) -> SimpleExpr
IN
sub-query expression. Read moreSourceยงfn in_tuples<V, I>(self, v: I) -> SimpleExprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
fn in_tuples<V, I>(self, v: I) -> SimpleExprwhere
V: IntoValueTuple,
I: IntoIterator<Item = V>,
IN
sub expression. Read moreSourceยงfn is<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn is<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
IS
expression. Read moreSourceยงfn is_in<V, I>(self, v: I) -> SimpleExpr
fn is_in<V, I>(self, v: I) -> SimpleExpr
IN
expression. Read moreSourceยงfn is_not<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn is_not<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
IS NOT
expression. Read moreSourceยงfn is_not_in<V, I>(self, v: I) -> SimpleExpr
fn is_not_in<V, I>(self, v: I) -> SimpleExpr
NOT IN
expression. Read moreSourceยงfn is_not_null(self) -> SimpleExpr
fn is_not_null(self) -> SimpleExpr
IS NOT NULL
expression. Read moreSourceยงfn is_null(self) -> SimpleExpr
fn is_null(self) -> SimpleExpr
IS NULL
expression. Read moreSourceยงfn left_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn left_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Sourceยงfn like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
LIKE
expression. Read moreSourceยงfn lt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn lt<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
<
) expression. Read moreSourceยงfn lte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn lte<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
<=
) expression. Read moreSourceยงfn modulo<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn modulo<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Sourceยงfn mul<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn mul<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Sourceยงfn ne<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn ne<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
<>
) expression. Read moreSourceยงfn not(self) -> SimpleExpr
fn not(self) -> SimpleExpr
NOT
. Read moreSourceยงfn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
fn not_between<A, B>(self, a: A, b: B) -> SimpleExpr
NOT BETWEEN
expression. Read moreSourceยงfn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
fn not_equals<C>(self, col: C) -> SimpleExprwhere
C: IntoColumnRef,
Sourceยงfn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
fn not_in_subquery(self, sel: SelectStatement) -> SimpleExpr
NOT IN
sub-query expression. Read moreSourceยงfn not_like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
fn not_like<L>(self, like: L) -> SimpleExprwhere
L: IntoLikeExpr,
NOT LIKE
expression. Read moreSourceยงfn or<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn or<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
OR
operation. Read moreSourceยงfn right_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn right_shift<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Sourceยงfn sub<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
fn sub<R>(self, right: R) -> SimpleExprwhere
R: Into<SimpleExpr>,
Sourceยงimpl<V> FromValueTuple for V
impl<V> FromValueTuple for V
fn from_value_tuple<I>(i: I) -> Vwhere
I: IntoValueTuple,
Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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