Struct BrokenDownTime
struct BrokenDownTime { ... }
The "broken down time" used by parsing and formatting.
This is a lower level aspect of the strptime and strftime APIs that you
probably won't need to use directly. The main use case is if you want to
observe formatting errors or if you want to format a datetime to something
other than a String via the fmt::Write trait.
Otherwise, typical use of this module happens indirectly via APIs like
Zoned::strptime and Zoned::strftime.
Design
This is the type that parsing writes to and formatting reads from. That
is, parsing proceeds by writing individual parsed fields to this type, and
then converting the fields to datetime types like Zoned only after
parsing is complete. Similarly, formatting always begins by converting
datetime types like Zoned into a BrokenDownTime, and then formatting
the individual fields from there.
Implementations
impl BrokenDownTime
fn parse<impl AsRef<[u8]>: AsRef<[u8]>, impl AsRef<[u8]>: AsRef<[u8]>>(format: impl AsRef<[u8]>, input: impl AsRef<[u8]>) -> Result<BrokenDownTime, Error>Parse the given
inputaccording to the givenformatstring.See the module documentation for details on what's supported.
This routine is the same as the module level free function
strtime::parse.Errors
This returns an error when parsing failed. This might happen because the format string itself was invalid, or because the input didn't match the format string.
Example
use ; let tm = parse?; let date = tm.to_date?; assert_eq!; # Ok::fn parse_prefix<impl AsRef<[u8]>: AsRef<[u8]>, impl AsRef<[u8]>: AsRef<[u8]>>(format: impl AsRef<[u8]>, input: impl AsRef<[u8]>) -> Result<(BrokenDownTime, usize), Error>Parse a prefix of the given
inputaccording to the givenformatstring. The offset returned corresponds to the number of bytes parsed. That is, the length of the prefix (which may be the length of the entire input if there are no unparsed bytes remaining).See the module documentation for details on what's supported.
This is like
BrokenDownTime::parse, but it won't return an error if there is input remaining after parsing the format directives.Errors
This returns an error when parsing failed. This might happen because the format string itself was invalid, or because the input didn't match the format string.
Example
use ; // %y only parses two-digit years, so the 99 following // 24 is unparsed! let input = "7/14/2499"; let = parse_prefix?; let date = tm.to_date?; assert_eq!; assert_eq!; assert_eq!; # Ok::If the entire input is parsed, then the offset is the length of the input:
use ; let = parse_prefix?; let date = tm.to_date?; assert_eq!; assert_eq!; # Ok::Example: how to parse a only parse of a timestamp
If you only need, for example, the date from a timestamp, then you can parse it as a prefix:
use ; let input = "2024-01-20T17:55Z"; let = parse_prefix?; let date = tm.to_date?; assert_eq!; assert_eq!; assert_eq!; # Ok::Note though that Jiff's default parsing functions are already quite flexible, and one can just parse a civil date directly from a timestamp automatically:
use civil; let input = "2024-01-20T17:55-05"; let date: Date = input.parse?; assert_eq!; # Ok::Although in this case, you don't get the length of the prefix parsed.
fn format<W: Write, impl AsRef<[u8]>: AsRef<[u8]>>(self: &Self, format: impl AsRef<[u8]>, wtr: W) -> Result<(), Error>Format this broken down time using the format string given.
See the module documentation for details on what's supported.
This routine is like the module level free function
strtime::format, except it takes afmt::Writetrait implementations instead of assuming you want aString.Errors
This returns an error when formatting failed. Formatting can fail either because of an invalid format string, or if formatting requires a field in
BrokenDownTimeto be set that isn't. For example, trying to format aDateTimewith the%zspecifier will fail because aDateTimehas no time zone or offset information associated with it.Formatting also fails if writing to the given writer fails.
Example
This example shows a formatting option,
%Z, that isn't available during parsing. Namely,%Zinserts a time zone abbreviation. This is generally only intended for display purposes, since it can be ambiguous when parsing.use ; let zdt = date.at.in_tz?; let tm = from; let mut buf = Stringnew; tm.format?; assert_eq!; # Ok::fn to_string<impl AsRef<[u8]>: AsRef<[u8]>>(self: &Self, format: impl AsRef<[u8]>) -> Result<alloc::string::String, Error>Format this broken down time using the format string given into a new
String.See the module documentation for details on what's supported.
This is like
BrokenDownTime::format, but always uses aStringto format the time into. If you need to reuse allocations or write a formatted time into a different type, then you should useBrokenDownTime::formatinstead.Errors
This returns an error when formatting failed. Formatting can fail either because of an invalid format string, or if formatting requires a field in
BrokenDownTimeto be set that isn't. For example, trying to format aDateTimewith the%zspecifier will fail because aDateTimehas no time zone or offset information associated with it.Example
This example shows a formatting option,
%Z, that isn't available during parsing. Namely,%Zinserts a time zone abbreviation. This is generally only intended for display purposes, since it can be ambiguous when parsing.use ; let zdt = date.at.in_tz?; let tm = from; let string = tm.to_string?; assert_eq!; # Ok::fn to_zoned(self: &Self) -> Result<Zoned, Error>Extracts a zoned datetime from this broken down time.
When an IANA time zone identifier is present but an offset is not, then the
Disambiguation::Compatiblestrategy is used if the parsed datetime is ambiguous in the time zone.If you need to use a custom time zone database for doing IANA time zone identifier lookups (via the
%Qdirective), then useBrokenDownTime::to_zoned_with.Warning
The
strtimemodule APIs do not require an IANA time zone identifier to parse aZoned. If one is not used, then if you format a zoned datetime in a time zone likeAmerica/New_Yorkand then parse it back again, the zoned datetime you get back will be a "fixed offset" zoned datetime. This in turn means it will not perform daylight saving time safe arithmetic.However, the
%Qdirective may be used to both format and parse an IANA time zone identifier. It is strongly recommended to use this directive whenever one is formatting or parsingZonedvalues.Errors
This returns an error if there weren't enough components to construct a civil datetime and either a UTC offset or a IANA time zone identifier. When both a UTC offset and an IANA time zone identifier are found, then
OffsetConflict::Rejectis used to detect any inconsistency between the offset and the time zone.Example
This example shows how to parse a zoned datetime:
use strtime; let zdt = parse?.to_zoned?; assert_eq!; # Ok::This shows that an error is returned when the offset is inconsistent with the time zone. For example,
US/Easternis in daylight saving time in July 2024:use strtime; let result = parse?.to_zoned; assert_eq!; # Ok::fn to_zoned_with(self: &Self, db: &TimeZoneDatabase) -> Result<Zoned, Error>Extracts a zoned datetime from this broken down time and uses the time zone database given for any IANA time zone identifier lookups.
An IANA time zone identifier lookup is only performed when this
BrokenDownTimecontains an IANA time zone identifier. An IANA time zone identifier can be parsed with the%Qdirective.When an IANA time zone identifier is present but an offset is not, then the
Disambiguation::Compatiblestrategy is used if the parsed datetime is ambiguous in the time zone.Warning
The
strtimemodule APIs do not require an IANA time zone identifier to parse aZoned. If one is not used, then if you format a zoned datetime in a time zone likeAmerica/New_Yorkand then parse it back again, the zoned datetime you get back will be a "fixed offset" zoned datetime. This in turn means it will not perform daylight saving time safe arithmetic.However, the
%Qdirective may be used to both format and parse an IANA time zone identifier. It is strongly recommended to use this directive whenever one is formatting or parsingZonedvalues.Errors
This returns an error if there weren't enough components to construct a civil datetime and either a UTC offset or a IANA time zone identifier. When both a UTC offset and an IANA time zone identifier are found, then
OffsetConflict::Rejectis used to detect any inconsistency between the offset and the time zone.Example
This example shows how to parse a zoned datetime:
use strtime; let zdt = parse?.to_zoned_with?; assert_eq!; # Ok::fn to_timestamp(self: &Self) -> Result<Timestamp, Error>Extracts a timestamp from this broken down time.
Errors
This returns an error if there weren't enough components to construct a civil datetime and a UTC offset.
Example
This example shows how to parse a timestamp from a broken down time:
use strtime; let ts = parse?.to_timestamp?; assert_eq!; # Ok::fn to_datetime(self: &Self) -> Result<DateTime, Error>Extracts a civil datetime from this broken down time.
Errors
This returns an error if there weren't enough components to construct a civil datetime. This means there must be at least a year, month and day.
It's okay if there are more units than are needed to construct a civil datetime. For example, if this broken down time contains an offset, then it won't prevent a conversion to a civil datetime.
Example
This example shows how to parse a civil datetime from a broken down time:
use strtime; let dt = parse?.to_datetime?; assert_eq!; # Ok::fn to_date(self: &Self) -> Result<Date, Error>Extracts a civil date from this broken down time.
This requires that the year is set along with a way to identify the day in the year. This can be done by either setting the month and the day of the month (
%mand%d), or by setting the day of the year (%j).Errors
This returns an error if there weren't enough components to construct a civil date. This means there must be at least a year and either the month and day or the day of the year.
It's okay if there are more units than are needed to construct a civil datetime. For example, if this broken down time contain a civil time, then it won't prevent a conversion to a civil date.
Example
This example shows how to parse a civil date from a broken down time:
use strtime; let date = parse?.to_date?; assert_eq!; # Ok::fn to_time(self: &Self) -> Result<Time, Error>Extracts a civil time from this broken down time.
Errors
This returns an error if there weren't enough components to construct a civil time. Interestingly, this succeeds if there are no time units, since this will assume an absent time is midnight. However, this can still error when, for example, there are minutes but no hours.
It's okay if there are more units than are needed to construct a civil time. For example, if this broken down time contains a date, then it won't prevent a conversion to a civil time.
Example
This example shows how to parse a civil time from a broken down time:
use strtime; let time = parse?.to_time?; assert_eq!; # Ok::Example: time defaults to midnight
Since time defaults to midnight, one can parse an empty input string with an empty format string and still extract a
Time:use strtime; let time = parse?.to_time?; assert_eq!; # Ok::Example: invalid time
Other than using illegal values (like
24for hours), if lower units are parsed without higher units, then this results in an error:use strtime; assert!; # Ok::Example: invalid date
Since validation of a date is only done when a date is requested, it is actually possible to parse an invalid date and extract the time without an error occurring:
use strtime; // 31 is a legal day value, but not for June. // However, this is not validated unless you // ask for a `Date` from the parsed `BrokenDownTime`. // Everything except for `BrokenDownTime::time` // creates a date, so asking for only a `time` // will circumvent date validation! let tm = parse?; let time = tm.to_time?; assert_eq!; # Ok::fn year(self: &Self) -> Option<i16>Returns the parsed year, if available.
This is also set when a 2 digit year is parsed. (But that's limited to the years 1969 to 2068, inclusive.)
Example
This shows how to parse just a year:
use BrokenDownTime; let tm = parse?; assert_eq!; # Ok::And 2-digit years are supported too:
use BrokenDownTime; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; // 2-digit years have limited range. They must // be in the range 0-99. assert!; # Ok::fn month(self: &Self) -> Option<i8>Returns the parsed month, if available.
Example
This shows a few different ways of parsing just a month:
use BrokenDownTime; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; # Ok::fn day(self: &Self) -> Option<i8>Returns the parsed day, if available.
Example
This shows how to parse the day of the month:
use BrokenDownTime; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; // Parsing a day only works for all possible legal // values, even if, e.g., 31 isn't valid for all // possible year/month combinations. let tm = parse?; assert_eq!; // This is true even if you're parsing a full date: let tm = parse?; assert_eq!; // An error only occurs when you try to extract a date: assert!; // But parsing a value that is always illegal will // result in an error: assert!; # Ok::fn day_of_year(self: &Self) -> Option<i16>Returns the parsed day of the year (1-366), if available.
Example
This shows how to parse the day of the year:
use BrokenDownTime; let tm = parse?; assert_eq!; assert_eq!; assert_eq!; // Parsing the day of the year works for all possible legal // values, even if, e.g., 366 isn't valid for all possible // year/month combinations. let tm = parse?; assert_eq!; // This is true even if you're parsing a year: let tm = parse?; assert_eq!; // An error only occurs when you try to extract a date: assert_eq!; // But parsing a value that is always illegal will // result in an error: assert!; assert!; # Ok::Example: extract a
DateThis example shows how parsing a year and a day of the year enables the extraction of a date:
use ; let tm = parse?; assert_eq!; # Ok::When all of
%m,%dand%jare used, then%mand%dtake priority over%jwhen extracting aDatefrom aBrokenDownTime. However,%jis still parsed and accessible:use ; let tm = parse?; assert_eq!; assert_eq!; # Ok::fn iso_week_year(self: &Self) -> Option<i16>Returns the parsed ISO 8601 week-based year, if available.
This is also set when a 2 digit ISO 8601 week-based year is parsed. (But that's limited to the years 1969 to 2068, inclusive.)
Example
This shows how to parse just an ISO 8601 week-based year:
use BrokenDownTime; let tm = parse?; assert_eq!; # Ok::And 2-digit years are supported too:
use BrokenDownTime; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; // 2-digit years have limited range. They must // be in the range 0-99. assert!; # Ok::fn iso_week(self: &Self) -> Option<i8>Returns the parsed ISO 8601 week-based number, if available.
The week number is guaranteed to be in the range
1..53. Week1is the first week of the year to contain 4 days.Example
This shows how to parse just an ISO 8601 week-based dates:
use ; let tm = parse?; assert_eq!; assert_eq!; assert_eq!; assert_eq!; # Ok::fn sunday_based_week(self: &Self) -> Option<i8>Returns the Sunday based week number.
The week number returned is always in the range
0..=53. Week1begins on the first Sunday of the year. Any days in the year prior to week1are in week0.Example
use ; let tm = parse?; assert_eq!; assert_eq!; assert_eq!; assert_eq!; # Ok::fn monday_based_week(self: &Self) -> Option<i8>Returns the Monday based week number.
The week number returned is always in the range
0..=53. Week1begins on the first Monday of the year. Any days in the year prior to week1are in week0.Example
use ; let tm = parse?; assert_eq!; assert_eq!; assert_eq!; assert_eq!; # Ok::fn hour(self: &Self) -> Option<i8>Returns the parsed hour, if available.
The hour returned incorporates
BrokenDownTime::meridiemif it's set. That is, if the actual parsed hour value is1but the meridiem isPM, then the hour returned by this method will be13.Example
This shows a how to parse an hour:
use BrokenDownTime; let tm = parse?; assert_eq!; // When parsing a 12-hour clock without a // meridiem, the hour value is as parsed. let tm = parse?; assert_eq!; // If a meridiem is parsed, then it is used // to calculate the correct hour value. let tm = parse?; assert_eq!; // This works even if the hour and meridiem are // inconsistent with each other: let tm = parse?; assert_eq!; # Ok::fn minute(self: &Self) -> Option<i8>Returns the parsed minute, if available.
Example
This shows how to parse the minute:
use BrokenDownTime; let tm = parse?; assert_eq!; # Ok::fn second(self: &Self) -> Option<i8>Returns the parsed second, if available.
Example
This shows how to parse the second:
use BrokenDownTime; let tm = parse?; assert_eq!; # Ok::fn subsec_nanosecond(self: &Self) -> Option<i32>Returns the parsed subsecond nanosecond, if available.
Example
This shows how to parse fractional seconds:
use BrokenDownTime; let tm = parse?; assert_eq!; # Ok::Note that when using
%.f, the fractional component is optional!use BrokenDownTime; let tm = parse?; assert_eq!; assert_eq!; let tm = parse?; assert_eq!; assert_eq!; # Ok::fn offset(self: &Self) -> Option<Offset>Returns the parsed offset, if available.
Example
This shows how to parse the offset:
use ; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; // Or, if you want colons: let tm = parse?; assert_eq!; # Ok::fn iana_time_zone(self: &Self) -> Option<&str>Returns the time zone IANA identifier, if available.
Note that when
allocis disabled, this always returnsNone. (And there is no way to set it.)Example
This shows how to parse an IANA time zone identifier:
use ; let tm = parse?; assert_eq!; assert_eq!; // Note that %Q (and %:Q) also support parsing an offset // as a fallback. If that occurs, an IANA time zone // identifier is not available. let tm = parse?; assert_eq!; assert_eq!; # Ok::fn weekday(self: &Self) -> Option<Weekday>Returns the parsed weekday, if available.
Example
This shows a few different ways of parsing just a weekday:
use ; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; // A weekday is only available if it is explicitly parsed! let tm = parse?; assert_eq!; // If you need a weekday derived from a parsed date, then: assert_eq!; # Ok::Note that this will return the parsed weekday even if it's inconsistent with a parsed date:
use ; let mut tm = parse?; // 2024-07-27 is a Saturday, but Wednesday was parsed: assert_eq!; // An error only occurs when extracting a date: assert!; // To skip the weekday, error checking, zero it out first: tm.set_weekday; assert_eq!; # Ok::fn meridiem(self: &Self) -> Option<Meridiem>Returns the parsed meridiem, if available.
Note that unlike other fields, there is no
BrokenDownTime::set_meridiem. Instead, when formatting, the meridiem label (if it's used in the formatting string) is determined purely as a function of the hour in a 24 hour clock.Example
This shows a how to parse the meridiem:
use ; let tm = parse?; assert_eq!; let tm = parse?; assert_eq!; # Ok::fn set_year(self: &mut Self, year: Option<i16>) -> Result<(), Error>Set the year on this broken down time.
Errors
This returns an error if the given year is out of range.
Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_year?; assert_eq!; # Ok::fn set_month(self: &mut Self, month: Option<i8>) -> Result<(), Error>Set the month on this broken down time.
Errors
This returns an error if the given month is out of range.
Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_month?; assert_eq!; # Ok::fn set_day(self: &mut Self, day: Option<i8>) -> Result<(), Error>Set the day on this broken down time.
Errors
This returns an error if the given day is out of range.
Note that setting a day to a value that is legal in any context is always valid, even if it isn't valid for the year and month components already set.
Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_day?; assert_eq!; // Works even if the resulting date is invalid. let mut tm = default; tm.set_year?; tm.set_month?; tm.set_day?; // April has 30 days, not 31 assert_eq!; # Ok::fn set_day_of_year(self: &mut Self, day: Option<i16>) -> Result<(), Error>Set the day of year on this broken down time.
Errors
This returns an error if the given day is out of range.
Note that setting a day to a value that is legal in any context is always valid, even if it isn't valid for the year, month and day-of-month components already set.
Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_day_of_year?; assert_eq!; // Works even if the resulting date is invalid. let mut tm = default; tm.set_year?; tm.set_day_of_year?; // 2023 wasn't a leap year assert_eq!; # Ok::fn set_iso_week_year(self: &mut Self, year: Option<i16>) -> Result<(), Error>Set the ISO 8601 week-based year on this broken down time.
Errors
This returns an error if the given year is out of range.
Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_iso_week_year?; assert_eq!; # Ok::fn set_iso_week(self: &mut Self, week_number: Option<i8>) -> Result<(), Error>Set the ISO 8601 week-based number on this broken down time.
The week number must be in the range
1..53. Week1is the first week of the year to contain 4 days.Errors
This returns an error if the given week number is out of range.
Example
use ; let mut tm = default; // out of range assert!; // out of range assert!; tm.set_iso_week_year?; tm.set_iso_week?; tm.set_weekday; assert_eq!; assert_eq!; # Ok::fn set_sunday_based_week(self: &mut Self, week_number: Option<i8>) -> Result<(), Error>Set the Sunday based week number.
The week number returned is always in the range
0..=53. Week1begins on the first Sunday of the year. Any days in the year prior to week1are in week0.Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_sunday_based_week?; assert_eq!; # Ok::fn set_monday_based_week(self: &mut Self, week_number: Option<i8>) -> Result<(), Error>Set the Monday based week number.
The week number returned is always in the range
0..=53. Week1begins on the first Monday of the year. Any days in the year prior to week1are in week0.Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_monday_based_week?; assert_eq!; # Ok::fn set_hour(self: &mut Self, hour: Option<i8>) -> Result<(), Error>Set the hour on this broken down time.
Errors
This returns an error if the given hour is out of range.
Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_hour?; assert_eq!; assert_eq!; # Ok::fn set_minute(self: &mut Self, minute: Option<i8>) -> Result<(), Error>Set the minute on this broken down time.
Errors
This returns an error if the given minute is out of range.
Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_minute?; assert_eq!; assert_eq!; assert_eq!; # Ok::fn set_second(self: &mut Self, second: Option<i8>) -> Result<(), Error>Set the second on this broken down time.
Errors
This returns an error if the given second is out of range.
Jiff does not support leap seconds, so the range of valid seconds is
0to59, inclusive. Note though that when parsing, a parsed value of60is automatically constrained to59.Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_second?; assert_eq!; # Ok::fn set_subsec_nanosecond(self: &mut Self, subsec_nanosecond: Option<i32>) -> Result<(), Error>Set the subsecond nanosecond on this broken down time.
Errors
This returns an error if the given number of nanoseconds is out of range. It must be non-negative and less than 1 whole second.
Example
use BrokenDownTime; let mut tm = default; // out of range assert!; tm.set_subsec_nanosecond?; assert_eq!; assert_eq!; # Ok::fn set_offset(self: &mut Self, offset: Option<Offset>)Set the time zone offset on this broken down time.
This can be useful for setting the offset after parsing if the offset is known from the context or from some out-of-band information.
Note that one can set any legal offset value, regardless of whether it's consistent with the IANA time zone identifier on this broken down time (if it's set). Similarly, setting the offset does not actually change any other value in this broken down time.
Example: setting the offset after parsing
One use case for this routine is when parsing a datetime without an offset, but where one wants to set an offset based on the context. For example, while it's usually not correct to assume a datetime is in UTC, if you know it is, then you can parse it into a
Timestamplike so:use ; let mut tm = parse?; tm.set_offset; // Normally this would fail since the parse // itself doesn't include an offset. It only // works here because we explicitly set the // offset after parsing. assert_eq!; # Ok::Example: setting the offset is not "smart"
This example shows how setting the offset on an existing broken down time does not impact any other field, even if the result printed is non-sensical:
use ; let zdt = date.at.in_tz?; let mut tm = from; tm.set_offset; assert_eq!; # Ok::fn set_iana_time_zone(self: &mut Self, id: Option<alloc::string::String>)Set the IANA time zone identifier on this broken down time.
This can be useful for setting the time zone after parsing if the time zone is known from the context or from some out-of-band information.
Note that one can set any string value, regardless of whether it's consistent with the offset on this broken down time (if it's set). Similarly, setting the IANA time zone identifier does not actually change any other value in this broken down time.
Example: setting the IANA time zone identifier after parsing
One use case for this routine is when parsing a datetime without a time zone, but where one wants to set a time zone based on the context.
use ; let mut tm = parse?; tm.set_iana_time_zone; // Normally this would fail since the parse // itself doesn't include an offset or a time // zone. It only works here because we // explicitly set the time zone after parsing. assert_eq!; # Ok::Example: setting the IANA time zone identifier is not "smart"
This example shows how setting the IANA time zone identifier on an existing broken down time does not impact any other field, even if the result printed is non-sensical:
use ; let zdt = date.at.in_tz?; let mut tm = from; tm.set_iana_time_zone; assert_eq!; // In fact, it's not even required that the string // given be a valid IANA time zone identifier! let mut tm = from; tm.set_iana_time_zone; assert_eq!; # Ok::fn set_weekday(self: &mut Self, weekday: Option<Weekday>)Set the weekday on this broken down time.
Example
use ; let mut tm = default; tm.set_weekday; assert_eq!; assert_eq!; assert_eq!; # Ok::Note that one use case for this routine is to enable parsing of weekdays in datetime, but skip checking that the weekday is valid for the parsed date.
use ; let mut tm = parse?; // 2024-07-27 was a Saturday, so asking for a date fails: assert!; // But we can remove the weekday from our broken down time: tm.set_weekday; assert_eq!; # Ok::The advantage of this approach is that it still ensures the parsed weekday is a valid weekday (for example,
Watwill cause parsing to fail), but doesn't require it to be consistent with the date. This is useful for interacting with systems that don't do strict error checking.
impl Debug for BrokenDownTime
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for BrokenDownTime
fn default() -> BrokenDownTime
impl Freeze for BrokenDownTime
impl From for BrokenDownTime
fn from(dt: DateTime) -> BrokenDownTime
impl From for BrokenDownTime
fn from(t: Time) -> BrokenDownTime
impl From for BrokenDownTime
fn from(wd: ISOWeekDate) -> BrokenDownTime
impl From for BrokenDownTime
fn from(ts: Timestamp) -> BrokenDownTime
impl From for BrokenDownTime
fn from(d: Date) -> BrokenDownTime
impl RefUnwindSafe for BrokenDownTime
impl Send for BrokenDownTime
impl Sync for BrokenDownTime
impl Unpin for BrokenDownTime
impl UnwindSafe for BrokenDownTime
impl<'a> From for BrokenDownTime
fn from(zdt: &'a Zoned) -> BrokenDownTime
impl<T> Any for BrokenDownTime
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for BrokenDownTime
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for BrokenDownTime
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for BrokenDownTime
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for BrokenDownTime
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for BrokenDownTime
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for BrokenDownTime
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>