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
EpochStart
public static readonly DateTime EpochStart
Field Value
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
OneDay
One Day TimeSpan Period Constant
public static readonly TimeSpan OneDay
Field Value
OneHour
One Hour TimeSpan Period Constant
public static readonly TimeSpan OneHour
Field Value
OneMillisecond
One Millisecond TimeSpan Period Constant
public static readonly TimeSpan OneMillisecond
Field Value
OneMinute
One Minute TimeSpan Period Constant
public static readonly TimeSpan OneMinute
Field Value
OneSecond
One Second TimeSpan Period Constant
public static readonly TimeSpan OneSecond
Field Value
OneYear
One Year TimeSpan Period Constant
public static readonly TimeSpan OneYear
Field Value
Remarks
365 days
Properties
LocalNow
Provides local time now in milliseconds-epoch time.
public static long LocalNow { get; }
Property Value
Now
Provides UTC time now in milliseconds-epoch time.
public static long Now { get; }
Property Value
Methods
Abs(TimeSpan)
Gets the absolute value of the specified time span
public static TimeSpan Abs(this TimeSpan timeSpan)
Parameters
timeSpanTimeSpanTime 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
timeDateTimeC# 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
Returns
Max(TimeSpan, TimeSpan)
Returns the timespan with the larger value
public static TimeSpan Max(TimeSpan one, TimeSpan two)
Parameters
Returns
Min(DateTime, DateTime)
Returns the smaller of two date times
public static DateTime Min(DateTime one, DateTime two)
Parameters
Returns
Min(TimeSpan, TimeSpan)
Returns the timespan with the smaller value
public static TimeSpan Min(TimeSpan one, TimeSpan two)
Parameters
Returns
Multiply(TimeSpan, double)
Multiplies the specified interval by the multiplier
public static TimeSpan Multiply(this TimeSpan interval, double multiplier)
Parameters
intervalTimeSpanThe interval to be multiplied, such as TimeSpan.FromSeconds(1)
multiplierdoubleThe 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
startDateTimeThe start time of the range
currentDateTimeThe current time we seek to normalize
periodTimeSpanThe 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
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)
public static DateTime ToDateTime(this long epochMilliseconds)
Parameters
epochMillisecondslong
Returns
ToEpochTime(DateTime)
public static long ToEpochTime(this DateTime ts)
Parameters
tsDateTime
Returns
ToEpochTime(DateTimeOffset)
public static long ToEpochTime(this DateTimeOffset ts)
Parameters
Returns
ToEpochTime(TimeSpan)
public static long ToEpochTime(this TimeSpan ts)
Parameters
tsTimeSpan
Returns
UnixMillisecondTimeStampToDateTime(double)
Create a C# DateTime from a UnixTimestamp
public static DateTime UnixMillisecondTimeStampToDateTime(double unixTimeStamp)
Parameters
unixTimeStampdoubleDouble 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
unixTimeStampdoubleDouble unix timestamp (Time since Midnight Jan 1 1970)
Returns
- DateTime
C# date timeobject