Struct LrcTimestamp
Non-negative monotonic time offset within an LRC document, stored as 100ns ticks
(matching Ticks). LRC syntax has no negative form, so every
factory enforces ≥ 0; LrcDocumentExtensions.GetEffectiveTime
returns TimeSpan (signed) for offset application.
public readonly struct LrcTimestamp : IEquatable<LrcTimestamp>, IComparable<LrcTimestamp>, ISpanFormattable, IFormattable, IUtf8SpanFormattable, ISpanParsable<LrcTimestamp>, IParsable<LrcTimestamp>
- Implements
- Inherited Members
Examples
var ts = LrcTimestamp.FromMilliseconds(83_450);
Console.WriteLine(ts); // "01:23.45"
Console.WriteLine(ts.ToString("F", null)); // "01:23.450"
Console.WriteLine(ts.ToString("B", null)); // "[01:23.45]"
LrcTimestamp parsed = LrcTimestamp.Parse("01:23.45");
LrcTimestamp shifted = parsed + TimeSpan.FromSeconds(1);
Remarks
Implements IParsable<TSelf>, ISpanParsable<TSelf>,
IFormattable, ISpanFormattable, and
IUtf8SpanFormattable. Parse accepts the canonical mm:ss.xx as well as
tolerant variants (3-digit fraction, colon fraction, hours notation, comma decimal).
Format codes: "G" (default, mm:ss.xx), "F" (mm:ss.xxx),
"S" (mm:ss), "B" ([mm:ss.xx]), "W" (<mm:ss.xx>).
Properties
Ticks
100ns units. Always >= 0.
public long Ticks { get; }
Property Value
TotalMilliseconds
Whole milliseconds (truncated).
public long TotalMilliseconds { get; }
Property Value
TotalSeconds
Total seconds as floating-point.
public double TotalSeconds { get; }
Property Value
Zero
The zero timestamp.
public static LrcTimestamp Zero { get; }
Property Value
Methods
CompareTo(LrcTimestamp)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(LrcTimestamp other)
Parameters
otherLrcTimestampAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
Equals(LrcTimestamp)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(LrcTimestamp other)
Parameters
otherLrcTimestampAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
FromMilliseconds(long)
Construct from milliseconds. Throws on negative.
public static LrcTimestamp FromMilliseconds(long ms)
Parameters
mslong
Returns
FromTicks(long)
Construct from raw 100ns ticks. Throws on negative.
public static LrcTimestamp FromTicks(long ticks)
Parameters
tickslong
Returns
FromTimeSpan(TimeSpan)
Construct from a TimeSpan. Throws if the input is negative.
public static LrcTimestamp FromTimeSpan(TimeSpan ts)
Parameters
tsTimeSpan
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Parse(ReadOnlySpan<char>, IFormatProvider?)
Parse "mm:ss.xx", "mm:ss.xxx", "mm:ss", or "mm:ss:xx".
Minutes unbounded; hours notation NOT accepted; negative input rejected. Always uses
InvariantCulture.
public static LrcTimestamp Parse(ReadOnlySpan<char> s, IFormatProvider? provider = null)
Parameters
sReadOnlySpan<char>providerIFormatProvider
Returns
Parse(string, IFormatProvider?)
Parse from a string. Throws on null.
public static LrcTimestamp Parse(string s, IFormatProvider? provider = null)
Parameters
sstringproviderIFormatProvider
Returns
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
ToString(string?, IFormatProvider?)
Format using a code: "G" (default, mm:ss.xx), "F" (mm:ss.xxx),
"S" (mm:ss), "B" ([mm:ss.xx]), "W" (<mm:ss.xx>).
public string ToString(string? format, IFormatProvider? formatProvider = null)
Parameters
formatstringformatProviderIFormatProvider
Returns
ToTimeSpan()
Convert to TimeSpan; always non-negative.
public TimeSpan ToTimeSpan()
Returns
TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance as UTF-8 into the provided span of bytes.
public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
utf8DestinationSpan<byte>The span in which to write this instance's value formatted as a span of bytes.
bytesWrittenintWhen this method returns, contains the number of bytes that were written in
utf8Destination.formatReadOnlySpan<char>A span containing the characters that represent a standard or custom format string that defines the acceptable format for
utf8Destination.providerIFormatProviderAn optional object that supplies culture-specific formatting information for
utf8Destination.
Returns
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance into the provided span of characters.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
destinationSpan<char>The span in which to write this instance's value formatted as a span of characters.
charsWrittenintWhen this method returns, contains the number of characters that were written in
destination.formatReadOnlySpan<char>A span containing the characters that represent a standard or custom format string that defines the acceptable format for
destination.providerIFormatProviderAn optional object that supplies culture-specific formatting information for
destination.
Returns
TryParse(ReadOnlySpan<char>, IFormatProvider?, out LrcTimestamp)
Try-parse a span (canonical core).
public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out LrcTimestamp result)
Parameters
sReadOnlySpan<char>providerIFormatProviderresultLrcTimestamp
Returns
TryParse(string?, IFormatProvider?, out LrcTimestamp)
Try-parse a string. Null returns false.
public static bool TryParse(string? s, IFormatProvider? provider, out LrcTimestamp result)
Parameters
sstringproviderIFormatProviderresultLrcTimestamp
Returns
Operators
operator +(LrcTimestamp, TimeSpan)
Add a TimeSpan. Throws OverflowException if the result would be negative.
[SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Arithmetic on LrcTimestamp is intentionally operator-only; named helpers would pollute the API surface for a value type used in hot paths.")]
public static LrcTimestamp operator +(LrcTimestamp left, TimeSpan right)
Parameters
leftLrcTimestamprightTimeSpan
Returns
operator ==(LrcTimestamp, LrcTimestamp)
Equality.
public static bool operator ==(LrcTimestamp left, LrcTimestamp right)
Parameters
leftLrcTimestamprightLrcTimestamp
Returns
operator >(LrcTimestamp, LrcTimestamp)
Greater than.
public static bool operator >(LrcTimestamp left, LrcTimestamp right)
Parameters
leftLrcTimestamprightLrcTimestamp
Returns
operator >=(LrcTimestamp, LrcTimestamp)
Greater than or equal.
public static bool operator >=(LrcTimestamp left, LrcTimestamp right)
Parameters
leftLrcTimestamprightLrcTimestamp
Returns
implicit operator TimeSpan(LrcTimestamp)
Implicit lift to TimeSpan.
[SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Implicit lift to TimeSpan is the canonical interop; ToTimeSpan() serves as the named alternate.")]
public static implicit operator TimeSpan(LrcTimestamp t)
Parameters
Returns
operator !=(LrcTimestamp, LrcTimestamp)
Inequality.
public static bool operator !=(LrcTimestamp left, LrcTimestamp right)
Parameters
leftLrcTimestamprightLrcTimestamp
Returns
operator <(LrcTimestamp, LrcTimestamp)
Less than.
public static bool operator <(LrcTimestamp left, LrcTimestamp right)
Parameters
leftLrcTimestamprightLrcTimestamp
Returns
operator <=(LrcTimestamp, LrcTimestamp)
Less than or equal.
public static bool operator <=(LrcTimestamp left, LrcTimestamp right)
Parameters
leftLrcTimestamprightLrcTimestamp
Returns
operator -(LrcTimestamp, LrcTimestamp)
Subtract two timestamps producing a (signed) TimeSpan.
[SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Arithmetic on LrcTimestamp is intentionally operator-only; named helpers would pollute the API surface for a value type used in hot paths.")]
public static TimeSpan operator -(LrcTimestamp left, LrcTimestamp right)
Parameters
leftLrcTimestamprightLrcTimestamp
Returns
operator -(LrcTimestamp, TimeSpan)
Subtract a TimeSpan. Throws OverflowException if the result would be negative.
[SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Arithmetic on LrcTimestamp is intentionally operator-only; named helpers would pollute the API surface for a value type used in hot paths.")]
public static LrcTimestamp operator -(LrcTimestamp left, TimeSpan right)
Parameters
leftLrcTimestamprightTimeSpan