@@ -25,7 +25,7 @@ use crate::format::{write_rfc2822, write_rfc3339, DelayedFormat, SecondsFormat};
2525use crate :: naive:: { Days , IsoWeek , NaiveDate , NaiveDateTime , NaiveTime } ;
2626#[ cfg( feature = "clock" ) ]
2727use crate :: offset:: Local ;
28- use crate :: offset:: { FixedOffset , LocalResult , Offset , TimeZone , Utc } ;
28+ use crate :: offset:: { FixedOffset , FromOffset , LocalResult , Offset , TimeZone , Utc } ;
2929#[ allow( deprecated) ]
3030use crate :: Date ;
3131use crate :: { expect, try_opt} ;
@@ -405,14 +405,30 @@ impl<Tz: TimeZone> DateTime<Tz> {
405405 }
406406
407407 /// Changes the associated time zone.
408- /// The returned `DateTime` references the same instant of time from the perspective of the
409- /// provided time zone.
408+ ///
409+ /// The returned `DateTime` references the same instant of time in UTC but with the offset of
410+ /// the target time zone.
410411 #[ inline]
411412 #[ must_use]
412413 pub fn with_timezone < Tz2 : TimeZone > ( & self , tz : & Tz2 ) -> DateTime < Tz2 > {
413414 tz. from_utc_datetime ( & self . datetime )
414415 }
415416
417+ /// Changes the associated `TimeZone` type.
418+ ///
419+ /// The returned `DateTime` references the same instant of time in UTC but with another
420+ /// [`TimeZone`] type. A best effort is made to convert the value of the associated [`Offset`]
421+ /// type to the `Offset` type of the target `TimeZone`.
422+ #[ inline]
423+ #[ must_use]
424+ pub fn to_timezone < Tz2 : TimeZone > ( & self ) -> DateTime < Tz2 >
425+ where
426+ <Tz2 as TimeZone >:: Offset : FromOffset < <Tz as TimeZone >:: Offset > ,
427+ {
428+ let new_offset = <Tz2 as TimeZone >:: Offset :: from_offset ( self . offset ( ) ) ;
429+ DateTime { datetime : self . datetime , offset : new_offset }
430+ }
431+
416432 /// Fix the offset from UTC to its current value, dropping the associated timezone information.
417433 /// This it useful for converting a generic `DateTime<Tz: Timezone>` to `DateTime<FixedOffset>`.
418434 #[ inline]
0 commit comments