Table of Contents

Class Time

Namespace
FinanceSharp
Assembly
FinanceSharp.dll

Time helper class collection for working with trading dates

public static class Time
Inheritance
Time
Inherited Members

Fields

BeginningOfTime

Provides a value far enough in the past that can be used as a lower bound on dates

public static readonly DateTime BeginningOfTime

Field Value

DateTime

DateTime.FromOADate(0)

EndOfTime

Provides a value far enough in the future the current computer hardware will have decayed :)

public static readonly DateTime EndOfTime

Field Value

DateTime

new DateTime(2050, 12, 31)

EndOfTimeTimeSpan

Provides a time span based on EndOfTime

public static TimeSpan EndOfTimeTimeSpan

Field Value

TimeSpan

EpochStart

public static readonly DateTime EpochStart

Field Value

DateTime

MaxTimeSpan

Provides a value large enough that we won't hit the limit, while small enough we can still do math against it without checking everywhere for MaxValue

public static readonly TimeSpan MaxTimeSpan

Field Value

TimeSpan

OneDay

One Day TimeSpan Period Constant

public static readonly TimeSpan OneDay

Field Value

TimeSpan

OneHour

One Hour TimeSpan Period Constant

public static readonly TimeSpan OneHour

Field Value

TimeSpan

OneMillisecond

One Millisecond TimeSpan Period Constant

public static readonly TimeSpan OneMillisecond

Field Value

TimeSpan

OneMinute

One Minute TimeSpan Period Constant

public static readonly TimeSpan OneMinute

Field Value

TimeSpan

OneSecond

One Second TimeSpan Period Constant

public static readonly TimeSpan OneSecond

Field Value

TimeSpan

OneYear

One Year TimeSpan Period Constant

public static readonly TimeSpan OneYear

Field Value

TimeSpan

Remarks

365 days

Properties

LocalNow

Provides local time now in milliseconds-epoch time.

public static long LocalNow { get; }

Property Value

long

Now

Provides UTC time now in milliseconds-epoch time.

public static long Now { get; }

Property Value

long

Methods

Abs(TimeSpan)

Gets the absolute value of the specified time span

public static TimeSpan Abs(this TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

Time span whose absolute value we seek

Returns

TimeSpan

The absolute value of the specified time span

DateTimeToUnixTimeStamp(DateTime)

Convert a Datetime to Unix Timestamp

public static double DateTimeToUnixTimeStamp(DateTime time)

Parameters

time DateTime

C# datetime object

Returns

double

Double unix timestamp

Max(DateTime, DateTime)

Returns the larger of two date times

public static DateTime Max(DateTime one, DateTime two)

Parameters

one DateTime
two DateTime

Returns

DateTime

Max(TimeSpan, TimeSpan)

Returns the timespan with the larger value

public static TimeSpan Max(TimeSpan one, TimeSpan two)

Parameters

one TimeSpan
two TimeSpan

Returns

TimeSpan

Min(DateTime, DateTime)

Returns the smaller of two date times

public static DateTime Min(DateTime one, DateTime two)

Parameters

one DateTime
two DateTime

Returns

DateTime

Min(TimeSpan, TimeSpan)

Returns the timespan with the smaller value

public static TimeSpan Min(TimeSpan one, TimeSpan two)

Parameters

one TimeSpan
two TimeSpan

Returns

TimeSpan

Multiply(TimeSpan, double)

Multiplies the specified interval by the multiplier

public static TimeSpan Multiply(this TimeSpan interval, double multiplier)

Parameters

interval TimeSpan

The interval to be multiplied, such as TimeSpan.FromSeconds(1)

multiplier double

The number of times to multiply the interval

Returns

TimeSpan

The multiplied interval, such as 1s*5 = 5s

NormalizeInstantWithinRange(DateTime, DateTime, TimeSpan)

Normalizes the current time within the specified period time = start => 0 time = start + period => 1

public static double NormalizeInstantWithinRange(DateTime start, DateTime current, TimeSpan period)

Parameters

start DateTime

The start time of the range

current DateTime

The current time we seek to normalize

period TimeSpan

The time span of the range

Returns

double

The normalized time

NormalizeTimeStep(TimeSpan, TimeSpan)

Normalizes the step size as a percentage of the period.

public static double NormalizeTimeStep(TimeSpan period, TimeSpan stepSize)

Parameters

period TimeSpan

The period to normalize against

stepSize TimeSpan

The step size to be normaized

Returns

double

The normalized step size as a percentage of the period

TimeStamp()

Get the current time as a unix timestamp

public static double TimeStamp()

Returns

double

Double value of the unix as UTC timestamp

ToDateTime(long)

Converts milliseconds-epoch time to DateTime represented by long.

public static DateTime ToDateTime(this long epochMilliseconds)

Parameters

epochMilliseconds long

Returns

DateTime

ToEpochTime(DateTime)

Converts DateTime to milliseconds-epoch time represented by long.

public static long ToEpochTime(this DateTime ts)

Parameters

ts DateTime

Returns

long

ToEpochTime(DateTimeOffset)

Converts DateTime to milliseconds-epoch time represented by long.

public static long ToEpochTime(this DateTimeOffset ts)

Parameters

ts DateTimeOffset

Returns

long

ToEpochTime(TimeSpan)

Converts TimeSpan to milliseconds-epoch time represented by long.

public static long ToEpochTime(this TimeSpan ts)

Parameters

ts TimeSpan

Returns

long

UnixMillisecondTimeStampToDateTime(double)

Create a C# DateTime from a UnixTimestamp

public static DateTime UnixMillisecondTimeStampToDateTime(double unixTimeStamp)

Parameters

unixTimeStamp double

Double unix timestamp (Time since Midnight Jan 1 1970) in milliseconds

Returns

DateTime

C# date timeobject

UnixTimeStampToDateTime(double)

Create a C# DateTime from a UnixTimestamp

public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)

Parameters

unixTimeStamp double

Double unix timestamp (Time since Midnight Jan 1 1970)

Returns

DateTime

C# date timeobject