Struct TimeFormat
Defines a token-based formatting pattern used to render TimeUnit values as structured, human-readable strings such as clock displays, countdown timers, or custom duration labels.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Units
Assembly: ScyllaCore.dll
Syntax
public readonly struct TimeFormat : IEquatable<TimeFormat>
Remarks
A TimeFormat consists of a pattern string containing any combination of recognized token characters and literal separator characters. Token characters are expanded by Formatted(TimeFormat?) into the corresponding integer or fractional time component; all other characters are passed through verbatim.
The supported token characters are:
Y-- years (Julian, 365.25 days each)W-- weeksD-- daysH-- hoursm-- minutess-- whole secondsf-- fractional seconds (run length = number of digits)
The number of consecutive repetitions of a token character specifies the minimum output
field width; shorter values are left-padded with zeros. For example, "HH" always
emits at least two digits for hours.
Patterns are deterministic: no locale, calendar, or system clock state is consulted during formatting. The only predefined instance is StandardClock.
Constructors
TimeFormat(string)
Initializes a new TimeFormat with the specified pattern string.
Declaration
public TimeFormat(string pattern)
Parameters
| Type | Name | Description |
|---|---|---|
| string | pattern | The format pattern that controls how a TimeUnit is rendered by
Formatted(TimeFormat?). The string may contain any mix of
recognized token characters (see IsTokenChar(char)) and literal separator
characters such as |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when |
Fields
StandardClock
The standard 24-hour clock format "HH:mm:ss", which renders hours (zero-padded
to two digits), minutes, and whole seconds separated by colons.
Declaration
public static readonly TimeFormat StandardClock
Field Value
| Type | Description |
|---|---|
| TimeFormat |
Remarks
This is the fallback format used by Formatted(TimeFormat?) when
null or an empty pattern is supplied. Example output: "01:30:05".
Properties
Pattern
Gets the pattern string that drives formatting when this TimeFormat is passed to Formatted(TimeFormat?).
Declaration
public string Pattern { get; }
Property Value
| Type | Description |
|---|---|
| string | A non-null, non-empty string whose characters are interpreted as either recognized token
characters (see IsTokenChar(char)) or literal pass-through characters. This
property is always set at construction time and is immutable thereafter, since
TimeFormat is a |
Methods
Equals(TimeFormat)
Determines whether the current TimeFormat is equal to another TimeFormat.
Declaration
public bool Equals(TimeFormat other)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeFormat | other | The TimeFormat to compare to the current instance. |
Returns
| Type | Description |
|---|---|
| bool | True if the patterns of both TimeFormat instances are equal; otherwise, false. |
Equals(object)
Determines whether the current TimeFormat instance is equal to a specified object.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with the current instance. |
Returns
| Type | Description |
|---|---|
| bool | True if the specified object is a TimeFormat and its pattern is equal to the pattern of the current instance; otherwise, false. |
Overrides
GetHashCode()
Returns a hash code for the current TimeFormat instance.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A hash code representing the current TimeFormat. |
Overrides
IsTokenChar(char)
Determines whether the specified character is a recognized format token that Formatted(TimeFormat?) will expand into a time component value.
Declaration
public static bool IsTokenChar(char c)
Parameters
| Type | Name | Description |
|---|---|---|
| char | c | The character to test. The full set of recognized tokens is:
All other characters are treated as literal separators. |
Returns
| Type | Description |
|---|---|
| bool |
|
Operators
operator ==(TimeFormat, TimeFormat)
Determines whether two TimeFormat instances are equal.
Declaration
public static bool operator ==(TimeFormat left, TimeFormat right)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeFormat | left | The first TimeFormat to compare. |
| TimeFormat | right | The second TimeFormat to compare. |
Returns
| Type | Description |
|---|---|
| bool | True if the patterns of both TimeFormat instances are equal; otherwise, false. |
operator !=(TimeFormat, TimeFormat)
Determines whether two TimeFormat instances are not equal.
Declaration
public static bool operator !=(TimeFormat left, TimeFormat right)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeFormat | left | The first TimeFormat to compare. |
| TimeFormat | right | The second TimeFormat to compare. |
Returns
| Type | Description |
|---|---|
| bool | True if the patterns of both TimeFormat instances are not equal; otherwise, false. |