Skip to content

Commit

Permalink
tz: re-arrange relative ordering of methods on Offset
Browse files Browse the repository at this point in the history
This makes it match how 'add' and 'until' methods are ordered on the
datetime types.
  • Loading branch information
BurntSushi committed Aug 14, 2024
1 parent 8cc6312 commit e329b2e
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions src/tz/offset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,67 +453,6 @@ impl Offset {
.checked_sub_seconds(i64::from(self.seconds()))
}

/// Returns the span of time from this offset until the other given.
///
/// When the `other` offset is more west (i.e., more negative) of the prime
/// meridian than this offset, then the span returned will be negative.
///
/// # Properties
///
/// Adding the span returned to this offset will always equal the `other`
/// offset given.
///
/// # Examples
///
/// ```
/// use jiff::{tz, ToSpan};
///
/// assert_eq!(
/// tz::offset(-5).until(tz::Offset::UTC),
/// (5 * 60 * 60).seconds(),
/// );
/// // Flipping the operands in this case results in a negative span.
/// assert_eq!(
/// tz::Offset::UTC.until(tz::offset(-5)),
/// -(5 * 60 * 60).seconds(),
/// );
/// ```
#[inline]
pub fn until(self, other: Offset) -> Span {
Span::new()
.seconds_ranged(other.seconds_ranged() - self.seconds_ranged())
}

/// Returns the span of time since the other offset given from this offset.
///
/// When the `other` is more east (i.e., more positive) of the prime
/// meridian than this offset, then the span returned will be negative.
///
/// # Properties
///
/// Adding the span returned to the `other` offset will always equal this
/// offset.
///
/// # Examples
///
/// ```
/// use jiff::{tz, ToSpan};
///
/// assert_eq!(
/// tz::Offset::UTC.since(tz::offset(-5)),
/// (5 * 60 * 60).seconds(),
/// );
/// // Flipping the operands in this case results in a negative span.
/// assert_eq!(
/// tz::offset(-5).since(tz::Offset::UTC),
/// -(5 * 60 * 60).seconds(),
/// );
/// ```
#[inline]
pub fn since(self, other: Offset) -> Span {
self.until(other).negate()
}

/// Adds the given span of time to this offset.
///
/// Since time zone offsets have second resolution, any fractional seconds
Expand Down Expand Up @@ -679,6 +618,67 @@ impl Offset {
self.saturating_add(span.negate())
}

/// Returns the span of time from this offset until the other given.
///
/// When the `other` offset is more west (i.e., more negative) of the prime
/// meridian than this offset, then the span returned will be negative.
///
/// # Properties
///
/// Adding the span returned to this offset will always equal the `other`
/// offset given.
///
/// # Examples
///
/// ```
/// use jiff::{tz, ToSpan};
///
/// assert_eq!(
/// tz::offset(-5).until(tz::Offset::UTC),
/// (5 * 60 * 60).seconds(),
/// );
/// // Flipping the operands in this case results in a negative span.
/// assert_eq!(
/// tz::Offset::UTC.until(tz::offset(-5)),
/// -(5 * 60 * 60).seconds(),
/// );
/// ```
#[inline]
pub fn until(self, other: Offset) -> Span {
Span::new()
.seconds_ranged(other.seconds_ranged() - self.seconds_ranged())
}

/// Returns the span of time since the other offset given from this offset.
///
/// When the `other` is more east (i.e., more positive) of the prime
/// meridian than this offset, then the span returned will be negative.
///
/// # Properties
///
/// Adding the span returned to the `other` offset will always equal this
/// offset.
///
/// # Examples
///
/// ```
/// use jiff::{tz, ToSpan};
///
/// assert_eq!(
/// tz::Offset::UTC.since(tz::offset(-5)),
/// (5 * 60 * 60).seconds(),
/// );
/// // Flipping the operands in this case results in a negative span.
/// assert_eq!(
/// tz::offset(-5).since(tz::Offset::UTC),
/// -(5 * 60 * 60).seconds(),
/// );
/// ```
#[inline]
pub fn since(self, other: Offset) -> Span {
self.until(other).negate()
}

/// Returns this offset as a [`Span`].
#[inline]
pub(crate) fn to_span(self) -> Span {
Expand Down

0 comments on commit e329b2e

Please sign in to comment.