From cf2f7df7618b3dd609773c00933772a78aca2595 Mon Sep 17 00:00:00 2001 From: afractal Date: Fri, 16 Jun 2017 13:46:59 +0200 Subject: [PATCH 1/4] add type definitions for timespan --- types/sharp-timer/index.d.ts | 58 ++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/types/sharp-timer/index.d.ts b/types/sharp-timer/index.d.ts index 928a47eed7..e68b5aa04e 100644 --- a/types/sharp-timer/index.d.ts +++ b/types/sharp-timer/index.d.ts @@ -1,17 +1,24 @@ -// Type definitions for sharp-timer 0.3 +// Type definitions for sharp-timer 1.0 // Project: https://github.com/afractal/SharpTimer // Definitions by: Hermes Gjini - afractal // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + +export const millisPerSecond: number; +export const millisPerMinute: number; +export const millisPerHour: number; +export const millisPerDay: number; + export type ElapsedEvent = () => void; export type ElapsingEvent = (intervalValue: number) => void; export class Timer { - private _enabled; - private _stopped; - private _interval; - private _intervalElapsedEvents; - private _intervalElapsingEvents; + private _enabled: boolean; + private _stopped: boolean; + private _interval: number; + private _intervalElapsedEvents: ElapsedEvent[]; + private _intervalElapsingEvents: ElapsingEvent[]; constructor(interval: number); readonly enabled: boolean; readonly stopped: boolean; @@ -23,18 +30,15 @@ export class Timer { onIntervalElapsed(intervalElapsedHandler: ElapsedEvent): void; onIntervalElapsing(intervalElapsingHandler: ElapsingEvent): void; toString(): string; - private getDoubleDigit(number); - private checkForValidInterval(interval); + private getDoubleDigit(number: number): string; + private checkForValidInterval(interval: number): void; } export class Stopwatch { - private _isRunning; - private _elapsedMilliseconds; - private _startedTimeInMillis; - private _intervalIds; - private static readonly millisPerSecond; - private static readonly millisPerMinute; - private static readonly millisPerHour; + private _isRunning: boolean; + private _elapsedMilliseconds: number; + private _startedTimeInMillis: number; + private _intervalIds: Array; constructor(); readonly elapsed: string; readonly elapsedMilliseconds: number; @@ -48,5 +52,27 @@ export class Stopwatch { reset(): void; restart(): void; dispose(): void; - private getDoubleDigit(num); + private getDoubleDigit(num: number): string; +} + +export class Timespan { + private _milliseconds: number; + private constructor(milliseconds: number); + readonly milliseconds: number; + readonly seconds: number; + readonly minutes: number; + readonly hours: number; + readonly days: number; + static fromDays(days: number): Timespan; + static fromHours(hours: number): Timespan; + static fromMinutes(minutes: number): Timespan; + static fromSeconds(seconds: number): Timespan; + static fromMilliseconds(milliseconds: number): Timespan; + static compare(t1: Timespan, t2: Timespan): 1 | 0 | -1; + static equals(t1: Timespan, t2: Timespan): boolean; + addMutable(timespan: Timespan): void; + substractMutable(timespan: Timespan): void; + add(timespan: Timespan): Timespan; + substract(timespan: Timespan): Timespan; + negate(): Timespan; } From 0a28af9b9159306f0664b3a3034497a2126ac38a Mon Sep 17 00:00:00 2001 From: afractal Date: Sat, 17 Jun 2017 11:55:42 +0200 Subject: [PATCH 2/4] add documentation --- types/sharp-timer/index.d.ts | 381 ++++++++++++++++++++----- types/sharp-timer/sharp-timer-tests.ts | 8 +- 2 files changed, 319 insertions(+), 70 deletions(-) diff --git a/types/sharp-timer/index.d.ts b/types/sharp-timer/index.d.ts index e68b5aa04e..88ebbc9844 100644 --- a/types/sharp-timer/index.d.ts +++ b/types/sharp-timer/index.d.ts @@ -1,78 +1,323 @@ -// Type definitions for sharp-timer 1.0 +// Type definitions for sharp-timer library. 1.0 // Project: https://github.com/afractal/SharpTimer // Definitions by: Hermes Gjini - afractal // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// -export const millisPerSecond: number; -export const millisPerMinute: number; -export const millisPerHour: number; -export const millisPerDay: number; - -export type ElapsedEvent = () => void; -export type ElapsingEvent = (intervalValue: number) => void; - -export class Timer { - private _enabled: boolean; - private _stopped: boolean; - private _interval: number; - private _intervalElapsedEvents: ElapsedEvent[]; - private _intervalElapsingEvents: ElapsingEvent[]; - constructor(interval: number); - readonly enabled: boolean; - readonly stopped: boolean; - interval: number; - start(): void; - pause(): void; - resume(): void; - stop(): void; - onIntervalElapsed(intervalElapsedHandler: ElapsedEvent): void; - onIntervalElapsing(intervalElapsingHandler: ElapsingEvent): void; - toString(): string; - private getDoubleDigit(number: number): string; - private checkForValidInterval(interval: number): void; +declare global { + namespace SharpTimer { + const millisPerSecond: 1000; + const millisPerMinute: 60000; + const millisPerHour: 3600000; + const millisPerDay: 86400000; + type ElapsedEvent = () => void; + type ElapsingEvent = (intervalValue: number) => void; + } } -export class Stopwatch { - private _isRunning: boolean; - private _elapsedMilliseconds: number; - private _startedTimeInMillis: number; - private _intervalIds: Array; - constructor(); - readonly elapsed: string; - readonly elapsedMilliseconds: number; - readonly elapsedSeconds: number; - readonly elapsedMinutes: number; - readonly elapsedHours: number; - readonly isRunning: boolean; - static startNew(): Stopwatch; - start(): void; - stop(): void; - reset(): void; - restart(): void; - dispose(): void; - private getDoubleDigit(num: number): string; +declare module "sharp-timer" { + /** + * Simulates the actions of a generic timer, + * generates elapsing and elapsed events for a specified interval. + */ + class Timer { + private _enabled: boolean; + private _stopped: boolean; + private _interval: number; + private _intervalElapsedEvents: SharpTimer.ElapsedEvent[]; + private _intervalElapsingEvents: SharpTimer.ElapsingEvent[]; + + /** + * Initializes a new instance of the Timer class, + * and sets all the properties to their initial values. + * @param interval + * The time, in milliseconds, in which the timer will be active. + * The value must be greater than zero. + */ + constructor(interval: number); + + /** + * Gets a boolean value to indicate the enabled state + * of the current Timer instance. + * @readonly + * @default true + */ + readonly enabled: boolean; + + /** + * Gets a boolean value to indicate the stopped state + * of the current Timer instance. + * @readonly + * @default false + */ + readonly stopped: boolean; + + /** + * Gets or sets the remaining interval in milliseconds. + * The value must be greater than zero. + */ + interval: number; + + /** + * Starts raising the Timer events + * by setting the enabled property to true. + */ + start(): void; + + /** + * Pauses the Timer instance by setting the enabled property to false. + */ + pause(): void; + + /** + * Resumes the Timer instance by setting the enabled property to true. + */ + resume(): void; + + /** + * Stops raising the Timer event + * by setting the enabled property to false. + */ + stop(): void; + + /** + * Occurs when the interval has completely elapsed. + * @param intervalElapsedHandler + * The callback which will be executed when + * the interval elapsed event occurs. + */ + onIntervalElapsed(intervalElapsedHandler: SharpTimer.ElapsedEvent): void; + + /** + * Occurs when the interval elapses and completely elapsed. + * @param intervalElapsingHandler + * The callback which will be executed when + * the interval elapsing event occurs. + */ + onIntervalElapsing(intervalElapsingHandler: SharpTimer.ElapsingEvent): void; + + /** + * Returns a string represenation of the remaining + * in this format: minutes:seconds. + * examples: 20:23, 00:04, 59:59 + */ + toString(): string; + + private getDoubleDigit(number: number): string; + + private checkForValidInterval(interval: number): void; + } + + /** + * Simulates the actions of a generic stopwatch. + */ + class Stopwatch { + private _isRunning: boolean; + private _elapsedMilliseconds: number; + private _startedTimeInMillis: number; + private _intervalIds: Array; + + /** + * Initializes a new instance of the Stopwatch class. + */ + constructor(); + + /** + * Gets the elapsed time in this format: + * hrs:mins:secs:ms + * @readonly + */ + readonly elapsed: string; + + /** + * Gets the elapsed time in milliseconds. + * @readonly + */ + readonly elapsedMilliseconds: number; + + /** + * Gets the elapsed time in seconds. + * @readonly + */ + readonly elapsedSeconds: number; + + /** + * Gets the elapsed time in minutes. + * @readonly + */ + readonly elapsedMinutes: number; + + /** + * Gets the elapsed hours in hours. + * @readonly + */ + readonly elapsedHours: number; + + /** + * Gets the isRunning state of the current Stopwatch instance. + * @readonly + * @default false + */ + readonly isRunning: boolean; + + /** + * Initializes a new Stopwatch instance and + * starts measuring elapsed time. + */ + static startNew(): Stopwatch; + + /** + * Starts, or resumes the Stopwatch + * from measuring elapsed time. + */ + start(): void; + + /** + * Stops the Stopwatch from measuring elapsed time. + */ + stop(): void; + + /** + * Stops the Stopwatch and resets the elapsed time to zero. + */ + reset(): void; + + /** + * Stops the Stopwatch, + * resets the elapsed time to zero + * and starts the Stopwatch for measuring elapsed time. + * It is a shortcut for writing + * reset then start. + */ + restart(): void; + + /** + * Stops the Stopwatch and cleans up the intervals. + */ + dispose(): void; + + private getDoubleDigit(num: number): string; + } + + /** + * Simulates an object that represents a time interval. + */ + class Timespan { + private _milliseconds: number; + private constructor(milliseconds: number); + + /** + * Gets the time interval in milliseconds. + * @readonly + */ + readonly milliseconds: number; + + /** + * Gets the time interval in seconds. + * @readonly + */ + readonly seconds: number; + + /** + * Gets the time interval in minutes. + * @readonly + */ + readonly minutes: number; + + /** + * Gets the time interval in hours. + * @readonly + */ + readonly hours: number; + + /** + * Gets the time interval in days. + * @readonly + */ + readonly days: number; + + /** + * Returns a Timespan that represents a specified number of days. + * @param days The number of days. + */ + static fromDays(days: number): Timespan; + + /** + * Returns a Timespan that represents a specified number of hours. + * @param hours The number of hours. + */ + static fromHours(hours: number): Timespan; + + /** + * Returns a Timespan that represents a specified number of minutes. + * @param minutes The number of minutes. + */ + static fromMinutes(minutes: number): Timespan; + + /** + * Returns a Timespan that represents a specified number of seconds. + * @param seconds The number of seconds. + */ + static fromSeconds(seconds: number): Timespan; + + /** + * Returns a Timespan that represents a specified number of milliseconds. + * @param milliseconds The number of milliseconds. + */ + static fromMilliseconds(milliseconds: number): Timespan; + + /** + * Compares two Timespan objects and + * returns an integer that indicates whether + * the first value is shorter than, equal to, + * or longer than the second value. + * @param t1 The first Timespan to compare. + * @param t2 The second Timespan to compare. + */ + static compare(t1: Timespan, t2: Timespan): 1 | 0 | -1; + + /** + * Returns a boolean value that indicates + * whether two specified instances of Timespan are equal. + * @param t1 The first Timespan to compare. + * @param t2 The second Timespan to compare. + */ + static equals(t1: Timespan, t2: Timespan): boolean; + + /** + * Adds the specified Timespan to this instance. + * @param timespan The Timespan to add. + */ + addMutable(timespan: Timespan): void; + + /** + * Substracts the specified Timespan from this instance. + * @param timespan The Timespan to substract. + */ + substractMutable(timespan: Timespan): void; + + /** + * Returns a new Timespan object whose + * value is the sum of the specified Timespan object and this instance. + * @param timespan The Timespan to add. + */ + add(timespan: Timespan): Timespan; + + /** + * Returns a new Timespan object whose + * value is the difference between the + * specified Timespan object and this instance. + * @param timespan The Timespan to substract. + */ + substract(timespan: Timespan): Timespan; + + /** + * Returns a new Timespan object + * whose value is the negated value of this instance. + */ + negate(): Timespan; + } } -export class Timespan { - private _milliseconds: number; - private constructor(milliseconds: number); - readonly milliseconds: number; - readonly seconds: number; - readonly minutes: number; - readonly hours: number; - readonly days: number; - static fromDays(days: number): Timespan; - static fromHours(hours: number): Timespan; - static fromMinutes(minutes: number): Timespan; - static fromSeconds(seconds: number): Timespan; - static fromMilliseconds(milliseconds: number): Timespan; - static compare(t1: Timespan, t2: Timespan): 1 | 0 | -1; - static equals(t1: Timespan, t2: Timespan): boolean; - addMutable(timespan: Timespan): void; - substractMutable(timespan: Timespan): void; - add(timespan: Timespan): Timespan; - substract(timespan: Timespan): Timespan; - negate(): Timespan; -} +export * from 'sharp-timer'; diff --git a/types/sharp-timer/sharp-timer-tests.ts b/types/sharp-timer/sharp-timer-tests.ts index 5d8976e474..e5c758b32a 100644 --- a/types/sharp-timer/sharp-timer-tests.ts +++ b/types/sharp-timer/sharp-timer-tests.ts @@ -1,7 +1,11 @@ -import { Timer, Stopwatch } from 'sharp-timer'; +import { Timer, Stopwatch, Timespan } from 'sharp-timer'; +import * as s from 'sharp-timer'; +import S = require('sharp-timer'); + +type Elapsed = SharpTimer.ElapsedEvent; let timer = new Timer(10); - +timer.toString(); timer.onIntervalElapsing(i => { }); timer.onIntervalElapsed(() => { timer.stop(); From 1b909ed49b44d00f655a735f0b10fdd1feb75a72 Mon Sep 17 00:00:00 2001 From: afractal Date: Wed, 21 Jun 2017 11:09:50 +0200 Subject: [PATCH 3/4] fixed problems with v1 definitions and preserved v0 definitions for sharp-timer --- types/sharp-timer/index.d.ts | 26 +++++------- types/sharp-timer/sharp-timer-tests.ts | 26 ++++++++++-- types/sharp-timer/v0/index.d.ts | 52 +++++++++++++++++++++++ types/sharp-timer/v0/sharp-timer-tests.ts | 10 +++++ types/sharp-timer/v0/tsconfig.json | 27 ++++++++++++ types/sharp-timer/v0/tslint.json | 3 ++ 6 files changed, 125 insertions(+), 19 deletions(-) create mode 100644 types/sharp-timer/v0/index.d.ts create mode 100644 types/sharp-timer/v0/sharp-timer-tests.ts create mode 100644 types/sharp-timer/v0/tsconfig.json create mode 100644 types/sharp-timer/v0/tslint.json diff --git a/types/sharp-timer/index.d.ts b/types/sharp-timer/index.d.ts index 88ebbc9844..ba5b8b68a4 100644 --- a/types/sharp-timer/index.d.ts +++ b/types/sharp-timer/index.d.ts @@ -5,18 +5,14 @@ /// -declare global { - namespace SharpTimer { - const millisPerSecond: 1000; - const millisPerMinute: 60000; - const millisPerHour: 3600000; - const millisPerDay: 86400000; - type ElapsedEvent = () => void; - type ElapsingEvent = (intervalValue: number) => void; - } -} - declare module "sharp-timer" { + const millisPerSecond: 1000; + const millisPerMinute: 60000; + const millisPerHour: 3600000; + const millisPerDay: 86400000; + type ElapsedEvent = () => void; + type ElapsingEvent = (intervalValue: number) => void; + /** * Simulates the actions of a generic timer, * generates elapsing and elapsed events for a specified interval. @@ -25,8 +21,8 @@ declare module "sharp-timer" { private _enabled: boolean; private _stopped: boolean; private _interval: number; - private _intervalElapsedEvents: SharpTimer.ElapsedEvent[]; - private _intervalElapsingEvents: SharpTimer.ElapsingEvent[]; + private _intervalElapsedEvents: ElapsedEvent[]; + private _intervalElapsingEvents: ElapsingEvent[]; /** * Initializes a new instance of the Timer class, @@ -87,7 +83,7 @@ declare module "sharp-timer" { * The callback which will be executed when * the interval elapsed event occurs. */ - onIntervalElapsed(intervalElapsedHandler: SharpTimer.ElapsedEvent): void; + onIntervalElapsed(intervalElapsedHandler: ElapsedEvent): void; /** * Occurs when the interval elapses and completely elapsed. @@ -95,7 +91,7 @@ declare module "sharp-timer" { * The callback which will be executed when * the interval elapsing event occurs. */ - onIntervalElapsing(intervalElapsingHandler: SharpTimer.ElapsingEvent): void; + onIntervalElapsing(intervalElapsingHandler: ElapsingEvent): void; /** * Returns a string represenation of the remaining diff --git a/types/sharp-timer/sharp-timer-tests.ts b/types/sharp-timer/sharp-timer-tests.ts index e5c758b32a..db4d21b421 100644 --- a/types/sharp-timer/sharp-timer-tests.ts +++ b/types/sharp-timer/sharp-timer-tests.ts @@ -1,9 +1,8 @@ -import { Timer, Stopwatch, Timespan } from 'sharp-timer'; -import * as s from 'sharp-timer'; -import S = require('sharp-timer'); +import { Timer, Stopwatch, Timespan, millisPerSecond } from 'sharp-timer'; -type Elapsed = SharpTimer.ElapsedEvent; +const millisecondsPerSecond = millisPerSecond; +// timer test let timer = new Timer(10); timer.toString(); timer.onIntervalElapsing(i => { }); @@ -12,3 +11,22 @@ timer.onIntervalElapsed(() => { }); timer.start(); + +// stopwatch test +let stopwatch = Stopwatch.startNew(); + +const intervalId = setInterval(() => { }, 10); + +setTimeout(() => { + clearInterval(intervalId); + stopwatch.dispose(); +}, 100); + +// timespan test +const { + days, + hours, + minutes, + seconds, + milliseconds +} = Timespan.fromDays(2); diff --git a/types/sharp-timer/v0/index.d.ts b/types/sharp-timer/v0/index.d.ts new file mode 100644 index 0000000000..928a47eed7 --- /dev/null +++ b/types/sharp-timer/v0/index.d.ts @@ -0,0 +1,52 @@ +// Type definitions for sharp-timer 0.3 +// Project: https://github.com/afractal/SharpTimer +// Definitions by: Hermes Gjini - afractal +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export type ElapsedEvent = () => void; +export type ElapsingEvent = (intervalValue: number) => void; + +export class Timer { + private _enabled; + private _stopped; + private _interval; + private _intervalElapsedEvents; + private _intervalElapsingEvents; + constructor(interval: number); + readonly enabled: boolean; + readonly stopped: boolean; + interval: number; + start(): void; + pause(): void; + resume(): void; + stop(): void; + onIntervalElapsed(intervalElapsedHandler: ElapsedEvent): void; + onIntervalElapsing(intervalElapsingHandler: ElapsingEvent): void; + toString(): string; + private getDoubleDigit(number); + private checkForValidInterval(interval); +} + +export class Stopwatch { + private _isRunning; + private _elapsedMilliseconds; + private _startedTimeInMillis; + private _intervalIds; + private static readonly millisPerSecond; + private static readonly millisPerMinute; + private static readonly millisPerHour; + constructor(); + readonly elapsed: string; + readonly elapsedMilliseconds: number; + readonly elapsedSeconds: number; + readonly elapsedMinutes: number; + readonly elapsedHours: number; + readonly isRunning: boolean; + static startNew(): Stopwatch; + start(): void; + stop(): void; + reset(): void; + restart(): void; + dispose(): void; + private getDoubleDigit(num); +} diff --git a/types/sharp-timer/v0/sharp-timer-tests.ts b/types/sharp-timer/v0/sharp-timer-tests.ts new file mode 100644 index 0000000000..5d8976e474 --- /dev/null +++ b/types/sharp-timer/v0/sharp-timer-tests.ts @@ -0,0 +1,10 @@ +import { Timer, Stopwatch } from 'sharp-timer'; + +let timer = new Timer(10); + +timer.onIntervalElapsing(i => { }); +timer.onIntervalElapsed(() => { + timer.stop(); +}); + +timer.start(); diff --git a/types/sharp-timer/v0/tsconfig.json b/types/sharp-timer/v0/tsconfig.json new file mode 100644 index 0000000000..37520d93f4 --- /dev/null +++ b/types/sharp-timer/v0/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "sharp-timer": [ + "sharp-timer/v0" + ] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "sharp-timer-tests.ts" + ] +} diff --git a/types/sharp-timer/v0/tslint.json b/types/sharp-timer/v0/tslint.json new file mode 100644 index 0000000000..d88586e5bd --- /dev/null +++ b/types/sharp-timer/v0/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} From 6c572e6f16076583cfc1342103ec7da2d109ea1b Mon Sep 17 00:00:00 2001 From: afractal Date: Wed, 21 Jun 2017 15:22:56 +0200 Subject: [PATCH 4/4] remove module declaration --- types/sharp-timer/index.d.ts | 578 +++++++++++++++++------------------ 1 file changed, 287 insertions(+), 291 deletions(-) diff --git a/types/sharp-timer/index.d.ts b/types/sharp-timer/index.d.ts index ba5b8b68a4..cf2f7cba3f 100644 --- a/types/sharp-timer/index.d.ts +++ b/types/sharp-timer/index.d.ts @@ -5,315 +5,311 @@ /// -declare module "sharp-timer" { - const millisPerSecond: 1000; - const millisPerMinute: 60000; - const millisPerHour: 3600000; - const millisPerDay: 86400000; - type ElapsedEvent = () => void; - type ElapsingEvent = (intervalValue: number) => void; +export const millisPerSecond: 1000; +export const millisPerMinute: 60000; +export const millisPerHour: 3600000; +export const millisPerDay: 86400000; +export type ElapsedEvent = () => void; +export type ElapsingEvent = (intervalValue: number) => void; + +/** + * Simulates the actions of a generic timer, + * generates elapsing and elapsed events for a specified interval. + */ +export class Timer { + private _enabled: boolean; + private _stopped: boolean; + private _interval: number; + private _intervalElapsedEvents: ElapsedEvent[]; + private _intervalElapsingEvents: ElapsingEvent[]; /** - * Simulates the actions of a generic timer, - * generates elapsing and elapsed events for a specified interval. + * Initializes a new instance of the Timer class, + * and sets all the properties to their initial values. + * @param interval + * The time, in milliseconds, in which the timer will be active. + * The value must be greater than zero. */ - class Timer { - private _enabled: boolean; - private _stopped: boolean; - private _interval: number; - private _intervalElapsedEvents: ElapsedEvent[]; - private _intervalElapsingEvents: ElapsingEvent[]; - - /** - * Initializes a new instance of the Timer class, - * and sets all the properties to their initial values. - * @param interval - * The time, in milliseconds, in which the timer will be active. - * The value must be greater than zero. - */ - constructor(interval: number); - - /** - * Gets a boolean value to indicate the enabled state - * of the current Timer instance. - * @readonly - * @default true - */ - readonly enabled: boolean; - - /** - * Gets a boolean value to indicate the stopped state - * of the current Timer instance. - * @readonly - * @default false - */ - readonly stopped: boolean; - - /** - * Gets or sets the remaining interval in milliseconds. - * The value must be greater than zero. - */ - interval: number; - - /** - * Starts raising the Timer events - * by setting the enabled property to true. - */ - start(): void; - - /** - * Pauses the Timer instance by setting the enabled property to false. - */ - pause(): void; - - /** - * Resumes the Timer instance by setting the enabled property to true. - */ - resume(): void; - - /** - * Stops raising the Timer event - * by setting the enabled property to false. - */ - stop(): void; - - /** - * Occurs when the interval has completely elapsed. - * @param intervalElapsedHandler - * The callback which will be executed when - * the interval elapsed event occurs. - */ - onIntervalElapsed(intervalElapsedHandler: ElapsedEvent): void; - - /** - * Occurs when the interval elapses and completely elapsed. - * @param intervalElapsingHandler - * The callback which will be executed when - * the interval elapsing event occurs. - */ - onIntervalElapsing(intervalElapsingHandler: ElapsingEvent): void; - - /** - * Returns a string represenation of the remaining - * in this format: minutes:seconds. - * examples: 20:23, 00:04, 59:59 - */ - toString(): string; - - private getDoubleDigit(number: number): string; - - private checkForValidInterval(interval: number): void; - } + constructor(interval: number); /** - * Simulates the actions of a generic stopwatch. + * Gets a boolean value to indicate the enabled state + * of the current Timer instance. + * @readonly + * @default true */ - class Stopwatch { - private _isRunning: boolean; - private _elapsedMilliseconds: number; - private _startedTimeInMillis: number; - private _intervalIds: Array; - - /** - * Initializes a new instance of the Stopwatch class. - */ - constructor(); - - /** - * Gets the elapsed time in this format: - * hrs:mins:secs:ms - * @readonly - */ - readonly elapsed: string; - - /** - * Gets the elapsed time in milliseconds. - * @readonly - */ - readonly elapsedMilliseconds: number; - - /** - * Gets the elapsed time in seconds. - * @readonly - */ - readonly elapsedSeconds: number; - - /** - * Gets the elapsed time in minutes. - * @readonly - */ - readonly elapsedMinutes: number; - - /** - * Gets the elapsed hours in hours. - * @readonly - */ - readonly elapsedHours: number; - - /** - * Gets the isRunning state of the current Stopwatch instance. - * @readonly - * @default false - */ - readonly isRunning: boolean; - - /** - * Initializes a new Stopwatch instance and - * starts measuring elapsed time. - */ - static startNew(): Stopwatch; - - /** - * Starts, or resumes the Stopwatch - * from measuring elapsed time. - */ - start(): void; - - /** - * Stops the Stopwatch from measuring elapsed time. - */ - stop(): void; - - /** - * Stops the Stopwatch and resets the elapsed time to zero. - */ - reset(): void; - - /** - * Stops the Stopwatch, - * resets the elapsed time to zero - * and starts the Stopwatch for measuring elapsed time. - * It is a shortcut for writing - * reset then start. - */ - restart(): void; - - /** - * Stops the Stopwatch and cleans up the intervals. - */ - dispose(): void; - - private getDoubleDigit(num: number): string; - } + readonly enabled: boolean; /** - * Simulates an object that represents a time interval. + * Gets a boolean value to indicate the stopped state + * of the current Timer instance. + * @readonly + * @default false */ - class Timespan { - private _milliseconds: number; - private constructor(milliseconds: number); + readonly stopped: boolean; - /** - * Gets the time interval in milliseconds. - * @readonly - */ - readonly milliseconds: number; + /** + * Gets or sets the remaining interval in milliseconds. + * The value must be greater than zero. + */ + interval: number; - /** - * Gets the time interval in seconds. - * @readonly - */ - readonly seconds: number; + /** + * Starts raising the Timer events + * by setting the enabled property to true. + */ + start(): void; - /** - * Gets the time interval in minutes. - * @readonly - */ - readonly minutes: number; + /** + * Pauses the Timer instance by setting the enabled property to false. + */ + pause(): void; - /** - * Gets the time interval in hours. - * @readonly - */ - readonly hours: number; + /** + * Resumes the Timer instance by setting the enabled property to true. + */ + resume(): void; - /** - * Gets the time interval in days. - * @readonly - */ - readonly days: number; + /** + * Stops raising the Timer event + * by setting the enabled property to false. + */ + stop(): void; - /** - * Returns a Timespan that represents a specified number of days. - * @param days The number of days. - */ - static fromDays(days: number): Timespan; + /** + * Occurs when the interval has completely elapsed. + * @param intervalElapsedHandler + * The callback which will be executed when + * the interval elapsed event occurs. + */ + onIntervalElapsed(intervalElapsedHandler: ElapsedEvent): void; - /** - * Returns a Timespan that represents a specified number of hours. - * @param hours The number of hours. - */ - static fromHours(hours: number): Timespan; + /** + * Occurs when the interval elapses and completely elapsed. + * @param intervalElapsingHandler + * The callback which will be executed when + * the interval elapsing event occurs. + */ + onIntervalElapsing(intervalElapsingHandler: ElapsingEvent): void; - /** - * Returns a Timespan that represents a specified number of minutes. - * @param minutes The number of minutes. - */ - static fromMinutes(minutes: number): Timespan; + /** + * Returns a string represenation of the remaining + * in this format: minutes:seconds. + * examples: 20:23, 00:04, 59:59 + */ + toString(): string; - /** - * Returns a Timespan that represents a specified number of seconds. - * @param seconds The number of seconds. - */ - static fromSeconds(seconds: number): Timespan; + private getDoubleDigit(number: number): string; - /** - * Returns a Timespan that represents a specified number of milliseconds. - * @param milliseconds The number of milliseconds. - */ - static fromMilliseconds(milliseconds: number): Timespan; - - /** - * Compares two Timespan objects and - * returns an integer that indicates whether - * the first value is shorter than, equal to, - * or longer than the second value. - * @param t1 The first Timespan to compare. - * @param t2 The second Timespan to compare. - */ - static compare(t1: Timespan, t2: Timespan): 1 | 0 | -1; - - /** - * Returns a boolean value that indicates - * whether two specified instances of Timespan are equal. - * @param t1 The first Timespan to compare. - * @param t2 The second Timespan to compare. - */ - static equals(t1: Timespan, t2: Timespan): boolean; - - /** - * Adds the specified Timespan to this instance. - * @param timespan The Timespan to add. - */ - addMutable(timespan: Timespan): void; - - /** - * Substracts the specified Timespan from this instance. - * @param timespan The Timespan to substract. - */ - substractMutable(timespan: Timespan): void; - - /** - * Returns a new Timespan object whose - * value is the sum of the specified Timespan object and this instance. - * @param timespan The Timespan to add. - */ - add(timespan: Timespan): Timespan; - - /** - * Returns a new Timespan object whose - * value is the difference between the - * specified Timespan object and this instance. - * @param timespan The Timespan to substract. - */ - substract(timespan: Timespan): Timespan; - - /** - * Returns a new Timespan object - * whose value is the negated value of this instance. - */ - negate(): Timespan; - } + private checkForValidInterval(interval: number): void; } -export * from 'sharp-timer'; +/** + * Simulates the actions of a generic stopwatch. + */ +export class Stopwatch { + private _isRunning: boolean; + private _elapsedMilliseconds: number; + private _startedTimeInMillis: number; + private _intervalIds: Array; + + /** + * Initializes a new instance of the Stopwatch class. + */ + constructor(); + + /** + * Gets the elapsed time in this format: + * hrs:mins:secs:ms + * @readonly + */ + readonly elapsed: string; + + /** + * Gets the elapsed time in milliseconds. + * @readonly + */ + readonly elapsedMilliseconds: number; + + /** + * Gets the elapsed time in seconds. + * @readonly + */ + readonly elapsedSeconds: number; + + /** + * Gets the elapsed time in minutes. + * @readonly + */ + readonly elapsedMinutes: number; + + /** + * Gets the elapsed hours in hours. + * @readonly + */ + readonly elapsedHours: number; + + /** + * Gets the isRunning state of the current Stopwatch instance. + * @readonly + * @default false + */ + readonly isRunning: boolean; + + /** + * Initializes a new Stopwatch instance and + * starts measuring elapsed time. + */ + static startNew(): Stopwatch; + + /** + * Starts, or resumes the Stopwatch + * from measuring elapsed time. + */ + start(): void; + + /** + * Stops the Stopwatch from measuring elapsed time. + */ + stop(): void; + + /** + * Stops the Stopwatch and resets the elapsed time to zero. + */ + reset(): void; + + /** + * Stops the Stopwatch, + * resets the elapsed time to zero + * and starts the Stopwatch for measuring elapsed time. + * It is a shortcut for writing + * reset then start. + */ + restart(): void; + + /** + * Stops the Stopwatch and cleans up the intervals. + */ + dispose(): void; + + private getDoubleDigit(num: number): string; +} + +/** + * Simulates an object that represents a time interval. + */ +export class Timespan { + private _milliseconds: number; + private constructor(milliseconds: number); + + /** + * Gets the time interval in milliseconds. + * @readonly + */ + readonly milliseconds: number; + + /** + * Gets the time interval in seconds. + * @readonly + */ + readonly seconds: number; + + /** + * Gets the time interval in minutes. + * @readonly + */ + readonly minutes: number; + + /** + * Gets the time interval in hours. + * @readonly + */ + readonly hours: number; + + /** + * Gets the time interval in days. + * @readonly + */ + readonly days: number; + + /** + * Returns a Timespan that represents a specified number of days. + * @param days The number of days. + */ + static fromDays(days: number): Timespan; + + /** + * Returns a Timespan that represents a specified number of hours. + * @param hours The number of hours. + */ + static fromHours(hours: number): Timespan; + + /** + * Returns a Timespan that represents a specified number of minutes. + * @param minutes The number of minutes. + */ + static fromMinutes(minutes: number): Timespan; + + /** + * Returns a Timespan that represents a specified number of seconds. + * @param seconds The number of seconds. + */ + static fromSeconds(seconds: number): Timespan; + + /** + * Returns a Timespan that represents a specified number of milliseconds. + * @param milliseconds The number of milliseconds. + */ + static fromMilliseconds(milliseconds: number): Timespan; + + /** + * Compares two Timespan objects and + * returns an integer that indicates whether + * the first value is shorter than, equal to, + * or longer than the second value. + * @param t1 The first Timespan to compare. + * @param t2 The second Timespan to compare. + */ + static compare(t1: Timespan, t2: Timespan): 1 | 0 | -1; + + /** + * Returns a boolean value that indicates + * whether two specified instances of Timespan are equal. + * @param t1 The first Timespan to compare. + * @param t2 The second Timespan to compare. + */ + static equals(t1: Timespan, t2: Timespan): boolean; + + /** + * Adds the specified Timespan to this instance. + * @param timespan The Timespan to add. + */ + addMutable(timespan: Timespan): void; + + /** + * Substracts the specified Timespan from this instance. + * @param timespan The Timespan to substract. + */ + substractMutable(timespan: Timespan): void; + + /** + * Returns a new Timespan object whose + * value is the sum of the specified Timespan object and this instance. + * @param timespan The Timespan to add. + */ + add(timespan: Timespan): Timespan; + + /** + * Returns a new Timespan object whose + * value is the difference between the + * specified Timespan object and this instance. + * @param timespan The Timespan to substract. + */ + substract(timespan: Timespan): Timespan; + + /** + * Returns a new Timespan object + * whose value is the negated value of this instance. + */ + negate(): Timespan; +}