PgTime
Namespace: Ankus
Assembly: Ankus.Runtime.dll
Implements .NET’s parsing contract over PostgreSQL’s input function.
[JsonConverter(typeof(PgTimeConverter))]public readonly struct PgTime : IParsable<PgTime>, IComparable<PgTime>, IEquatable<PgTime>Implements: IParsable<PgTime>, IComparable<PgTime>, IEquatable<PgTime>
Constructors
Section titled “Constructors”PgTime(long)
Section titled “PgTime(long)”Creates a time from microseconds since midnight, between zero and 86,400,000,000 inclusive.
public PgTime(long microseconds)Parameters:
microseconds — long
The time of day in microseconds.
Exceptions:
- ArgumentOutOfRangeException: The offset is negative or later than 24:00:00.
Methods
Section titled “Methods”Add(PgInterval)
Section titled “Add(PgInterval)”Adds the interval’s time component, wrapping at midnight as PostgreSQL does.
public PgTime Add(PgInterval interval)Parameters:
interval — PgInterval
The interval.
Returns: PgTime
The resulting time.
CompareTo(PgTime)
Section titled “CompareTo(PgTime)”Compares wall-clock times, retaining 24:00 as later than midnight, without requiring an active backend.
public int CompareTo(PgTime other)Parameters:
other — PgTime
The time to compare.
Returns: int
A negative value, zero, or a positive value for earlier, equal, or later times.
Create(int, int, double)
Section titled “Create(int, int, double)”Constructs a time using PostgreSQL’s field validation and fractional-second rounding.
public static PgTime Create(int hour, int minute, double second)Parameters:
hour — int
The hour, including 24 only for the end-of-day value.
minute — int
The minute.
second — double
The seconds, including a fractional part.
Returns: PgTime
The time.
Equals(PgTime)
Section titled “Equals(PgTime)”public bool Equals(PgTime other)Parameters:
other — PgTime
Returns: bool
Equals(object)
Section titled “Equals(object)”public override bool Equals(object obj)Parameters:
obj — object
Returns: bool
Extract(PgDateTimePart)
Section titled “Extract(PgDateTimePart)”Extracts a numeric field exactly on PostgreSQL 14+; PostgreSQL 13 converts its floating-point result.
public PgNumeric? Extract(PgDateTimePart part)Parameters:
part — PgDateTimePart
The field to extract.
Returns: PgNumeric?
The numeric field.
FromMicrosecondsWrapping(long)
Section titled “FromMicrosecondsWrapping(long)”Creates a time by wrapping a signed microsecond count into one day using a nonnegative remainder.
public static PgTime FromMicrosecondsWrapping(long microseconds)Parameters:
microseconds — long
The raw signed microseconds; whole days, including 24:00, wrap to midnight.
Returns: PgTime
A time from midnight through one microsecond before midnight, without requiring a backend.
FromTimeOnly(TimeOnly)
Section titled “FromTimeOnly(TimeOnly)”Converts a .NET time, rejecting sub-microsecond ticks.
public static PgTime FromTimeOnly(TimeOnly value)Parameters:
value — TimeOnly
The .NET time.
Returns: PgTime
The PostgreSQL time.
Exceptions:
- ArgumentException: The value contains sub-microsecond ticks.
GetHashCode()
Section titled “GetHashCode()”public override int GetHashCode()Returns: int
GetLocalTime(int)
Section titled “GetLocalTime(int)”Gets SQL LOCALTIME at the requested precision in the session timezone.
public static PgTime GetLocalTime(int precision = 6)Parameters:
precision — int
Fractional-second digits, zero through six.
Returns: PgTime
The current transaction’s local time.
GetPart(PgDateTimePart)
Section titled “GetPart(PgDateTimePart)”Reads a floating-point field using PostgreSQL date_part semantics.
public double? GetPart(PgDateTimePart part)Parameters:
part — PgDateTimePart
The field.
Returns: double?
The field value.
GetTimeParts()
Section titled “GetTimeParts()”Reads exact wall-clock fields without requiring a backend, preserving 24:00 and microseconds.
public (int Hour, int Minute, int Second, int Microseconds) GetTimeParts()Returns: (int Hour, int Minute, int Second, int Microseconds)
The hour, minute, whole second, and microseconds within that second.
Parse(string)
Section titled “Parse(string)”Parses PostgreSQL time syntax on the active backend thread.
public static PgTime Parse(string text)Parameters:
text — string
The time text.
Returns: PgTime
The parsed time.
Round(int)
Section titled “Round(int)”Rounds fractional seconds using PostgreSQL’s time type modifier.
public PgTime Round(int precision)Parameters:
precision — int
Fractional-second digits, zero through six.
Returns: PgTime
The rounded time, possibly 24:00.
Subtract(PgInterval)
Section titled “Subtract(PgInterval)”Subtracts the interval’s time component, wrapping at midnight.
public PgTime Subtract(PgInterval interval)Parameters:
interval — PgInterval
The interval.
Returns: PgTime
The resulting time.
Subtract(PgTime)
Section titled “Subtract(PgTime)”Subtracts another wall-clock time without wrapping the difference.
public PgInterval Subtract(PgTime other)Parameters:
other — PgTime
The time to subtract.
Returns: PgInterval
The signed interval.
ToInterval()
Section titled “ToInterval()”Converts the time of day to an interval with no months or days, as PostgreSQL’s time::interval cast does.
public PgInterval ToInterval()Returns: PgInterval
The interval.
ToIsoString()
Section titled “ToIsoString()”Formats the time using PostgreSQL’s ISO JSON representation.
public string ToIsoString()Returns: string
The ISO time.
ToPostgresString()
Section titled “ToPostgresString()”Formats the time using PostgreSQL’s output routine.
public string ToPostgresString()Returns: string
The time text.
ToString()
Section titled “ToString()”Formats stored diagnostic values without requiring a backend.
public override string ToString()Returns: string
The managed record diagnostic representation.
ToTimeOnly()
Section titled “ToTimeOnly()”Converts to TimeOnly, rejecting 24:00:00 rather than wrapping to midnight.
public TimeOnly ToTimeOnly()Returns: TimeOnly
The .NET time.
Exceptions:
- InvalidOperationException: The value is 24:00:00.
ToTimeTz()
Section titled “ToTimeTz()”Attaches the session timezone’s offset using PostgreSQL’s current-date rules.
public PgTimeTz ToTimeTz()Returns: PgTimeTz
The local time and offset.
TryParse(string?, out PgTime)
Section titled “TryParse(string?, out PgTime)”Tries to parse PostgreSQL time syntax on the active backend thread.
public static bool TryParse(string? text, out PgTime value)Parameters:
text — string
The time text.
value — PgTime
The parsed time, or the default value on invalid input.
Returns: bool
Whether the input is valid. Backend-access and operational errors still throw.
Invalid input leaves no error pending: PostgreSQL 16 and later report it as a soft input error, and earlier majors roll back an internal subtransaction. Before PostgreSQL 16, transaction callbacks and parallel operations forbid that rollback; native errors there remain pending and throw PgException.
Properties
Section titled “Properties”EndOfDay
Section titled “EndOfDay”Gets PostgreSQL’s 24:00:00 value.
public static PgTime EndOfDay { get; }Value: PgTime
FractionalSecond
Section titled “FractionalSecond”Gets the seconds within the minute, including the microsecond fraction, as a floating-point value.
public double FractionalSecond { get; }Value: double
Gets the hour from zero through twenty-four; twenty-four occurs only for the end-of-day value.
public int Hour { get; }Value: int
Microseconds
Section titled “Microseconds”Gets the microseconds since midnight. The end-of-day value is distinct from midnight.
public long Microseconds { get; }Value: long
MicrosecondsWithinSecond
Section titled “MicrosecondsWithinSecond”Gets the microseconds within the current second, from zero through 999999.
public int MicrosecondsWithinSecond { get; }Value: int
Minute
Section titled “Minute”Gets the minute within the hour.
public int Minute { get; }Value: int
Second
Section titled “Second”Gets the whole second within the minute.
public int Second { get; }Value: int
Fields
Section titled “Fields”MicrosecondsPerDay
Section titled “MicrosecondsPerDay”The microseconds in one 24-hour day.
public const long MicrosecondsPerDay = 86400000000MicrosecondsPerSecond
Section titled “MicrosecondsPerSecond”The microseconds in one second.
public const long MicrosecondsPerSecond = 1000000Operators
Section titled “Operators”operator +(PgInterval, PgTime)
Section titled “operator +(PgInterval, PgTime)”Adds an interval, wrapping at midnight.
public static PgTime operator +(PgInterval interval, PgTime time)Parameters:
interval — PgInterval
time — PgTime
Returns: PgTime
operator +(PgTime, PgInterval)
Section titled “operator +(PgTime, PgInterval)”Adds an interval, wrapping at midnight.
public static PgTime operator +(PgTime time, PgInterval interval)Parameters:
time — PgTime
interval — PgInterval
Returns: PgTime
operator ==(PgTime, PgTime)
Section titled “operator ==(PgTime, PgTime)”public static bool operator ==(PgTime left, PgTime right)Parameters:
left — PgTime
right — PgTime
Returns: bool
operator >(PgTime, PgTime)
Section titled “operator >(PgTime, PgTime)”Tests whether the left time follows the right time.
public static bool operator >(PgTime left, PgTime right)Parameters:
left — PgTime
right — PgTime
Returns: bool
operator >=(PgTime, PgTime)
Section titled “operator >=(PgTime, PgTime)”Tests whether the left time follows or equals the right time.
public static bool operator >=(PgTime left, PgTime right)Parameters:
left — PgTime
right — PgTime
Returns: bool
operator !=(PgTime, PgTime)
Section titled “operator !=(PgTime, PgTime)”public static bool operator !=(PgTime left, PgTime right)Parameters:
left — PgTime
right — PgTime
Returns: bool
operator <(PgTime, PgTime)
Section titled “operator <(PgTime, PgTime)”Tests whether the left time precedes the right time.
public static bool operator <(PgTime left, PgTime right)Parameters:
left — PgTime
right — PgTime
Returns: bool
operator <=(PgTime, PgTime)
Section titled “operator <=(PgTime, PgTime)”Tests whether the left time precedes or equals the right time.
public static bool operator <=(PgTime left, PgTime right)Parameters:
left — PgTime
right — PgTime
Returns: bool
operator -(PgTime, PgInterval)
Section titled “operator -(PgTime, PgInterval)”Subtracts an interval, wrapping at midnight.
public static PgTime operator -(PgTime time, PgInterval interval)Parameters:
time — PgTime
interval — PgInterval
Returns: PgTime
operator -(PgTime, PgTime)
Section titled “operator -(PgTime, PgTime)”Computes the signed wall-clock difference.
public static PgInterval operator -(PgTime left, PgTime right)Parameters:
left — PgTime
right — PgTime
Returns: PgInterval