Struct FixedOffset

pub struct FixedOffset { /* private fields */ }

The time zone with fixed offset, from UTC-23:59:59 to UTC+23:59:59.

Using the TimeZone methods on a FixedOffset struct is the preferred way to construct DateTime<FixedOffset> instances. See the east_opt and west_opt methods for examples.

Implementations

impl FixedOffset

fn east(secs: i32) -> FixedOffset

Makes a new FixedOffset for the Eastern Hemisphere with given timezone difference. The negative secs means the Western Hemisphere.

Panics on the out-of-bound secs.

const fn east_opt(secs: i32) -> Option<FixedOffset>

Makes a new FixedOffset for the Eastern Hemisphere with given timezone difference. The negative secs means the Western Hemisphere.

Returns None on the out-of-bound secs.

Example

# #[cfg(feature = "alloc")] {
use chrono::{FixedOffset, TimeZone};
let hour = 3600;
let datetime =
    FixedOffset::east_opt(5 * hour).unwrap().with_ymd_and_hms(2016, 11, 08, 0, 0, 0).unwrap();
assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00+05:00")
# }
fn west(secs: i32) -> FixedOffset

Makes a new FixedOffset for the Western Hemisphere with given timezone difference. The negative secs means the Eastern Hemisphere.

Panics on the out-of-bound secs.

const fn west_opt(secs: i32) -> Option<FixedOffset>

Makes a new FixedOffset for the Western Hemisphere with given timezone difference. The negative secs means the Eastern Hemisphere.

Returns None on the out-of-bound secs.

Example

# #[cfg(feature = "alloc")] {
use chrono::{FixedOffset, TimeZone};
let hour = 3600;
let datetime =
    FixedOffset::west_opt(5 * hour).unwrap().with_ymd_and_hms(2016, 11, 08, 0, 0, 0).unwrap();
assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00-05:00")
# }
const fn local_minus_utc(&self) -> i32

Returns the number of seconds to add to convert from UTC to the local time.

const fn utc_minus_local(&self) -> i32

Returns the number of seconds to add to convert from the local time to UTC.

Trait Implementations

impl Clone for FixedOffset

fn clone(&self) -> FixedOffset

impl Copy for FixedOffset

impl Debug for FixedOffset

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Display for FixedOffset

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Eq for FixedOffset

impl FromStr for FixedOffset

type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err>

impl Hash for FixedOffset

fn hash<__H: Hasher>(&self, state: &mut __H)

impl Offset for FixedOffset

fn fix(&self) -> FixedOffset

impl PartialEq for FixedOffset

fn eq(&self, other: &FixedOffset) -> bool

impl StructuralPartialEq for FixedOffset

impl TimeZone for FixedOffset

type Offset = FixedOffset;
fn from_offset(offset: &FixedOffset) -> FixedOffset
fn offset_from_local_date(&self, _local: &NaiveDate) -> MappedLocalTime<FixedOffset>
fn offset_from_local_datetime(&self, _local: &NaiveDateTime) -> MappedLocalTime<FixedOffset>
fn offset_from_utc_date(&self, _utc: &NaiveDate) -> FixedOffset
fn offset_from_utc_datetime(&self, _utc: &NaiveDateTime) -> FixedOffset

Auto Trait Implementations

impl Freeze for FixedOffset

impl RefUnwindSafe for FixedOffset

impl Send for FixedOffset

impl Sync for FixedOffset

impl Unpin for FixedOffset

impl UnsafeUnpin for FixedOffset

impl UnwindSafe for FixedOffset

Blanket Implementations

impl<T> Any for FixedOffset where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for FixedOffset where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for FixedOffset where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for FixedOffset where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for FixedOffset

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for FixedOffset where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> ToString for FixedOffset where T: Display + ?Sized,

fn to_string(&self) -> String

impl<T, U> Into<U> for FixedOffset where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for FixedOffset where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for FixedOffset where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>