Skip to content

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>

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:

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.

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.

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.

public bool Equals(PgTime other)

Parameters:

other — PgTime

Returns: bool

public override bool Equals(object obj)

Parameters:

obj — object

Returns: bool

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.

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.

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:

public override int GetHashCode()

Returns: 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.

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.

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.

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.

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.

Subtracts the interval’s time component, wrapping at midnight.

public PgTime Subtract(PgInterval interval)

Parameters:

interval — PgInterval

The interval.

Returns: PgTime

The resulting time.

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.

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.

Formats the time using PostgreSQL’s ISO JSON representation.

public string ToIsoString()

Returns: string

The ISO time.

Formats the time using PostgreSQL’s output routine.

public string ToPostgresString()

Returns: string

The time text.

Formats stored diagnostic values without requiring a backend.

public override string ToString()

Returns: string

The managed record diagnostic representation.

Converts to TimeOnly, rejecting 24:00:00 rather than wrapping to midnight.

public TimeOnly ToTimeOnly()

Returns: TimeOnly

The .NET time.

Exceptions:

Attaches the session timezone’s offset using PostgreSQL’s current-date rules.

public PgTimeTz ToTimeTz()

Returns: PgTimeTz

The local time and offset.

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.

Gets PostgreSQL’s 24:00:00 value.

public static PgTime EndOfDay { get; }

Value: PgTime

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

Gets the microseconds since midnight. The end-of-day value is distinct from midnight.

public long Microseconds { get; }

Value: long

Gets the microseconds within the current second, from zero through 999999.

public int MicrosecondsWithinSecond { get; }

Value: int

Gets the minute within the hour.

public int Minute { get; }

Value: int

Gets the whole second within the minute.

public int Second { get; }

Value: int

The microseconds in one 24-hour day.

public const long MicrosecondsPerDay = 86400000000

The microseconds in one second.

public const long MicrosecondsPerSecond = 1000000

Adds an interval, wrapping at midnight.

public static PgTime operator +(PgInterval interval, PgTime time)

Parameters:

interval — PgInterval

time — PgTime

Returns: PgTime

Adds an interval, wrapping at midnight.

public static PgTime operator +(PgTime time, PgInterval interval)

Parameters:

time — PgTime

interval — PgInterval

Returns: PgTime

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

Parameters:

left — PgTime

right — PgTime

Returns: bool

Tests whether the left time follows the right time.

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

Parameters:

left — PgTime

right — PgTime

Returns: bool

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

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

Parameters:

left — PgTime

right — PgTime

Returns: bool

Tests whether the left time precedes the right time.

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

Parameters:

left — PgTime

right — PgTime

Returns: bool

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

Subtracts an interval, wrapping at midnight.

public static PgTime operator -(PgTime time, PgInterval interval)

Parameters:

time — PgTime

interval — PgInterval

Returns: PgTime

Computes the signed wall-clock difference.

public static PgInterval operator -(PgTime left, PgTime right)

Parameters:

left — PgTime

right — PgTime

Returns: PgInterval