Table of Contents

Struct LrcTimestamp

Namespace
ModernLrc.Model
Assembly
ModernLrc.dll

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

long

TotalMilliseconds

Whole milliseconds (truncated).

public long TotalMilliseconds { get; }

Property Value

long

TotalSeconds

Total seconds as floating-point.

public double TotalSeconds { get; }

Property Value

double

Zero

The zero timestamp.

public static LrcTimestamp Zero { get; }

Property Value

LrcTimestamp

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

other LrcTimestamp

An 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 other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in 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

other LrcTimestamp

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

ms long

Returns

LrcTimestamp

FromTicks(long)

Construct from raw 100ns ticks. Throws on negative.

public static LrcTimestamp FromTicks(long ticks)

Parameters

ticks long

Returns

LrcTimestamp

FromTimeSpan(TimeSpan)

Construct from a TimeSpan. Throws if the input is negative.

public static LrcTimestamp FromTimeSpan(TimeSpan ts)

Parameters

ts TimeSpan

Returns

LrcTimestamp

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

s ReadOnlySpan<char>
provider IFormatProvider

Returns

LrcTimestamp

Parse(string, IFormatProvider?)

Parse from a string. Throws on null.

public static LrcTimestamp Parse(string s, IFormatProvider? provider = null)

Parameters

s string
provider IFormatProvider

Returns

LrcTimestamp

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

format string
formatProvider IFormatProvider

Returns

string

ToTimeSpan()

Convert to TimeSpan; always non-negative.

public TimeSpan ToTimeSpan()

Returns

TimeSpan

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

utf8Destination Span<byte>

The span in which to write this instance's value formatted as a span of bytes.

bytesWritten int

When this method returns, contains the number of bytes that were written in utf8Destination.

format ReadOnlySpan<char>

A span containing the characters that represent a standard or custom format string that defines the acceptable format for utf8Destination.

provider IFormatProvider

An optional object that supplies culture-specific formatting information for utf8Destination.

Returns

bool

true if the formatting was successful; otherwise, false.

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

destination Span<char>

The span in which to write this instance's value formatted as a span of characters.

charsWritten int

When this method returns, contains the number of characters that were written in destination.

format ReadOnlySpan<char>

A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination.

provider IFormatProvider

An optional object that supplies culture-specific formatting information for destination.

Returns

bool

true if the formatting was successful; otherwise, false.

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

s ReadOnlySpan<char>
provider IFormatProvider
result LrcTimestamp

Returns

bool

TryParse(string?, IFormatProvider?, out LrcTimestamp)

Try-parse a string. Null returns false.

public static bool TryParse(string? s, IFormatProvider? provider, out LrcTimestamp result)

Parameters

s string
provider IFormatProvider
result LrcTimestamp

Returns

bool

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

left LrcTimestamp
right TimeSpan

Returns

LrcTimestamp

operator ==(LrcTimestamp, LrcTimestamp)

Equality.

public static bool operator ==(LrcTimestamp left, LrcTimestamp right)

Parameters

left LrcTimestamp
right LrcTimestamp

Returns

bool

operator >(LrcTimestamp, LrcTimestamp)

Greater than.

public static bool operator >(LrcTimestamp left, LrcTimestamp right)

Parameters

left LrcTimestamp
right LrcTimestamp

Returns

bool

operator >=(LrcTimestamp, LrcTimestamp)

Greater than or equal.

public static bool operator >=(LrcTimestamp left, LrcTimestamp right)

Parameters

left LrcTimestamp
right LrcTimestamp

Returns

bool

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

t LrcTimestamp

Returns

TimeSpan

operator !=(LrcTimestamp, LrcTimestamp)

Inequality.

public static bool operator !=(LrcTimestamp left, LrcTimestamp right)

Parameters

left LrcTimestamp
right LrcTimestamp

Returns

bool

operator <(LrcTimestamp, LrcTimestamp)

Less than.

public static bool operator <(LrcTimestamp left, LrcTimestamp right)

Parameters

left LrcTimestamp
right LrcTimestamp

Returns

bool

operator <=(LrcTimestamp, LrcTimestamp)

Less than or equal.

public static bool operator <=(LrcTimestamp left, LrcTimestamp right)

Parameters

left LrcTimestamp
right LrcTimestamp

Returns

bool

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

left LrcTimestamp
right LrcTimestamp

Returns

TimeSpan

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

left LrcTimestamp
right TimeSpan

Returns

LrcTimestamp