Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

struct NodaTime.​Offset

Assembly: NodaTime

Implemented Interfaces

An offset from UTC in seconds. 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).

Remarks

<para> Offsets are always in the range of [-18, +18] hours. (Note that the ends are inclusive, so an offset of 18 hours can be represented, but an offset of 18 hours and one second cannot.) This allows all offsets within TZDB to be represented. The BCL <see cref="T:System.DateTimeOffset" /> type only allows offsets up to 14 hours, which means some historical data within TZDB could not be represented. </para> <para>Offsets are represented with a granularity of one second. This allows all offsets within TZDB to be represented. It is possible that it could present issues to some other time zone data sources, but only in very rare historical cases (or fictional ones).</para> <para>Equality and ordering are defined in the natural way by comparing the underlying number of seconds. For example, this means that offsets for America are ordered before offsets in Europe.</para> <para>The default value of this type is <see cref="F:NodaTime.Offset.Zero" />.</para>

Fields and Constants

public static readonly Offset
Zero
An offset of zero seconds - effectively the permanent offset for UTC.
public static readonly Offset
MinValue
The minimum permitted offset; 18 hours before UTC.
public static readonly Offset
MaxValue
The maximum permitted offset; 18 hours after UTC.

Properties

public static Offset
AdditiveIdentity
Gets the additive identity.
public int
Seconds
Gets the number of seconds represented by this offset, which may be negative.
public int
Milliseconds
Gets the number of milliseconds represented by this offset, which may be negative.
Remarks Offsets are only accurate to second precision; the number of seconds is simply multiplied by 1,000 to give the number of milliseconds.
public long
Ticks
Gets the number of ticks represented by this offset, which may be negative.
Remarks Offsets are only accurate to second precision; the number of seconds is simply multiplied by 10,000,000 to give the number of ticks.
public long
Nanoseconds
Gets the number of nanoseconds represented by this offset, which may be negative.
Remarks Offsets are only accurate to second precision; the number of seconds is simply multiplied by 1,000,000,000 to give the number of nanoseconds.

Methods

