Moment.js definitions and tests added

This commit is contained in:
Boris Yankov
2012-10-18 20:16:17 +03:00
parent f219942e4e
commit 21b0da83d5
3 changed files with 131 additions and 134 deletions
+103 -99
View File
@@ -5,141 +5,145 @@
interface MomentInput {
years?: number;
y?: number;
months?: number;
M?: number;
weeks?: number;
w?: number;
days?: number;
d?: number;
hours?: number;
h?: number;
minutes?: number;
m?: number;
seconds?: number;
s?: number;
milliseconds?: number;
ms?: number;
years?: number;
y?: number;
months?: number;
M?: number;
weeks?: number;
w?: number;
days?: number;
d?: number;
hours?: number;
h?: number;
minutes?: number;
m?: number;
seconds?: number;
s?: number;
milliseconds?: number;
ms?: number;
}
interface Duration {
humanize(): string;
humanize(): string;
milliseconds(): number;
asMilliseconds(): number;
seconds(): number;
asSeconds(): number;
milliseconds(): number;
asMilliseconds(): number;
minutes(): number;
asMinutes(): number;
hours(): number;
asHours(): number;
days(): number;
asDays(): number;
months(): number;
asMonths(): number;
years(): number;
asYears(): number;
seconds(): number;
asSeconds(): number;
minutes(): number;
asMinutes(): number;
hours(): number;
asHours(): number;
days(): number;
asDays(): number;
months(): number;
asMonths(): number;
years(): number;
asYears(): number;
}
interface Moment {
format(format: string): string;
format(): string;
format(format: string): string;
format(): string;
fromNow(): string;
fromNow(): string;
startOf(soort: string): Moment;
endOf(soort: string): Moment;
startOf(soort: string): Moment;
endOf(soort: string): Moment;
add(input: MomentInput): Moment;
add(soort: string, aantal: number): Moment;
substract(input: MomentInput): Moment;
substract(soort: string, aantal: number): Moment;
add(input: MomentInput): Moment;
add(soort: string, aantal: number): Moment;
add(duration: Duration): Moment;
subtract(input: MomentInput): Moment;
subtract(soort: string, aantal: number): Moment;
calendar(): string;
calendar(): string;
valueOf(): string;
valueOf(): string;
local(): Moment; // current date/time in local mode
local(): Moment; // current date/time in local mode
utc(): Moment; // current date/time in UTC mode
utc(): Moment; // current date/time in UTC mode
isValid(): bool;
isValid(): bool;
year(y: number): Moment;
month(M: number): Moment;
day(d: number): Moment;
date(d: number): Moment;
hours(h: number): Moment;
minutes(m: number): Moment;
seconds(s: number): Moment;
milliseconds(ms: number): Moment;
year(y?: number): Moment;
month(M?: number): Moment;
day(d?: number): Moment;
date(d?: number): Moment;
hours(h?: number): Moment;
minutes(m?: number): Moment;
seconds(s?: number): Moment;
milliseconds(ms?: number): Moment;
sod(): Moment; // Start of Day
eod(): Moment; // End of Day
sod(): Moment; // Start of Day
eod(): Moment; // End of Day
from(f: Moment): string;
from(f: Moment, suffix: bool): string;
from(d: Date): string;
from(s: string): string;
from(f: Moment): string;
from(f: Moment, suffix: bool): string;
from(d: Date): string;
from(s: string): string;
from(date: number[]): string;
diff(b: Moment): number;
diff(b: Moment, soort: string): number;
diff(b: Moment, soort: string, round: bool): number;
diff(b: Moment): number;
diff(b: Moment, soort: string): number;
diff(b: Moment, soort: string, round: bool): number;
toDate(): Date;
unix(): number;
toDate(): Date;
unix(): number;
isLeapYear(): bool;
zone(): number;
daysInMonth(): number;
isDST(): bool;
isLeapYear(): bool;
zone(): number;
daysInMonth(): number;
isDST(): bool;
lang(language: string);
lang(reset: bool);
lang(): string;
lang(language: string);
lang(reset: bool);
lang(): string;
}
/*
Static members of moment
*/
interface MomentStatic {
(): Moment;
(date: string): Moment;
(date: string, time: string): Moment;
(date: Date): Moment;
(clone: Moment): Moment;
(): Moment;
(date: number): Moment;
(date: string): Moment;
(date: string, time: string): Moment;
(date: Date): Moment;
(date: string, formats: string[]): Moment;
(date: number[]): Moment;
(clone: Moment): Moment;
clone(): Moment;
unix(timestamp: number): Moment;
utc(): Moment; // current date/time in UTC mode
utc(Number: number): Moment; // milliseconds since the Unix Epoch in UTC mode
utc(array: number[]): Moment; // parse an array of numbers matching Date.UTC() parameters
utc(String: string): Moment; // parse string into UTC mode
utc(String1: string, String2: string): Moment; // parse a string and format into UTC mode
clone(): Moment;
unix(timestamp: number): Moment;
isMoment(m: any): bool;
lang(language: string);
lang(language: string, definition: any); // TODO definition
utc(): Moment; // current date/time in UTC mode
utc(Number: number): Moment; // milliseconds since the Unix Epoch in UTC mode
utc(array: number[]): Moment; // parse an array of numbers matching Date.UTC() parameters
utc(String: string): Moment; // parse string into UTC mode
utc(String1: string, String2: string): Moment; // parse a string and format into UTC mode
isMoment(m: any): bool;
lang(language: string);
lang(language: string, definition: any); // TODO definition
duration(milliseconds: Number): Duration;
duration(num: Number, soort: string): Duration;
duration(input: MomentInput): Duration;
duration(milliseconds: Number): Duration;
duration(num: Number, soort: string): Duration;
duration(input: MomentInput): Duration;
duration(object: any): Duration;
}
declare var moment: MomentStatic;
+3
View File
@@ -19,6 +19,7 @@ Complete
* [jQuery UI](http://jqueryui.com/)
* [Knockout.js](http://knockoutjs.com/)
* [Modernizr](http://modernizr.com/)
* [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield))
* [Mustache.js](https://github.com/janl/mustache.js)
* [Node.js](http://nodejs.org/) (from TypeScript samples)
* [QUnit](http://qunitjs.com/) (by [Diullei Gomes](https://github.com/Diullei))
@@ -28,8 +29,10 @@ Complete
Next
----
* Angular.js
* google.visualization
* jQuery Mobile
* jQuery.Validate
* Knockout.Mapping
* PhoneGap
* Isotope
* ember.js
+25 -35
View File
@@ -40,8 +40,8 @@ a.hours();
moment("2011-10-10", "YYYY-MM-DD").isValid();
moment("2011-10-50", "YYYY-MM-DD").isValid();
moment("2011-10-10T10:20:90").isValid();
moment([2011, 0 1]).isValid();
moment([2011, 0 50]).isValid();
moment([2011, 0, 1]).isValid();
moment([2011, 0, 50]).isValid();
moment("not a date").isValid();
moment().add('days', 7).subtract('months', 1).year(2009).hours(0).minutes(0).seconds(0);
@@ -56,19 +56,14 @@ moment([2010, 0, 31]).add('months', 1);
var m = moment(new Date(2011, 2, 12, 5, 0, 0));
m.hours();
m.add('days', 1).hours();
var m = moment(new Date(2011, 2, 12, 5, 0, 0));
m.hours();
m.add('hours', 24).hours();
var duration = moment.duration({'days', 1});
var m2 = moment(new Date(2011, 2, 12, 5, 0, 0));
m2.hours();
m2.add('hours', 24).hours();
var duration = moment.duration({'days': 1});
moment([2012, 0, 31]).add(duration);
moment().subtract('days', 7);
moment().milliseconds(30) === new Date().setMilliseconds(30);
moment().milliseconds() === new Date().getMilliseconds();
moment.utc().milliseconds(30) === new Date().setUTCMilliseconds(30);
moment.utc().milliseconds() === new Date().getUTCMilliseconds();
moment().seconds(30);
moment().minutes(30);
@@ -86,37 +81,32 @@ moment().sod();
moment().hours(0).minutes(0).seconds(0).milliseconds(0);
moment().eod();
var a = moment.utc([2011, 0, 1, 8]);
a.hours();
a.local();
a.hours();
var a3 = moment([2011, 0, 1, 8]);
a3.hours();
a3.utc();
a3.hours();
var a = moment([2011, 0, 1, 8]);
a.hours();
a.utc();
a.hours();
var a = moment([2010, 1, 14, 15, 25, 50, 125]);
a.format("dddd, MMMM Do YYYY, h:mm:ss a");
a.format("ddd, hA");
var a4 = moment([2010, 1, 14, 15, 25, 50, 125]);
a4.format("dddd, MMMM Do YYYY, h:mm:ss a");
a4.format("ddd, hA");
moment().format('\\L');
moment().format('[today] DDDD');
var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.from(b) ;
var a5 = moment([2007, 0, 29]);
var b5 = moment([2007, 0, 28]);
a5.from(b5);
var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.from(b);
a.from([2007, 0, 28]);
a.from(new Date(2007, 0, 28));
a.from("1-28-2007");
var a6 = moment([2007, 0, 29]);
var b6 = moment([2007, 0, 28]);
a6.from(b6);
a6.from([2007, 0, 28]);
a6.from(new Date(2007, 0, 28));
a6.from("1-28-2007");
var a = moment();\n
var b = moment("10-10-1900", "MM-DD-YYYY");
a.from(b);
var a7 = moment();\n
var b7 = moment("10-10-1900", "MM-DD-YYYY");
a7.from(b7);
var start = moment([2007, 0, 5]);\n
var end = moment([2007, 0, 10]);