mirror of
https://github.com/chronotope/chrono.git
synced 2025-10-02 15:26:12 +00:00
Add TimeZone::with_ymd_and_hms() helper method
We don't add `with_yo_and_hms()` and `with_isoywd_and_hms()` here, instead recommending users can use `from_local_datetime()` with a separately constructed `NaiveDateTime`.
This commit is contained in:
parent
03165c8658
commit
7ba090d484
@ -206,6 +206,27 @@ pub trait TimeZone: Sized + Clone {
|
|||||||
/// The original `TimeZone` value can be recovered via `TimeZone::from_offset`.
|
/// The original `TimeZone` value can be recovered via `TimeZone::from_offset`.
|
||||||
type Offset: Offset;
|
type Offset: Offset;
|
||||||
|
|
||||||
|
/// Make a new `DateTime` from year, month, day, time components and current time zone.
|
||||||
|
///
|
||||||
|
/// This assumes the proleptic Gregorian calendar, with the year 0 being 1 BCE.
|
||||||
|
///
|
||||||
|
/// Returns `LocalResult::None` on invalid input data.
|
||||||
|
fn with_ymd_and_hms(
|
||||||
|
&self,
|
||||||
|
year: i32,
|
||||||
|
month: u32,
|
||||||
|
day: u32,
|
||||||
|
hour: u32,
|
||||||
|
min: u32,
|
||||||
|
sec: u32,
|
||||||
|
) -> LocalResult<DateTime<Self>> {
|
||||||
|
match NaiveDate::from_ymd_opt(year, month, day).and_then(|d| d.and_hms_opt(hour, min, sec))
|
||||||
|
{
|
||||||
|
Some(dt) => self.from_local_datetime(&dt),
|
||||||
|
None => LocalResult::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Makes a new `Date` from year, month, day and the current time zone.
|
/// Makes a new `Date` from year, month, day and the current time zone.
|
||||||
/// This assumes the proleptic Gregorian calendar, with the year 0 being 1 BCE.
|
/// This assumes the proleptic Gregorian calendar, with the year 0 being 1 BCE.
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user