public static Offset
Max​(Offset x, Offset y)
Returns the greater offset of the given two, i.e. the one which will give a later local time when added to an instant.
Returns The greater offset of <paramref name="x" /> and <paramref name="y" /> .
x The first offset
y The second offset
public static Offset
Min​(Offset x, Offset y)
Returns the lower offset of the given two, i.e. the one which will give an earlier local time when added to an instant.
Returns The lower offset of <paramref name="x" /> and <paramref name="y" /> .
x The first offset
y The second offset
public static Offset
Negate​(Offset offset)
Returns the negation of the specified offset. This is the method form of the unary minus operator.
Returns The negation of the specified offset.
offset The offset to negate.
public static Offset
Add​(Offset left, Offset right)
Adds one Offset to another. Friendly alternative to <c>operator+()</c> .
Returns A new <see cref="T:NodaTime.Offset" /> representing the sum of the given values.
left The left hand side of the operator.
right The right hand side of the operator.
public Offset
Plus​(Offset other)
Returns the result of adding another Offset to this one, for a fluent alternative to <c>operator+()</c> .
Returns The result of adding the other offset to this one.
other The offset to add
public static Offset
Subtract​(Offset minuend, Offset subtrahend)
Subtracts one Offset from another. Friendly alternative to <c>operator-()</c> .
Returns A new <see cref="T:NodaTime.Offset" /> representing the difference of the given values.
minuend The left hand side of the operator.
subtrahend The right hand side of the operator.
public Offset
Minus​(Offset other)
Returns the result of subtracting another Offset from this one, for a fluent alternative to <c>operator-()</c> .
Returns The result of subtracting the other offset from this one.
other The offset to subtract
public int
CompareTo​(Offset other)
Compares the current object with another object of the same type. See the type documentation for a description of ordering semantics.
Returns A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings: <list type="table"> <listheader> <term>Value</term> <description>Meaning</description> </listheader> <item> <term>&lt; 0</term> <description>This object is less than the <paramref name="other" /> parameter.</description> </item> <item> <term>0</term> <description>This object is equal to <paramref name="other" />.</description> </item> <item> <term>&gt; 0</term> <description>This object is greater than <paramref name="other" />.</description> </item> </list>
other An object to compare with this object.
public bool
Equals​(Offset other)
Indicates whether the current object is equal to another object of the same type. See the type documentation for a description of equality semantics.
Returns true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
other An object to compare with this object.
public bool
Equals​(object obj)
Determines whether the specified <see cref="T:System.Object" /> is equal to this instance. See the type documentation for a description of equality semantics.
Returns <c>true</c> if the specified <see cref="T:System.Object" /> is equal to this instance; otherwise, <c>false</c> .
obj The <see cref="T:System.Object" /> to compare with this instance.
public int
GetHashCode​()
Returns a hash code for this instance. See the type documentation for a description of equality semantics.
Returns A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
public string
ToString​()
Returns a <see cref="T:System.String" /> that represents this instance.
Returns The value of the current instance in the default format pattern ("g"), using the current thread's culture to obtain a format provider.
public string
ToString​(string patternText, System.​IFormatProvider formatProvider)
Formats the value of the current instance using the specified pattern.
Returns A <see cref="T:System.String" /> containing the value of the current instance in the specified format.
patternText The <see cref="T:System.String" /> specifying the pattern to use, or null to use the default format pattern ("g").
formatProvider The <see cref="T:System.IFormatProvider" /> to use when formatting the value, or null to use the current thread's culture to obtain a format provider.
public static Offset
FromSeconds​(int seconds)
Returns an offset for the given seconds value, which may be negative.
Returns An offset representing the given number of seconds.
seconds The int seconds value.
public static Offset
FromMilliseconds​(int milliseconds)
Returns an offset for the given milliseconds value, which may be negative.
Returns An offset representing the given number of milliseconds, to the (truncated) second.
milliseconds The int milliseconds value.
Remarks Offsets are only accurate to second precision; the given number of milliseconds is simply divided by 1,000 to give the number of seconds - any remainder is truncated.
public static Offset
FromTicks​(long ticks)
Returns an offset for the given number of ticks, which may be negative.
Returns An offset representing the given number of ticks, to the (truncated) second.
ticks The number of ticks specifying the length of the new offset.
Remarks Offsets are only accurate to second precision; the given number of ticks is simply divided by 10,000,000 to give the number of seconds - any remainder is truncated.
public static Offset
FromNanoseconds​(long nanoseconds)
Returns an offset for the given number of nanoseconds, which may be negative.
Returns An offset representing the given number of nanoseconds, to the (truncated) second.
nanoseconds The number of nanoseconds specifying the length of the new offset.
Remarks Offsets are only accurate to second precision; the given number of nanoseconds is simply divided by 1,000,000,000 to give the number of seconds - any remainder is truncated towards zero.
public static Offset
FromHours​(int hours)
Returns an offset for the specified number of hours, which may be negative.
Returns An offset representing the given value.
hours The number of hours to represent in the new offset.
public static Offset
FromHoursAndMinutes​(int hours, int minutes)
Returns an offset for the specified number of hours and minutes.
Returns An offset representing the given value.
hours The number of hours to represent in the new offset.
minutes The number of minutes to represent in the new offset.
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 <c>Offset.FromHoursAndMinutes(-3, -10)</c> .
ToTimeSpan​()
Converts this offset to a .NET standard <see cref="T:System.TimeSpan" /> value.
Returns An equivalent <see cref="T:System.TimeSpan" /> to this value.
public static Offset
FromTimeSpan​(System.​TimeSpan timeSpan)
Converts the given <see cref="T:System.TimeSpan" /> to an offset, with fractional seconds truncated.
Returns An offset for the same time as the given time span.
timeSpan The timespan to convert
AddSchema​(System.​Xml.​Schema.​XmlSchemaSet xmlSchemaSet)
Adds the XML schema type describing the structure of the <see cref="T:NodaTime.Offset" /> XML serialization to the given <paramref name="xmlSchemaSet" /> .
Returns The qualified name of the schema type that was added to the <paramref name="xmlSchemaSet" /> .
xmlSchemaSet The XML schema set provided by <see cref="T:System.Xml.Serialization.XmlSchemaExporter" /> .
protected void
Finalize​()
Inherited from object
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object