Skip to content

Commit

Permalink
add from_local
Browse files Browse the repository at this point in the history
  • Loading branch information
esheppa committed Apr 30, 2024
1 parent c566dba commit 7bac31b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/zoned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ where
}
}

impl<R, Z> Zoned<R, Z>
where
R: SubDateResolution<Params = ()>,
Z: FixedTimeZone,
{
pub fn from_local(value: R, zone: Z) -> Self {
value
.start_datetime()
.naive_utc()
.and_local_timezone(zone)
.single()
// unwrap will never panic becuase calling
// `and_local_timezone` with a FixedTimeZone will
// always reuturn a valid local time
.unwrap()
.into()
}
}

impl<R, Z> Zoned<R, Z>
where
R: TimeResolution,
Expand Down

0 comments on commit 7bac31b

Please sign in to comment.