Comparing version 1.1.0 to 1.2.0
@@ -10,3 +10,5 @@ export declare enum Precision { | ||
} | ||
export declare type Duration = {}; | ||
export declare type Duration = { | ||
toString(): string; | ||
}; | ||
export declare const Duration: { | ||
@@ -19,2 +21,3 @@ MilliSeconds(days: number): Duration; | ||
Months(months: number): Duration; | ||
fromString(string: string): Duration; | ||
}; | ||
@@ -21,0 +24,0 @@ export declare type NaturalDifference = {}; |
@@ -33,2 +33,33 @@ "use strict"; | ||
}); | ||
(0, _rusted.impl)(Duration, { | ||
$fromString: function $fromString(string) { | ||
var matches = /^Duration\.([A-Za-z]+)\(([0-9]+)\)$/.exec(string); | ||
if (!matches || matches.length !== 3) throw Error('Invalid string'); | ||
var unit = Duration[matches[1]]; | ||
if (!unit) throw Error('Invalid unit'); | ||
return unit.call(Duration, +matches[2]); | ||
}, | ||
toString: function toString(self) { | ||
return (0, _rusted.match)(self, { | ||
MilliSeconds: function MilliSeconds(duration) { | ||
return "Duration.MilliSeconds(" + duration + ")"; | ||
}, | ||
Seconds: function Seconds(duration) { | ||
return "Duration.Seconds(" + duration + ")"; | ||
}, | ||
Minutes: function Minutes(duration) { | ||
return "Duration.Minutes(" + duration + ")"; | ||
}, | ||
Hours: function Hours(duration) { | ||
return "Duration.Hours(" + duration + ")"; | ||
}, | ||
Days: function Days(duration) { | ||
return "Duration.Days(" + duration + ")"; | ||
}, | ||
Months: function Months(duration) { | ||
return "Duration.Months(" + duration + ")"; | ||
} | ||
}); | ||
} | ||
}); | ||
var NaturalDifference = exports.NaturalDifference = (0, _rusted.Enum)({ | ||
@@ -35,0 +66,0 @@ Last: Duration, |
{ | ||
"name": "date-tools", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Functions for comparing and counting with dates", | ||
@@ -5,0 +5,0 @@ "main": "dist/src/index.js", |
@@ -13,3 +13,5 @@ import {Enum, impl, match} from 'rusted' | ||
export type Duration = {} | ||
export type Duration = { | ||
toString(): string | ||
} | ||
export const Duration = Enum({ | ||
@@ -29,4 +31,28 @@ MilliSeconds: 'number', | ||
Months(months: number): Duration, | ||
fromString(string: string): Duration | ||
} | ||
impl(Duration, { | ||
$fromString(string: string) { | ||
const matches = /^Duration\.([A-Za-z]+)\(([0-9]+)\)$/.exec(string) | ||
if (!matches || matches.length !== 3) throw Error('Invalid string') | ||
const unit = Duration[matches[1]] | ||
if (!unit) throw Error('Invalid unit') | ||
return unit.call(Duration, +matches[2]) | ||
}, | ||
toString(self) { | ||
return match(self, { | ||
MilliSeconds: duration => `Duration.MilliSeconds(${duration})`, | ||
Seconds: duration => `Duration.Seconds(${duration})`, | ||
Minutes: duration => `Duration.Minutes(${duration})`, | ||
Hours: duration => `Duration.Hours(${duration})`, | ||
Days: duration => `Duration.Days(${duration})`, | ||
Months: duration => `Duration.Months(${duration})`, | ||
}) | ||
}, | ||
}) | ||
export type NaturalDifference = {} | ||
@@ -33,0 +59,0 @@ export const NaturalDifference = Enum({ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
98769
915