Struct Offset
An offset from UTC in milliseconds. A positive value means that the local time is
ahead of UTC (e.g. for Europe); a negative value means that the local time is behind
UTC (e.g. for America).
Since 1.0.x
Availability net35-Client, PCL
Inherited Members
Namespace: NodaTime
Assembly: NodaTime.dll
Syntax
public struct Offset : IEquatable<Offset>, IComparable<Offset>, IFormattable, IComparable
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Fields
MaxValue
The maximum permitted offset; one millisecond less than a standard day after UTC.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static readonly Offset MaxValue
Field Value
Type | Description |
---|---|
Offset |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
MinValue
The minimum permitted offset; one millisecond less than a standard day before UTC.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static readonly Offset MinValue
Field Value
Type | Description |
---|---|
Offset |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Zero
An offset of zero ticks - effectively the permanent offset for UTC.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static readonly Offset Zero
Field Value
Type | Description |
---|---|
Offset |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Properties
Milliseconds
Gets the total number of milliseconds in the offset, which may be negative.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int Milliseconds { get; }
Property Value
Type | Description |
---|---|
Int32 |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Ticks
Returns the number of ticks represented by this offset, which may be negative.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public long Ticks { get; }
Property Value
Type | Description |
---|---|
Int64 | The number of ticks. |
Remarks
Offsets are only accurate to millisecond precision; the number of milliseconds is simply multiplied
by 10,000 to give the number of ticks.
Methods
Add(Offset, Offset)
Adds one Offset to another. Friendly alternative to
operator+()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset Add(Offset left, Offset right)
Parameters
Type | Name | Description |
---|---|---|
Offset | left | The left hand side of the operator. |
Offset | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Offset | A new Offset representing the sum of the given values. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
CompareTo(Offset)
Compares the current object with another object of the same type.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public int CompareTo(Offset other)
Parameters
Type | Name | Description |
---|---|---|
Offset | other | An object to compare with this object. |
Returns
Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|
Int32 |
A 32-bit signed integer that indicates the relative order of the objects being compared.
The return value has the following meanings:
|
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Equals(Offset)
Indicates whether the current object is equal to another object of the same type.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public bool Equals(Offset other)
Parameters
Type | Name | Description |
---|---|---|
Offset | other | An object to compare with this object. |
Returns
Type | Description |
---|---|
Boolean |
true if the current object is equal to the other parameter;
otherwise, false.
|
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Equals(Object)
Determines whether the specified Object is equal to this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The Object to compare with this instance. |
Returns
Type | Description |
---|---|
Boolean |
true if the specified Object is equal to this instance;
otherwise, false .
|
Overrides
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
FromHours(Int32)
Creates an offset with the specified number of hours, which may be negative.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset FromHours(int hours)
Parameters
Type | Name | Description |
---|---|---|
Int32 | hours | The number of hours to represent in the new offset. |
Returns
Type | Description |
---|---|
Offset | A new Offset representing the given value. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
FromHoursAndMinutes(Int32, Int32)
Creates an offset with the specified number of hours and minutes.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset FromHoursAndMinutes(int hours, int minutes)
Parameters
Type | Name | Description |
---|---|---|
Int32 | hours | The number of hours to represent in the new offset. |
Int32 | minutes | The number of minutes to represent in the new offset. |
Returns
Type | Description |
---|---|
Offset | A new Offset representing the given value. |
Remarks
The result simply takes the hours and minutes and converts each component into milliseconds
separately. As a result, a negative offset should usually be obtained by making both arguments
negative. For example, to obtain "three hours and ten minutes behind UTC" you might call
Offset.FromHoursAndMinutes(-3, -10)
.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
FromMilliseconds(Int32)
Returns the offset for the given milliseconds value, which may be negative.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset FromMilliseconds(int milliseconds)
Parameters
Type | Name | Description |
---|---|---|
Int32 | milliseconds | The int milliseconds value. |
Returns
Type | Description |
---|---|
Offset | The Offset for the given milliseconds value |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
FromTicks(Int64)
Creates a new offset from the given number of ticks, which may be negative.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset FromTicks(long ticks)
Parameters
Type | Name | Description |
---|---|---|
Int64 | ticks | The number of ticks specifying the length of the new offset. |
Returns
Type | Description |
---|---|
Offset | An offset representing the given number of ticks, to the (truncated) millisecond. |
Remarks
Offsets are only accurate to millisecond precision; the given number of ticks is simply divided
by 10,000 to give the number of milliseconds - any remainder is truncated.
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
GetHashCode()
Returns a hash code for this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
Overrides
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Max(Offset, Offset)
Returns the greater offset of the given two, i.e. the one which will give a later local
time when added to an instant.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset Max(Offset x, Offset y)
Parameters
Type | Name | Description |
---|---|---|
Offset | x | The first offset |
Offset | y | The second offset |
Returns
Type | Description |
---|---|
Offset | The greater offset of x and y . |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Min(Offset, Offset)
Returns the lower offset of the given two, i.e. the one which will give an earlier local
time when added to an instant.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset Min(Offset x, Offset y)
Parameters
Type | Name | Description |
---|---|---|
Offset | x | The first offset |
Offset | y | The second offset |
Returns
Type | Description |
---|---|
Offset | The lower offset of x and y . |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Minus(Offset)
Returns the result of subtracting another Offset from this one, for a fluent alternative to
operator-()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Offset Minus(Offset other)
Parameters
Type | Name | Description |
---|---|---|
Offset | other | The offset to subtract |
Returns
Type | Description |
---|---|
Offset | The result of subtracting the other offset from this one. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
Negate(Offset)
Returns the negation of the specified offset. This is the method form of the unary minus operator.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset Negate(Offset offset)
Parameters
Type | Name | Description |
---|---|---|
Offset | offset | The offset to negate. |
Returns
Type | Description |
---|---|
Offset | The negation of the specified offset. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Plus(Offset)
Returns the result of adding another Offset to this one, for a fluent alternative to
operator+()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public Offset Plus(Offset other)
Parameters
Type | Name | Description |
---|---|---|
Offset | other | The offset to add |
Returns
Type | Description |
---|---|
Offset | The result of adding the other offset to this one. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
Subtract(Offset, Offset)
Subtracts one Offset from another. Friendly alternative to
operator-()
.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset Subtract(Offset minuend, Offset subtrahend)
Parameters
Type | Name | Description |
---|---|---|
Offset | minuend | The left hand side of the operator. |
Offset | subtrahend | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Offset | A new Offset representing the difference of the given values. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
ToString()
Returns a String that represents this instance.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | A String that represents this instance. |
Overrides
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
ToString(String, IFormatProvider)
Formats the value of the current instance using the specified format.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public string ToString(string patternText, IFormatProvider formatProvider)
Parameters
Type | Name | Description |
---|---|---|
String | patternText | The String specifying the pattern to use. -or- null to use the default pattern defined for the type of the IFormattable implementation. |
IFormatProvider | formatProvider | The IFormatProvider to use to format the value. -or- null to obtain the numeric format information from the current locale setting of the operating system. |
Returns
Type | Description |
---|---|
String | A String containing the value of the current instance in the specified format. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
ToTimeSpan()
Converts this offset to a .NET standard TimeSpan value.
Since 1.0.x
Availability net35-Client, PCL
Declaration
public TimeSpan ToTimeSpan()
Returns
Type | Description |
---|---|
TimeSpan | An equivalent TimeSpan to this value. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Operators
Addition(Offset, Offset)
Implements the operator + (addition).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset operator +(Offset left, Offset right)
Parameters
Type | Name | Description |
---|---|---|
Offset | left | The left hand side of the operator. |
Offset | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Offset | A new Offset representing the sum of the given values. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
Equality(Offset, Offset)
Implements the operator == (equality).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator ==(Offset left, Offset right)
Parameters
Type | Name | Description |
---|---|---|
Offset | left | The left hand side of the operator. |
Offset | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if values are equal to each other, otherwise false . |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
GreaterThan(Offset, Offset)
Implements the operator > (greater than).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator>(Offset left, Offset right)
Parameters
Type | Name | Description |
---|---|---|
Offset | left | The left hand side of the operator. |
Offset | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if the left value is greater than the right value, otherwise false . |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
GreaterThanOrEqual(Offset, Offset)
Implements the operator >= (greater than or equal).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator >=(Offset left, Offset right)
Parameters
Type | Name | Description |
---|---|---|
Offset | left | The left hand side of the operator. |
Offset | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if the left value is greater than or equal to the right value, otherwise false . |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Inequality(Offset, Offset)
Implements the operator != (inequality).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator !=(Offset left, Offset right)
Parameters
Type | Name | Description |
---|---|---|
Offset | left | The left hand side of the operator. |
Offset | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if values are not equal to each other, otherwise false . |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
LessThan(Offset, Offset)
Implements the operator < (less than).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator <(Offset left, Offset right)
Parameters
Type | Name | Description |
---|---|---|
Offset | left | The left hand side of the operator. |
Offset | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if the left value is less than the right value, otherwise false . |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
LessThanOrEqual(Offset, Offset)
Implements the operator <= (less than or equal).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static bool operator <=(Offset left, Offset right)
Parameters
Type | Name | Description |
---|---|---|
Offset | left | The left hand side of the operator. |
Offset | right | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Boolean | true if the left value is less than or equal to the right value, otherwise false . |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Subtraction(Offset, Offset)
Implements the operator - (subtraction).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset operator -(Offset minuend, Offset subtrahend)
Parameters
Type | Name | Description |
---|---|---|
Offset | minuend | The left hand side of the operator. |
Offset | subtrahend | The right hand side of the operator. |
Returns
Type | Description |
---|---|
Offset | A new Offset representing the difference of the given values. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
ArgumentOutOfRangeException | The result of the operation is outside the range of Offset. |
UnaryNegation(Offset)
Implements the unary operator - (negation).
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset operator -(Offset offset)
Parameters
Type | Name | Description |
---|---|---|
Offset | offset | The offset to negate. |
Returns
Type | Description |
---|---|
Offset | A new Offset instance with a negated value. |
Remarks
Offsets are always strictly less than 24 hours (as either a positive or negative offset).
UnaryPlus(Offset)
Implements the unary operator + .
Since 1.0.x
Availability net35-Client, PCL
Declaration
public static Offset operator +(Offset offset)
Parameters
Type | Name | Description |
---|---|---|
Offset | offset | The operand. |
Returns
Type | Description |
---|---|
Offset | The same Offset instance |
Remarks
There is no method form of this operator; the Plus(Offset) method is an instance
method for addition, and is more useful than a method form of this would be.
Explicit Interface Implementations
IComparable.CompareTo(Object)
Implementation of CompareTo(Object) to compare two offsets.
Since 1.0.x
Availability net35-Client, PCL
Declaration
int IComparable.CompareTo(object obj)
Parameters
Type | Name | Description |
---|---|---|
Object | obj | The object to compare this value with. |
Returns
Type | Description |
---|---|
Int32 | The result of comparing this instant with another one; see CompareTo(Offset) for general details.
If obj is null, this method returns a value greater than 0.
|
Remarks
This uses explicit interface implementation to avoid it being called accidentally. The generic implementation should usually be preferred.
Exceptions
Type | Condition |
---|---|
ArgumentException | obj is non-null but does not refer to an instance of Offset. |