2025-12-16 21:16:50 -08:00
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
|
|
namespace QuanTAlib;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A lightweight struct representing a time-value pair.
|
|
|
|
|
/// Pure data type: 16 bytes (long + double).
|
|
|
|
|
/// </summary>
|
|
|
|
|
[SkipLocalsInit]
|
2025-12-17 07:27:45 -08:00
|
|
|
public readonly record struct TValue(long Time, double Value)
|
2025-12-16 21:16:50 -08:00
|
|
|
{
|
|
|
|
|
public DateTime AsDateTime => new(Time, DateTimeKind.Utc);
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2025-12-17 07:27:45 -08:00
|
|
|
public TValue(DateTime time, double value)
|
|
|
|
|
: this(time.Kind == DateTimeKind.Utc ? time.Ticks : time.ToUniversalTime().Ticks, value)
|
2025-12-16 21:16:50 -08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public static implicit operator double(TValue tv) => tv.Value;
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public static implicit operator DateTime(TValue tv) => new(tv.Time, DateTimeKind.Utc);
|
|
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
|
public override string ToString() => $"[{AsDateTime:yyyy-MM-dd HH:mm:ss}, {Value:F2}]";
|
|
|
|
|
}
|