projects/wms-framework/src/lib/baseframework/TimeRange.ts
Represents a time interval (time range).
Properties |
|
Methods |
|
Accessors |
constructor(arg1?: number, arg2?: number, arg3?: number, arg4?: number, arg5?: number)
|
Creates an instance of TimeRange. |
Private Static Readonly DaysPerTick |
Type : number
|
Default value : 1.15740740740741e-12
|
Private Static Readonly HoursPerTick |
Type : number
|
Default value : 2.77777777777778e-11
|
Private Static Readonly MillisecondsPerTick |
Type : number
|
Default value : 0.0001
|
Private Static Readonly MillisPerDay |
Type : number
|
Default value : 86400000
|
Private Static Readonly MillisPerHour |
Type : number
|
Default value : 3600000
|
Private Static Readonly MillisPerMinute |
Type : number
|
Default value : 60000
|
Private Static Readonly MillisPerSecond |
Type : number
|
Default value : 1000
|
Private Static Readonly MinutesPerTick |
Type : number
|
Default value : 1.66666666666667e-9
|
Private Static Readonly SecondsPerTick |
Type : number
|
Default value : 1e-7
|
Private ticks |
Type : number
|
Default value : 0
|
Stores the time range in ticks. |
Private Static Readonly TicksPerDay |
Type : number
|
Default value : 864000000000
|
Private Static Readonly TicksPerHour |
Type : number
|
Default value : 36000000000
|
Private Static Readonly TicksPerMillisecond |
Type : number
|
Default value : 10000
|
Private Static Readonly TicksPerMinute |
Type : number
|
Default value : 600000000
|
Private Static Readonly TicksPerSecond |
Type : number
|
Default value : 10000000
|
Static Add | ||||||||||||
Add(timeRange1: TimeRange, timeRange2: TimeRange)
|
||||||||||||
Adds two specified TimeRange instances.
Parameters :
Returns :
TimeRange
an object whose value is the sum of timeRange1 and timeRange2. |
Private Static CheckValueRange | ||||||||||||||||||||||||
CheckValueRange(value: number, min: number, max: number, valueName: string, input: string)
|
||||||||||||||||||||||||
Checks if the given value is within a specified range. Throws an error if the value is outside the allowed range.
Parameters :
Returns :
void
|
Public CompareTo | ||||||
CompareTo(x: TimeRange)
|
||||||
Compare current TimeRange with another specified TimeRange.
Parameters :
Returns :
number
Returns -1 if the current TimeRange is lower than the specified TimeRange, 1 if it is higher, or 0 if both are equal. |
Static Equal | ||||||||||||
Equal(timeRange1: TimeRange, timeRange2: TimeRange)
|
||||||||||||
Indicates whether two TimeRange instances are equal.
Parameters :
Returns :
boolean
true if the values of timeRange1 and timeRange2 are equal; otherwise, false. |
Static FromDays | ||||||||
FromDays(days: number)
|
||||||||
Returns a TimeRange that represents a specified number of days, where the specification is accurate to the nearest millisecond.
Parameters :
Returns :
TimeRange
|
Static FromHours | ||||||||
FromHours(hours: number)
|
||||||||
Returns a TimeRange that represents a specified number of hours, where the specification is accurate to the nearest millisecond.
Parameters :
Returns :
TimeRange
|
Static FromMilliseconds | ||||||||
FromMilliseconds(milliseconds: number)
|
||||||||
Returns a TimeRange that represents a specified number of milliseconds.
Parameters :
Returns :
TimeRange
|
Static FromMinutes | ||||||||
FromMinutes(minutes: number)
|
||||||||
Returns a TimeRange that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.
Parameters :
Returns :
TimeRange
|
Static FromSeconds | ||||||||
FromSeconds(seconds: number)
|
||||||||
Returns a TimeRange that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.
Parameters :
Returns :
TimeRange
|
Static GreaterThan | ||||||||||||
GreaterThan(timeRange1: TimeRange, timeRange2: TimeRange)
|
||||||||||||
Indicates whether a specified TimeRange is greater than another specified TimeRange.
Parameters :
Returns :
boolean
true if the value of timeRange1 is greater than the value of timeRange2; otherwise, false. |
Static GreaterThanOrEqual | ||||||||||||
GreaterThanOrEqual(timeRange1: TimeRange, timeRange2: TimeRange)
|
||||||||||||
Indicates whether a specified TimeRange is greater than or rqula to another specified TimeRange.
Parameters :
Returns :
boolean
true if the value of timeRange1 is greater than or equal to the value of timeRange2; otherwise, false. |
Static LessThan | ||||||||||||
LessThan(timeRange1: TimeRange, timeRange2: TimeRange)
|
||||||||||||
Indicates whether a specified TimeRange is less than another specified TimeRange.
Parameters :
Returns :
boolean
true if the value of timeRange1 is less than the value of timeRange2; otherwise, false. |
Static LessThanOrEqual | ||||||||||||
LessThanOrEqual(timeRange1: TimeRange, timeRange2: TimeRange)
|
||||||||||||
Indicates whether a specified TimeRange is less than or equal to another specified TimeRange.
Parameters :
Returns :
boolean
true if the value of timeRange1 is less than or equal to the value of timeRange2; otherwise, false. |
Static NotEqual | ||||||||||||
NotEqual(timeRange1: TimeRange, timeRange2: TimeRange)
|
||||||||||||
Indicates whether two TimeRange instances are not equal.
Parameters :
Returns :
boolean
true if the values of timeRange1 and timeRange2 are not equal; otherwise, false. |
Static Parse | ||||||
Parse(input: string)
|
||||||
Parse a string into a The format for the input is
Valid input examples are:
Invalid input values:
Parameters :
Returns :
TimeRange
{KeyTime} |
Static Subtract | ||||||||||||
Subtract(timeRange1: TimeRange, timeRange2: TimeRange)
|
||||||||||||
Subtracts a specified TimeRange from another specified TimeRange.
Parameters :
Returns :
TimeRange
an object whose value is the result of the value of timeRange1 minus the value of timeRange2. |
Public ToString |
ToString()
|
Converts the value of the current TimeRange object to its equivalent string representation.
Returns :
string
{string} |
MaxValue |
getMaxValue()
|
Represents the maximum TimeRange value. This field is read-only.
Returns :
TimeRange
|
MinValue |
getMinValue()
|
Represents the minimum TimeRange value. This field is read-only.
Returns :
TimeRange
|
Zero |
getZero()
|
Represents the zero TimeRange value. This field is read-only.
Returns :
TimeRange
|
Ticks |
getTicks()
|
Gets the number of ticks that represents the value of the current TimeRange structure.
Returns :
number
|
Milliseconds |
getMilliseconds()
|
Gets the millisecond component of the time interval represented by the current TimeRange structure. Returns only the Milliseconds portion, the actual Milliseconds value
Returns :
number
|
Seconds |
getSeconds()
|
Gets the seconds of the time interval represented by the current TimeRange structure. Returns only the Seconds portion, the actual Seconds value
Returns :
number
|
Minutes |
getMinutes()
|
Gets the minute component of the time interval represented by the current TimeRange structure. Returns only the Minutes portion, the actual Minutes value
Returns :
number
|
Hours |
getHours()
|
Gets the hour component of the time interval represented by the current TimeRange structure. Returns only the Hour portion, the actual Hour value
Returns :
number
|
Days |
getDays()
|
Gets the days component of the time interval represented by the current TimeRange structure. Returns only the Day portion, the actual Day value
Returns :
number
|
TotalMilliseconds |
getTotalMilliseconds()
|
Gets the value of the current TimeRange structure expressed in whole and fractional milliseconds. Returns the total number of milliseconds represented by this instance
Returns :
number
|
TotalSeconds |
getTotalSeconds()
|
Gets the value of the current TimeRange structure expressed in whole and fractional seconds. Returns the total number of seconds represented by this instance
Returns :
number
|
TotalMinutes |
getTotalMinutes()
|
Gets the value of the current TimeRange structure expressed in whole and fractional minutes. Returns the total number of minutes represented by this instance
Returns :
number
|
TotalHours |
getTotalHours()
|
Gets the value of the current TimeRange structure expressed in whole and fractional hours. Returns the total number of hours represented by this instance
Returns :
number
|
TotalDays |
getTotalDays()
|
Gets the value of the current TimeRange structure expressed in whole and fractional days. Returns the total number of days represented by this instance
Returns :
number
|
import { IComparable } from './collections';
/**
* Represents a time interval (time range).
*
* @export
* @class TimeRange
* @wType System.TimeSpan
* @wNetSupport
*/
// @dynamic
export class TimeRange implements IComparable<TimeRange> {
private static readonly TicksPerMillisecond = 10000;
private static readonly TicksPerSecond = 10000000;
private static readonly TicksPerMinute = 600000000;
private static readonly TicksPerHour = 36000000000;
private static readonly TicksPerDay = 864000000000;
private static readonly MillisecondsPerTick = 0.0001;
private static readonly SecondsPerTick = 1e-7;
private static readonly MinutesPerTick = 1.66666666666667e-9;
private static readonly HoursPerTick = 2.77777777777778e-11;
private static readonly DaysPerTick = 1.15740740740741e-12;
private static readonly MillisPerSecond = 1000;
private static readonly MillisPerMinute = 60000;
private static readonly MillisPerHour = 3600000;
private static readonly MillisPerDay = 86400000;
/**
* Stores the time range in ticks.
*
* @memberof TimeRange
*/
private ticks = 0;
/**
* Creates an instance of TimeRange with zero ticks.
*
* @memberof TimeRange
*/
constructor();
/**
* Creates an instance of TimeRange to the specified number of ticks.
*
* @param {number} ticks Ticks.
* @memberof TimeRange
*/
constructor(ticks: number);
/**
* Creates an instance of TimeRange to a specified number of hours, minutes, and seconds.
*
* @param {number} hours Number of hours.
* @param {number} minutes Number of minutes.
* @param {number} seconds Number of seconds.
* @memberof TimeRange
*/
constructor(hours: number, minutes: number, seconds: number);
/**
* Creates an instance of TimeRange to a specified number of days, hours, minutes, and seconds.
*
* @param {number} days Number of days.
* @param {number} hours Number of hours.
* @param {number} minutes Number of minutes.
* @param {number} seconds Number of seconds.
* @memberof TimeRange
*/
constructor(days: number, hours: number, minutes: number, seconds: number);
/**
* Creates an instance of TimeRange to a specified number of days, hours, minutes, seconds and milliseconds.
*
* @param {number} days Number of days.
* @param {number} hours Number of hours.
* @param {number} minutes Number of minutes.
* @param {number} seconds Number of seconds.
* @param {number} milliseconds Number of milliseconds.
* @memberof TimeRange
*/
constructor(
days: number,
hours: number,
minutes: number,
seconds: number,
milliseconds: number
);
/**
* Creates an instance of TimeRange.
*
* @param {number} arg1
* @param {number} arg2
* @param {number} arg3
* @param {number} arg4
* @param {number} arg5
* @memberof TimeRange
*/
constructor(
arg1?: number,
arg2?: number,
arg3?: number,
arg4?: number,
arg5?: number
) {
if (
arg1 !== undefined &&
arg2 !== undefined &&
arg3 !== undefined &&
arg4 !== undefined
) {
const days = arg1;
const hours = arg2;
const minutes = arg3;
const seconds = arg4;
const milloscds = arg5 ? arg5 : 0;
const milliseconds =
days * TimeRange.MillisPerDay +
hours * TimeRange.MillisPerHour +
minutes * TimeRange.MillisPerMinute +
seconds * TimeRange.MillisPerSecond;
this.ticks = (milliseconds + milloscds) * TimeRange.TicksPerMillisecond;
} else if (arg1 !== undefined && arg2 !== undefined && arg3 !== undefined) {
const hours = arg1;
const minutes = arg2;
const seconds = arg3;
const milliseconds =
hours * TimeRange.MillisPerHour +
minutes * TimeRange.MillisPerMinute +
seconds * TimeRange.MillisPerSecond;
this.ticks = milliseconds * TimeRange.TicksPerMillisecond;
} else if (arg1 !== undefined) {
this.ticks = arg1;
}
}
/**
* Represents the maximum TimeRange value. This field is read-only.
*
* @type {TimeRange}
* @memberof TimeRange
*/
public static get MaxValue(): TimeRange {
return new TimeRange(92233721036854775807); //long.MaxValue = 9223372036854775807
}
/**
* Represents the minimum TimeRange value. This field is read-only.
*
* @type {TimeRange}
* @memberof TimeRange
*/
public static get MinValue(): TimeRange {
return new TimeRange(-9223372036854775808); //long.MinValue = -9223372036854775808
}
/**
* Represents the zero TimeRange value. This field is read-only.
*
* @type {TimeRange}
* @memberof TimeRange
*/
public static get Zero(): TimeRange {
return new TimeRange(0);
}
/**
* Gets the number of ticks that represents the value of the current TimeRange structure.
*
* @type {number}
* @memberof TimeRange
*/
public get Ticks(): number {
return this.ticks;
}
/**
* Returns a TimeRange that represents a specified number of milliseconds.
*
* @param {number} milliseconds A number of milliseconds.
* @memberof TimeRange
*/
public static FromMilliseconds(milliseconds: number): TimeRange {
return new TimeRange(milliseconds * 10000);
}
/**
* Returns a TimeRange that represents a specified number of seconds, where the specification is accurate to the nearest millisecond.
*
* @param {number} seconds A number of seconds, accurate to the nearest millisecond.
* @memberof TimeRange
*/
public static FromSeconds(seconds: number): TimeRange {
const milliseconds = seconds * 1000;
return new TimeRange(milliseconds * 10000);
}
/**
* Returns a TimeRange that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.
*
* @param {number} minutes A number of minutes, accurate to the nearest millisecond.
* @memberof TimeRange
*/
public static FromMinutes(minutes: number): TimeRange {
const milliseconds = minutes * 60000;
return new TimeRange(milliseconds * 10000);
}
/**
* Returns a TimeRange that represents a specified number of hours, where the specification is accurate to the nearest millisecond.
*
* @param {number} hours A number of hours, accurate to the nearest millisecond.
* @memberof TimeRange
*/
public static FromHours(hours: number): TimeRange {
const milliseconds = hours * 3600000;
return new TimeRange(milliseconds * 10000);
}
/**
* Returns a TimeRange that represents a specified number of days, where the specification is accurate to the nearest millisecond.
*
* @param {number} days A number of days, accurate to the nearest millisecond.
* @memberof TimeRange
*/
public static FromDays(days: number): TimeRange {
const milliseconds = days * 86400000;
return new TimeRange(milliseconds * 10000);
}
/**
* Subtracts a specified TimeRange from another specified TimeRange.
*
* @returns an object whose value is the result of the value of timeRange1 minus the value of timeRange2.
* @param {TimeRange} timeRange1 The time interval to subtract from (the minuend).
* @param {TimeRange} timeRange2 The time interval to subtract (the subtrahend).
* @memberof TimeRange
*/
public static Subtract(
timeRange1: TimeRange,
timeRange2: TimeRange
): TimeRange {
const ticks = timeRange1.Ticks - timeRange2.Ticks;
return new TimeRange(ticks);
}
/**
* Adds two specified TimeRange instances.
*
* @returns an object whose value is the sum of timeRange1 and timeRange2.
* @param {TimeRange} timeRange1 The first time interval to add.
* @param {TimeRange} timeRange2 The second time interval to add.
* @memberof TimeRange
*/
public static Add(timeRange1: TimeRange, timeRange2: TimeRange): TimeRange {
const ticks = timeRange1.Ticks + timeRange2.Ticks;
return new TimeRange(ticks);
}
/**
* Indicates whether two TimeRange instances are equal.
*
* @returns true if the values of timeRange1 and timeRange2 are equal; otherwise, false.
* @param {TimeRange} timeRange1 The first time interval to compare.
* @param {TimeRange} timeRange2 The second time interval to compare.
* @memberof TimeRange
*/
public static Equal(timeRange1: TimeRange, timeRange2: TimeRange): boolean {
return timeRange1.Ticks === timeRange2.Ticks;
}
/**
* Indicates whether two TimeRange instances are not equal.
*
* @returns true if the values of timeRange1 and timeRange2 are not equal; otherwise, false.
* @param {TimeRange} timeRange1 The first time interval to compare.
* @param {TimeRange} timeRange2 The second time interval to compare.
* @memberof TimeRange
*/
public static NotEqual(
timeRange1: TimeRange,
timeRange2: TimeRange
): boolean {
return timeRange1.Ticks !== timeRange2.Ticks;
}
/**
* Indicates whether a specified TimeRange is less than another specified TimeRange.
*
* @returns true if the value of timeRange1 is less than the value of timeRange2; otherwise, false.
* @param {TimeRange} timeRange1 The first time interval to compare.
* @param {TimeRange} timeRange2 The second time interval to compare.
* @memberof TimeRange
*/
public static LessThan(
timeRange1: TimeRange,
timeRange2: TimeRange
): boolean {
return timeRange1.Ticks < timeRange2.Ticks;
}
/**
* Indicates whether a specified TimeRange is less than or equal to another specified TimeRange.
*
* @returns true if the value of timeRange1 is less than or equal to the value of timeRange2; otherwise, false.
* @param {TimeRange} timeRange1 The first time interval to compare.
* @param {TimeRange} timeRange2 The second time interval to compare.
* @memberof TimeRange
*/
public static LessThanOrEqual(
timeRange1: TimeRange,
timeRange2: TimeRange
): boolean {
return timeRange1.Ticks <= timeRange2.Ticks;
}
/**
* Indicates whether a specified TimeRange is greater than another specified TimeRange.
*
* @returns true if the value of timeRange1 is greater than the value of timeRange2; otherwise, false.
* @param {TimeRange} timeRange1 The first time interval to compare.
* @param {TimeRange} timeRange2 The second time interval to compare.
* @memberof TimeRange
*/
public static GreaterThan(
timeRange1: TimeRange,
timeRange2: TimeRange
): boolean {
return timeRange1.Ticks > timeRange2.Ticks;
}
/**
* Indicates whether a specified TimeRange is greater than or rqula to another specified TimeRange.
*
* @returns true if the value of timeRange1 is greater than or equal to the value of timeRange2; otherwise, false.
* @param {TimeRange} timeRange1 The first time interval to compare.
* @param {TimeRange} timeRange2 The second time interval to compare.
* @memberof TimeRange
*/
public static GreaterThanOrEqual(
timeRange1: TimeRange,
timeRange2: TimeRange
): boolean {
return timeRange1.Ticks >= timeRange2.Ticks;
}
/**
* Parse a string into a `TimeRange`.
*
* The format for the input is `dd.hh:mm:ss.ff`, where:
* - `dd` = days - optional
* - `hh` = hours - mandatory
* - `mm` = minutes - optional
* - `ss` = seconds - optional
* - `ff` = fractionalSeconds - optional
*
* Valid input examples are:
* - `1.2:3:4.5` = 1 day, 2 hours, 3 minutes, 4 seconds, 500 milliseconds.
* - `02:30` = 2 hours, 30 minutes.
* - `3.2:15` = 3 days, 2 hours, 15 minutes.
* - `13` = *special* - this is interpreted as 13 days, not 13 hours.
*
* Invalid input values:
* - `1.2` = ambiguous input. It could mean 1 day and 2 hours, or 1 second and 200 milliseconds.
* - `15:52.3` = 15 minutes, 52 seconds and 300 milliseconds. Is invalid because hours is mandatory.
* - `3:14:` = lacks seconds. In general, a number should always follow `:` or `.`.
*
* @static
* @param {string} input
* @return {*} {KeyTime}
* @memberof TimeRange
*/
public static Parse(input: string): TimeRange {
if (/^\s*(\d+)\s*$/.test(input)) {
// There is only one number in the input, without `:` or `.`, like "13".
// "13" should be interpreted as 13 days, not 13 hours.
const days = Number.parseInt(input, 10);
return new TimeRange(days, 0, 0, 0, 0);
}
// This regex should match the following patterns:
// - `dd.hh:mm:ss.ff`
// - `dd.hh:mm:ss`
// - `dd.hh:mm`
// - `hh:mm:ss.ff`
// - `hh:mm:ss`
// - `hh:mm`
const matches = input.match(
/^\s*((\d+)\.)?(\d+):(\d+)(:(\d+)(\.(\d+))?)?\s*$/
);
if (matches != null) {
const days = Number.parseInt(matches[2] ?? '0', 10);
const hours = Number.parseInt(matches[3] ?? '0', 10);
const minutes = Number.parseInt(matches[4] ?? '0', 10);
const seconds = Number.parseInt(matches[6] ?? '0', 10);
TimeRange.CheckValueRange(hours, 0, 23, 'Hours', input);
TimeRange.CheckValueRange(minutes, 0, 59, 'Minutes', input);
TimeRange.CheckValueRange(seconds, 0, 59, 'Seconds', input);
// We need to convert the fractional seconds to milliseconds.
const fractionalSeconds = matches[8];
const fullNumber = fractionalSeconds ? `0.${fractionalSeconds}` : '0';
if (fullNumber.length > 9) {
throw Error(
`Wrong input format for TimeRange: "${input}". Fractional seconds have more than 7 digits.`
);
}
const milliseconds = Math.floor(Number.parseFloat(fullNumber) * 1000);
return new TimeRange(days, hours, minutes, seconds, milliseconds);
}
throw Error(
`Wrong input format for TimeRange: "${input}" is not a valid time range.`
);
}
/**
* Checks if the given value is within a specified range.
* Throws an error if the value is outside the allowed range.
*
* @private
* @static
* @param {number} value The value to check.
* @param {number} min The lower limit for the value.
* @param {number} max The higher limit for the value.
* @param {string} valueName Name of the value, to show on the error message.
* @param {string} input The original input string, to show on the error message.
* @memberof TimeRange
*/
private static CheckValueRange(
value: number,
min: number,
max: number,
valueName: string,
input: string
): void {
if (value < min || value > max) {
throw Error(
`Wrong input format for TimeRange: "${input}". ${valueName} are outside of valid range (${min}-${max}).`
);
}
}
/**
* Gets the millisecond component of the time interval represented by the current TimeRange structure.
* Returns only the Milliseconds portion, the actual Milliseconds value
*
* @type {number}
* @memberof TimeRange
*/
public get Milliseconds(): number {
return Math.trunc((this.ticks / TimeRange.TicksPerMillisecond) % 1000);
}
/**
* Gets the seconds of the time interval represented by the current TimeRange structure.
* Returns only the Seconds portion, the actual Seconds value
*
* @type {number}
* @memberof TimeRange
*/
public get Seconds(): number {
return Math.trunc((this.ticks / TimeRange.TicksPerSecond) % 60);
}
/**
* Gets the minute component of the time interval represented by the current TimeRange structure.
* Returns only the Minutes portion, the actual Minutes value
*
* @type {number}
* @memberof TimeRange
*/
public get Minutes(): number {
return Math.trunc((this.ticks / TimeRange.TicksPerMinute) % 60);
}
/**
* Gets the hour component of the time interval represented by the current TimeRange structure.
* Returns only the Hour portion, the actual Hour value
*
* @type {number}
* @memberof TimeRange
*/
public get Hours(): number {
return Math.trunc((this.ticks / TimeRange.TicksPerHour) % 24);
}
/**
* Gets the days component of the time interval represented by the current TimeRange structure.
* Returns only the Day portion, the actual Day value
*
* @type {number}
* @memberof TimeRange
*/
public get Days(): number {
return Math.trunc(this.ticks / TimeRange.TicksPerDay);
}
/**
* Gets the value of the current TimeRange structure expressed in whole and fractional milliseconds.
* Returns the total number of milliseconds represented by this instance
*
* @type {number}
* @memberof TimeRange
*/
public get TotalMilliseconds(): number {
return this.ticks * TimeRange.MillisecondsPerTick;
}
/**
* Gets the value of the current TimeRange structure expressed in whole and fractional seconds.
* Returns the total number of seconds represented by this instance
*
* @type {number}
* @memberof TimeRange
*/
public get TotalSeconds(): number {
return this.ticks * TimeRange.SecondsPerTick;
}
/**
* Gets the value of the current TimeRange structure expressed in whole and fractional minutes.
* Returns the total number of minutes represented by this instance
*
* @type {number}
* @memberof TimeRange
*/
public get TotalMinutes(): number {
return this.ticks * TimeRange.MinutesPerTick;
}
/**
* Gets the value of the current TimeRange structure expressed in whole and fractional hours.
* Returns the total number of hours represented by this instance
*
* @type {number}
* @memberof TimeRange
*/
public get TotalHours(): number {
return this.ticks * TimeRange.HoursPerTick;
}
/**
* Gets the value of the current TimeRange structure expressed in whole and fractional days.
* Returns the total number of days represented by this instance
*
* @type {number}
* @memberof TimeRange
*/
public get TotalDays(): number {
return this.ticks * TimeRange.DaysPerTick;
}
/**
* Compare current TimeRange with another specified TimeRange.
* @param {TimeRange} x
* @return Returns -1 if the current TimeRange is lower than the specified TimeRange, 1 if it is higher, or 0 if both are equal.
* @memberof TimeRange
*/
public CompareTo(x: TimeRange): number {
if (!x || this.TotalMilliseconds > x.TotalMilliseconds) return 1;
else if (this.TotalMilliseconds === x.TotalMilliseconds) {
return 0;
} else {
return -1;
}
}
/**
* Converts the value of the current TimeRange object to its equivalent string representation.
*
* @return {*} {string}
* @memberof TimeRange
*/
public ToString(): string {
const days = this.Days;
const hours = this.Hours;
const minutes = this.Minutes;
const seconds = this.Seconds;
const milliseconds = this.Milliseconds;
let str = '';
if (days !== 0) {
str += days + '.';
}
str += (hours.toString().length === 1 ? '0' + hours : hours) + ':';
str += (minutes.toString().length === 1 ? '0' + minutes : minutes) + ':';
str += seconds.toString().length === 1 ? '0' + seconds : seconds;
if (milliseconds !== 0) {
str += '.' + milliseconds;
}
return str;
}
}